|
|
@ -1,5 +1,5 @@
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
|
|
|
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import Foundation
|
|
|
@ -27,7 +27,8 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|
|
|
private let titleLabel = UILabel()
|
|
|
|
private let titleLabel = UILabel()
|
|
|
|
private let titleIconView = UIImageView()
|
|
|
|
private let titleIconView = UIImageView()
|
|
|
|
|
|
|
|
|
|
|
|
private var selectedIds = Set<String>()
|
|
|
|
// We use NSMutableOrderedSet so that we can honor selection order.
|
|
|
|
|
|
|
|
private let selectedIds = NSMutableOrderedSet()
|
|
|
|
|
|
|
|
|
|
|
|
// This variable should only be accessed on the main thread.
|
|
|
|
// This variable should only be accessed on the main thread.
|
|
|
|
private var assetIdToCommentMap = [String: String]()
|
|
|
|
private var assetIdToCommentMap = [String: String]()
|
|
|
@ -278,19 +279,30 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|
|
|
func didPressDone(_ sender: Any) {
|
|
|
|
func didPressDone(_ sender: Any) {
|
|
|
|
Logger.debug("")
|
|
|
|
Logger.debug("")
|
|
|
|
|
|
|
|
|
|
|
|
guard let collectionView = self.collectionView else {
|
|
|
|
hasPressedDoneSinceAppeared = true
|
|
|
|
owsFailDebug("collectionView was unexpectedly nil")
|
|
|
|
updateDoneButton()
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let indexPaths = collectionView.indexPathsForSelectedItems else {
|
|
|
|
// Honor selection order.
|
|
|
|
owsFailDebug("indexPaths was unexpectedly nil")
|
|
|
|
var assetIdToAssetIndexMap = [String: Int]()
|
|
|
|
return
|
|
|
|
let assetCount = photoCollectionContents.assetCount
|
|
|
|
|
|
|
|
for index in 0..<assetCount {
|
|
|
|
|
|
|
|
let asset = photoCollectionContents.asset(at: index)
|
|
|
|
|
|
|
|
let assetId = asset.localIdentifier
|
|
|
|
|
|
|
|
assetIdToAssetIndexMap[assetId] = index
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var assets = [PHAsset]()
|
|
|
|
|
|
|
|
for selectedIdAny in selectedIds.array {
|
|
|
|
|
|
|
|
guard let selectedId = selectedIdAny as? String else {
|
|
|
|
|
|
|
|
owsFailDebug("Invalid asset id: \(selectedIdAny)")
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let assetIndex = assetIdToAssetIndexMap[selectedId] else {
|
|
|
|
|
|
|
|
owsFailDebug("Missing asset id: \(selectedId)")
|
|
|
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
assets.append(photoCollectionContents.asset(at: assetIndex))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
hasPressedDoneSinceAppeared = true
|
|
|
|
|
|
|
|
updateDoneButton()
|
|
|
|
|
|
|
|
let assets: [PHAsset] = indexPaths.compactMap { return photoCollectionContents.asset(at: $0.row) }
|
|
|
|
|
|
|
|
complete(withAssets: assets)
|
|
|
|
complete(withAssets: assets)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -381,7 +393,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
selectedIds = Set()
|
|
|
|
selectedIds.removeAllObjects()
|
|
|
|
collectionView.indexPathsForSelectedItems?.forEach { collectionView.deselectItem(at: $0, animated: false)}
|
|
|
|
collectionView.indexPathsForSelectedItems?.forEach { collectionView.deselectItem(at: $0, animated: false)}
|
|
|
|
|
|
|
|
|
|
|
|
if isInBatchSelectMode {
|
|
|
|
if isInBatchSelectMode {
|
|
|
@ -510,7 +522,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat
|
|
|
|
|
|
|
|
|
|
|
|
let asset = photoCollectionContents.asset(at: indexPath.item)
|
|
|
|
let asset = photoCollectionContents.asset(at: indexPath.item)
|
|
|
|
let assetId = asset.localIdentifier
|
|
|
|
let assetId = asset.localIdentifier
|
|
|
|
selectedIds.insert(assetId)
|
|
|
|
selectedIds.add(assetId)
|
|
|
|
|
|
|
|
|
|
|
|
if isInBatchSelectMode {
|
|
|
|
if isInBatchSelectMode {
|
|
|
|
updateDoneButton()
|
|
|
|
updateDoneButton()
|
|
|
|