Browse Source

EditToolBar: Add UI-Elements for editing

Added assets for rename, share and delete button
Added these buttons and Add to playlist in a stackview to the toolbar
Added assertions to know why some controllers crash when trying to edit
Carola Nitz 6 years ago
parent
commit
4fd8b4e836

+ 3 - 0
Resources/en.lproj/Localizable.strings

@@ -317,3 +317,6 @@
 
 "MODIFIED_DATE" = "Modified date";
 "NAME" = "Name";
+
+//EDIT
+"ADD_TO_PLAYLIST" = "Add to Playlist";

+ 0 - 1
Sources/MediaCategories/MediaCategoryViewController.swift

@@ -127,7 +127,6 @@ class VLCMediaCategoryViewController: UICollectionViewController, UICollectionVi
             editToolbar.trailingAnchor.constraint(equalTo: view.trailingAnchor),
             editToolbar.heightAnchor.constraint(equalToConstant: 50)
         ])
-
     }
 
     override func viewDidAppear(_ animated: Bool) {

+ 16 - 8
Sources/VLCEditController.swift

@@ -136,6 +136,10 @@ extension VLCEditController: VLCEditToolbarDelegate {
                                                                 deleteButton])
     }
 
+    func share() {
+        assertionFailure("Implement me")
+    }
+
     func rename() {
         // FIXME: Multiple renaming of files(multiple alert can get unfriendly if too many files)
         for indexPath in selectedCellIndexPaths {
@@ -168,15 +172,19 @@ extension VLCEditController: UICollectionViewDataSource {
     }
 
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
-        if let editCell = (category as? EditableMLModel)?.editCellType() {
-            if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: editCell.defaultReuseIdentifier,
-                                                             for: indexPath) as? MediaEditCell {
-                cell.media = category.anyfiles[indexPath.row]
-                cell.isChecked = selectedCellIndexPaths.contains(indexPath)
-                return cell
-            }
+        guard let editCell = (category as? EditableMLModel)?.editCellType() else {
+            assertionFailure("The category either doesn't implement EditableMLModel or doesn't have a editcellType defined")
+            return UICollectionViewCell()
+        }
+        if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: editCell.defaultReuseIdentifier,
+                                                         for: indexPath) as? MediaEditCell {
+            cell.media = category.anyfiles[indexPath.row]
+            cell.isChecked = selectedCellIndexPaths.contains(indexPath)
+            return cell
+        } else {
+            assertionFailure("We couldn't dequeue a reusable cell, the cell might not be registered or is not a MediaEditCell")
+            return UICollectionViewCell()
         }
-        return UICollectionViewCell()
     }
 }
 

+ 64 - 6
Sources/VLCEditToolbar.swift

@@ -13,14 +13,49 @@ protocol VLCEditToolbarDelegate: class {
     func delete()
     func createPlaylist()
     func rename()
+    func share()
 }
 
-// Decided to use a UIView instead of UIToolbar because we have more freedom
-// FIXME: Basic structure without UI
 class VLCEditToolbar: UIView {
     weak var delegate: VLCEditToolbarDelegate?
+    private var category: MediaLibraryBaseModel
+    private var stackView = UIStackView()
+    private var shareButton: UIButton = {
+        let shareButton = UIButton(type: .system)
+        shareButton.addTarget(self, action: #selector(share), for: .touchUpInside)
+        shareButton.setImage(UIImage(named: "share"), for: .normal)
+        shareButton.tintColor = .orange
+        shareButton.widthAnchor.constraint(equalToConstant: 44).isActive = true
+        return shareButton
+    }()
+    private var renameButton: UIButton = {
+        let renameButton = UIButton(type: .system)
+        renameButton.addTarget(self, action: #selector(rename), for: .touchUpInside)
+        renameButton.setImage(UIImage(named: "rename"), for: .normal)
+        renameButton.tintColor = .orange
+        renameButton.widthAnchor.constraint(equalToConstant: 44).isActive = true
+        return renameButton
+    }()
+    private var deleteButton: UIButton = {
+        let deleteButton = UIButton(type: .system)
+        deleteButton.addTarget(self, action: #selector(deleteSelection), for: .touchUpInside)
+        deleteButton.setImage(UIImage(named: "delete"), for: .normal)
+        deleteButton.tintColor = .orange
+        deleteButton.widthAnchor.constraint(equalToConstant: 44).isActive = true
 
-    @objc func createFolder() {
+        return deleteButton
+    }()
+    private var addToPlaylistButton: UIButton = {
+        let addToPlaylistButton = UIButton(type: .system)
+        addToPlaylistButton.setTitle(NSLocalizedString("ADD_TO_PLAYLIST", comment: ""), for: .normal)
+        addToPlaylistButton.titleLabel?.font = UIFont.systemFont(ofSize: 17)
+        addToPlaylistButton.contentHorizontalAlignment = .left
+        addToPlaylistButton.addTarget(self, action: #selector(addToPlaylist), for: .touchUpInside)
+        addToPlaylistButton.tintColor = .orange
+        return addToPlaylistButton
+    }()
+
+    @objc func addToPlaylist() {
         delegate?.createPlaylist()
     }
 
@@ -28,16 +63,39 @@ class VLCEditToolbar: UIView {
         delegate?.delete()
     }
 
-    @objc func renameSelection() {
+    @objc func rename() {
         delegate?.rename()
     }
 
+    @objc func share() {
+        delegate?.share()
+    }
+
+    private func setupStackView() {
+        let stackView = UIStackView(arrangedSubviews: [addToPlaylistButton, deleteButton, shareButton])
+        let file = category.anyfiles.first
+        if !(file is VLCMLAlbum) && !(file is VLCMLArtist) && !(file is VLCMLGenre) {
+            stackView.addArrangedSubview(renameButton)
+        }
+
+        stackView.translatesAutoresizingMaskIntoConstraints = false
+        addSubview(stackView)
+        NSLayoutConstraint.activate([
+            stackView.topAnchor.constraint(equalTo: topAnchor),
+            stackView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: 20),
+            stackView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -20),
+            stackView.bottomAnchor.constraint(equalTo: bottomAnchor)
+            ])
+    }
+
     init(category: MediaLibraryBaseModel) {
+        self.category = category
         super.init(frame: .zero)
-        //depending on category show edit buttons
+        setupStackView()
     }
 
-    required init?(coder aDecoder: NSCoder) {
+    required init(coder: NSCoder) {
         fatalError("init(coder:) has not been implemented")
     }
+
 }

+ 6 - 0
vlc-ios/Images.xcassets/Movie View/Edit/Contents.json

@@ -0,0 +1,6 @@
+{
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

vlc-ios/Images.xcassets/Movie View/delete.imageset/Contents.json → vlc-ios/Images.xcassets/Movie View/Edit/delete.imageset/Contents.json


vlc-ios/Images.xcassets/Movie View/delete.imageset/delete.png → vlc-ios/Images.xcassets/Movie View/Edit/delete.imageset/delete.png


vlc-ios/Images.xcassets/Movie View/delete.imageset/delete@2x.png → vlc-ios/Images.xcassets/Movie View/Edit/delete.imageset/delete@2x.png


vlc-ios/Images.xcassets/Movie View/delete.imageset/delete@3x.png → vlc-ios/Images.xcassets/Movie View/Edit/delete.imageset/delete@3x.png


+ 23 - 0
vlc-ios/Images.xcassets/Movie View/Edit/rename.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "rename.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "rename@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "rename@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
vlc-ios/Images.xcassets/Movie View/Edit/rename.imageset/rename.png


BIN
vlc-ios/Images.xcassets/Movie View/Edit/rename.imageset/rename@2x.png


BIN
vlc-ios/Images.xcassets/Movie View/Edit/rename.imageset/rename@3x.png


+ 23 - 0
vlc-ios/Images.xcassets/Movie View/Edit/share.imageset/Contents.json

@@ -0,0 +1,23 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "filename" : "Share.png",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "Share@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "Share@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
vlc-ios/Images.xcassets/Movie View/Edit/share.imageset/Share.png


BIN
vlc-ios/Images.xcassets/Movie View/Edit/share.imageset/Share@2x.png


BIN
vlc-ios/Images.xcassets/Movie View/Edit/share.imageset/Share@3x.png