Browse Source

Add edit feature base UI

Soomin Lee 7 years ago
parent
commit
9990ade446

+ 27 - 0
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -32,6 +32,13 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
         return emptyView
     }()
 
+    let editCollectionViewLayout: UICollectionViewFlowLayout = {
+        let editCollectionViewLayout = UICollectionViewFlowLayout()
+        editCollectionViewLayout.minimumLineSpacing = 1
+        editCollectionViewLayout.minimumInteritemSpacing = 0
+        return editCollectionViewLayout
+    }()
+
     @available(*, unavailable)
     init() {
         fatalError()
@@ -86,6 +93,7 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     func setupCollectionView() {
         let playlistnib = UINib(nibName: "VLCPlaylistCollectionViewCell", bundle: nil)
         collectionView?.register(playlistnib, forCellWithReuseIdentifier: VLCPlaylistCollectionViewCell.cellIdentifier())
+        collectionView?.register(VLCMediaViewEditCell.self, forCellWithReuseIdentifier: VLCMediaViewEditCell.identifier)
         collectionView?.backgroundColor = PresentationTheme.current.colors.background
         collectionView?.alwaysBounceVertical = true
         if #available(iOS 11.0, *) {
@@ -134,6 +142,19 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
         collectionView?.collectionViewLayout.invalidateLayout()
     }
 
+    override func setEditing(_ editing: Bool, animated: Bool) {
+        super.setEditing(editing, animated: animated)
+        let layoutToBe = editing ? editCollectionViewLayout : UICollectionViewFlowLayout()
+        collectionView?.setCollectionViewLayout(layoutToBe, animated: false, completion: {
+            [weak self] finished in
+            guard finished else {
+                assertionFailure("VLCMediaSubcategoryViewController: Edit layout transition failed.")
+                return
+            }
+            self?.reloadData()
+        })
+    }
+
     // MARK: - Search
 
     func updateSearchResults(for searchController: UISearchController) {
@@ -187,6 +208,12 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
     // MARK: - UICollectionViewDelegateFlowLayout
     func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
 
+        if isEditing {
+            let contentInset = collectionView.contentInset
+            let insetToRemove = contentInset.left + contentInset.right + (cellPadding * 2)
+            return CGSize(width: collectionView.frame.width - insetToRemove, height: VLCMediaViewEditCell.height)
+        }
+
         let numberOfCells: CGFloat = collectionView.traitCollection.horizontalSizeClass == .regular ? 3.0 : 2.0
         let aspectRatio: CGFloat = 10.0 / 16.0
 

+ 11 - 1
Sources/MediaViewControllers/MediaViewController.swift

@@ -15,6 +15,7 @@ import UIKit
 class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
     var services: Services
     private var rendererButton: UIButton
+    private let fixedSpaceWidth: CGFloat = 21
 
     init(services: Services) {
         self.services = services
@@ -37,8 +38,12 @@ class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
         if #available(iOS 11.0, *) {
             navigationController?.navigationBar.prefersLargeTitles = false
         }
+
+        let fixedSpace: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
+        fixedSpace.width = fixedSpaceWidth
+
         navigationItem.leftBarButtonItem = UIBarButtonItem(title: NSLocalizedString("SORT", comment: ""), style: .plain, target: self, action: #selector(sort))
-        navigationItem.rightBarButtonItem = UIBarButtonItem(customView: rendererButton)
+        navigationItem.rightBarButtonItems = [editButtonItem, fixedSpace, UIBarButtonItem(customView: rendererButton)]
     }
 
     @objc func sort() {
@@ -94,4 +99,9 @@ class VLCMediaViewController: VLCPagingViewController<VLCLabelCell> {
     override var preferredStatusBarStyle: UIStatusBarStyle {
         return PresentationTheme.current.colors.statusBarStyle
     }
+
+    override func setEditing(_ editing: Bool, animated: Bool) {
+        super.setEditing(editing, animated: animated)
+        viewControllers[currentIndex].setEditing(editing, animated: animated)
+    }
 }

+ 136 - 0
Sources/VLCMediaViewEditCell.swift

@@ -0,0 +1,136 @@
+/*****************************************************************************
+ * VLCMediaViewEditCell.swift
+ *
+ * Copyright © 2018 VLC authors and VideoLAN
+ * Copyright © 2018 Videolabs
+ *
+ * Authors: Soomin Lee <bubu@mikan.io>
+ *
+ * Refer to the COPYING file of the official project for license.
+ *****************************************************************************/
+
+struct VLCCheckView {
+    var isEnabled: Bool {
+        didSet {
+            let backgroundColor: UIColor = isEnabled ? .orange : .clear
+            let borderColor: UIColor = isEnabled ? .clear : .lightGray
+            view.backgroundColor = backgroundColor
+            view.layer.borderColor = borderColor.cgColor
+        }
+    }
+
+    var view: UIView = {
+        let view = UIView(frame: CGRect(x: 0, y: 0, width: 20, height: 20))
+        view.translatesAutoresizingMaskIntoConstraints = false
+        view.clipsToBounds = true
+        view.layer.cornerRadius = view.frame.width / 2
+        view.layer.borderColor = UIColor.lightGray.cgColor
+        view.layer.borderWidth = 1
+        return view
+    }()
+
+    init(isEnabled: Bool) {
+        self.isEnabled = isEnabled
+    }
+}
+
+class VLCMediaViewEditCell: UICollectionViewCell {
+
+    static let identifier = String(describing: VLCMediaViewEditCell.self)
+
+    static let height: CGFloat = 56
+
+    var checkView = VLCCheckView(isEnabled: false)
+
+    let thumbnailImageView: UIImageView = {
+        let thumbnailImageView = UIImageView()
+        thumbnailImageView.translatesAutoresizingMaskIntoConstraints = false
+        thumbnailImageView.contentMode = .scaleAspectFit
+        thumbnailImageView.clipsToBounds = true
+        thumbnailImageView.layer.cornerRadius = 3
+        return thumbnailImageView
+    }()
+
+    let titleLabel: UILabel = {
+        let titleLabel = UILabel()
+        titleLabel.textColor = PresentationTheme.current.colors.cellTextColor
+        titleLabel.font = UIFont.systemFont(ofSize: 17)
+        titleLabel.translatesAutoresizingMaskIntoConstraints = false
+        return titleLabel
+    }()
+
+    let subInfoLabel: UILabel = {
+        let subInfoLabel = UILabel()
+        subInfoLabel.textColor = PresentationTheme.current.colors.cellTextColor
+        subInfoLabel.font = UIFont.systemFont(ofSize: 13)
+        subInfoLabel.translatesAutoresizingMaskIntoConstraints = false
+        return subInfoLabel
+    }()
+
+    let sizeLabel: UILabel = {
+        let sizeLabel = UILabel()
+        sizeLabel.textColor = PresentationTheme.current.colors.cellTextColor
+        sizeLabel.font = UIFont.systemFont(ofSize: 11)
+        sizeLabel.translatesAutoresizingMaskIntoConstraints = false
+        return sizeLabel
+    }()
+
+    let mainStackView: UIStackView = {
+        let mainStackView = UIStackView()
+        mainStackView.spacing = 20.0
+        mainStackView.axis = .horizontal
+        mainStackView.alignment = .center
+        mainStackView.translatesAutoresizingMaskIntoConstraints = false
+        return mainStackView
+    }()
+
+    let mediaInfoStackView: UIStackView = {
+        let mediaInfoStackView = UIStackView()
+        mediaInfoStackView.spacing = 5.0
+        mediaInfoStackView.axis = .vertical
+        mediaInfoStackView.alignment = .leading
+        mediaInfoStackView.translatesAutoresizingMaskIntoConstraints = false
+        return mediaInfoStackView
+    }()
+
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        setupViews()
+    }
+
+    required init?(coder aDecoder: NSCoder) {
+        super.init(coder: aDecoder)
+        setupViews()
+    }
+
+    private func setupViews() {
+
+        mediaInfoStackView.addArrangedSubview(titleLabel)
+        mediaInfoStackView.addArrangedSubview(subInfoLabel)
+        mediaInfoStackView.addArrangedSubview(sizeLabel)
+
+        mainStackView.addArrangedSubview(checkView.view)
+        mainStackView.addArrangedSubview(thumbnailImageView)
+        mainStackView.addArrangedSubview(mediaInfoStackView)
+
+        addSubview(mainStackView)
+
+        var guide: LayoutAnchorContainer = self
+
+        if #available(iOS 11.0, *) {
+            guide = safeAreaLayoutGuide
+        }
+        NSLayoutConstraint.activate([
+            checkView.view.heightAnchor.constraint(equalToConstant: 20),
+            checkView.view.widthAnchor.constraint(equalTo: checkView.view.heightAnchor),
+
+            thumbnailImageView.heightAnchor.constraint(equalToConstant: VLCMediaViewEditCell.height),
+            thumbnailImageView.widthAnchor.constraint(equalTo: thumbnailImageView.heightAnchor),
+
+            mainStackView.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 20),
+            mainStackView.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -20),
+            mainStackView.heightAnchor.constraint(equalTo: heightAnchor),
+            mainStackView.topAnchor.constraint(equalTo: topAnchor)
+            ])
+    }
+}

+ 4 - 0
VLC.xcodeproj/project.pbxproj

@@ -246,6 +246,7 @@
 		7DF90B4A1BE7A8110059C0E3 /* IASKSettingsReader.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF90B471BE7A8110059C0E3 /* IASKSettingsReader.m */; };
 		7DF90B4B1BE7A8110059C0E3 /* IASKSpecifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF90B491BE7A8110059C0E3 /* IASKSpecifier.m */; };
 		7DF9352F1958AB0600E60FD4 /* UIColor+Presets.m in Sources */ = {isa = PBXBuildFile; fileRef = 7DF9352E1958AB0600E60FD4 /* UIColor+Presets.m */; };
+		8D222DC220F779F1009C0D34 /* VLCMediaViewEditCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D222DC120F779F1009C0D34 /* VLCMediaViewEditCell.swift */; };
 		8D43712D2056AF1600F36458 /* VLCRendererDiscovererManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D43712C2056AF1600F36458 /* VLCRendererDiscovererManager.swift */; };
 		8D437154205808FF00F36458 /* VLCActionSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D437153205808FF00F36458 /* VLCActionSheet.swift */; };
 		8D66A47320AC61B900FA5B92 /* VLCMediaLibraryManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8D66A47220AC61B900FA5B92 /* VLCMediaLibraryManager.swift */; };
@@ -939,6 +940,7 @@
 		7DF9352E1958AB0600E60FD4 /* UIColor+Presets.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIColor+Presets.m"; path = "Sources/UIColor+Presets.m"; sourceTree = SOURCE_ROOT; };
 		7FC9CCF39DD8843873A42D34 /* Pods-VLC-iOSTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-iOSTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-iOSTests/Pods-VLC-iOSTests.release.xcconfig"; sourceTree = "<group>"; };
 		8C707B9BB2C5681D50CC9B99 /* Pods-VLC-tvOS-Debug.distribution.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-VLC-tvOS-Debug.distribution.xcconfig"; path = "Pods/Target Support Files/Pods-VLC-tvOS-Debug/Pods-VLC-tvOS-Debug.distribution.xcconfig"; sourceTree = "<group>"; };
+		8D222DC120F779F1009C0D34 /* VLCMediaViewEditCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCMediaViewEditCell.swift; path = Sources/VLCMediaViewEditCell.swift; sourceTree = "<group>"; };
 		8D43712C2056AF1600F36458 /* VLCRendererDiscovererManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = VLCRendererDiscovererManager.swift; path = Sources/VLCRendererDiscovererManager.swift; sourceTree = "<group>"; };
 		8D437153205808FF00F36458 /* VLCActionSheet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCActionSheet.swift; sourceTree = "<group>"; };
 		8D66A47220AC61B900FA5B92 /* VLCMediaLibraryManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VLCMediaLibraryManager.swift; sourceTree = "<group>"; };
@@ -1463,6 +1465,7 @@
 				8DD651B0208F62B70052EE68 /* VLCActionSheet */,
 				4144156920ECD2620078EC37 /* VLCSectionTableHeaderView.swift */,
 				4144156B20ECE6330078EC37 /* VLCFileServerSectionTableHeaderView.swift */,
+				8D222DC120F779F1009C0D34 /* VLCMediaViewEditCell.swift */,
 			);
 			name = "UI Elements";
 			sourceTree = "<group>";
@@ -3202,6 +3205,7 @@
 				413EC98B201B4F2C00BF412F /* PresentationTheme.swift in Sources */,
 				DD1CB0321BB9E005006EDDE6 /* VLCMovieViewControlPanelView.m in Sources */,
 				DDF908D01CF4CCAA00108B70 /* VLCNetworkLoginViewButtonCell.m in Sources */,
+				8D222DC220F779F1009C0D34 /* VLCMediaViewEditCell.swift in Sources */,
 				DD3EFF3D1BDEBCE500B68579 /* VLCLocalNetworkServiceBrowserHTTP.m in Sources */,
 				DDEAECBE1BDEBF6700756C83 /* VLCNetworkServerLoginInformation.m in Sources */,
 				418DFE9F211C93C6005D3652 /* VLCPlaybackController+VLCDialogProvider.swift in Sources */,