浏览代码

VLCEditController: Save selected cell indexPath

Soomin Lee 7 年之前
父节点
当前提交
8c53a80732
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      Sources/VLCEditController.swift

+ 11 - 0
Sources/VLCEditController.swift

@@ -14,6 +14,7 @@ protocol VLCEditControllerDataSource {
 }
 }
 
 
 class VLCEditController: NSObject {
 class VLCEditController: NSObject {
+    private var selectedCellIndexPaths = Set<IndexPath>()
     private let collectionView: UICollectionView
     private let collectionView: UICollectionView
     private let category: MediaLibraryBaseModel
     private let category: MediaLibraryBaseModel
 
 
@@ -38,6 +39,10 @@ class VLCEditController: NSObject {
 extension VLCEditController: VLCEditControllerDataSource {
 extension VLCEditController: VLCEditControllerDataSource {
     func toolbarNeedsUpdate(editing: Bool) {
     func toolbarNeedsUpdate(editing: Bool) {
         editToolbar.isHidden = !editing
         editToolbar.isHidden = !editing
+        if !editing {
+            // not in editing mode anymore should reset
+            selectedCellIndexPaths.removeAll(keepingCapacity: false)
+        }
     }
     }
 }
 }
 
 
@@ -78,6 +83,12 @@ extension VLCEditController: UICollectionViewDelegate {
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
     func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
         if let cell = collectionView.cellForItem(at: indexPath) as? VLCMediaViewEditCell {
         if let cell = collectionView.cellForItem(at: indexPath) as? VLCMediaViewEditCell {
             cell.checkView.isEnabled = !cell.checkView.isEnabled
             cell.checkView.isEnabled = !cell.checkView.isEnabled
+            if cell.checkView.isEnabled {
+                // cell selected, saving indexPath
+                selectedCellIndexPaths.insert(indexPath)
+            } else {
+                selectedCellIndexPaths.remove(indexPath)
+            }
         }
         }
     }
     }
 }
 }