bulk deselect

pull/1/head
Michael Kirk 6 years ago
parent 599a57e3a4
commit 34d11dda49

@ -100,6 +100,10 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
} }
var selectionPanGesture: UIPanGestureRecognizer? var selectionPanGesture: UIPanGestureRecognizer?
enum BatchSelectionGestureMode {
case select, deselect
}
var selectionPanGestureMode: BatchSelectionGestureMode = .select
@objc @objc
func didPanSelection(_ selectionPanGesture: UIPanGestureRecognizer) { func didPanSelection(_ selectionPanGesture: UIPanGestureRecognizer) {
@ -118,19 +122,30 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
case .began: case .began:
collectionView.isUserInteractionEnabled = false collectionView.isUserInteractionEnabled = false
collectionView.isScrollEnabled = false collectionView.isScrollEnabled = false
let location = selectionPanGesture.location(in: collectionView)
guard let indexPath = collectionView.indexPathForItem(at: location) else {
return
}
let asset = photoCollectionContents.asset(at: indexPath.item)
if selectedIds.contains(asset.localIdentifier) {
selectionPanGestureMode = .deselect
} else {
selectionPanGestureMode = .select
}
case .changed: case .changed:
let location = selectionPanGesture.location(in: collectionView) let location = selectionPanGesture.location(in: collectionView)
guard let indexPath = collectionView.indexPathForItem(at: location) else { guard let indexPath = collectionView.indexPathForItem(at: location) else {
return return
} }
tryToBatchSelectItem(at: indexPath) tryToToggleBatchSelect(at: indexPath)
case .cancelled, .ended, .failed: case .cancelled, .ended, .failed:
collectionView.isUserInteractionEnabled = true collectionView.isUserInteractionEnabled = true
collectionView.isScrollEnabled = true collectionView.isScrollEnabled = true
} }
} }
func tryToBatchSelectItem(at indexPath: IndexPath) { func tryToToggleBatchSelect(at indexPath: IndexPath) {
guard isInBatchSelectMode else { guard isInBatchSelectMode else {
owsFailDebug("isInBatchSelectMode was unexpectedly false") owsFailDebug("isInBatchSelectMode was unexpectedly false")
return return
@ -147,10 +162,16 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
} }
let asset = photoCollectionContents.asset(at: indexPath.item) let asset = photoCollectionContents.asset(at: indexPath.item)
switch selectionPanGestureMode {
case .select:
selectedIds.add(asset.localIdentifier) selectedIds.add(asset.localIdentifier)
updateDoneButton()
collectionView.selectItem(at: indexPath, animated: true, scrollPosition: []) collectionView.selectItem(at: indexPath, animated: true, scrollPosition: [])
case .deselect:
selectedIds.remove(asset.localIdentifier)
collectionView.deselectItem(at: indexPath, animated: true)
}
updateDoneButton()
} }
var canSelectAdditionalItems: Bool { var canSelectAdditionalItems: Bool {

Loading…
Cancel
Save