From 7a06985f5982a99b1876c3f9d8ee4490f8b12b8b Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 23 Aug 2022 17:21:30 +0900 Subject: [PATCH 1/5] Fixed a dropping asset issue after changing selected photos on the system setting. --- ...tListSelectableDateSectionController.swift | 29 +++++++++++++++++++ NohanaImagePicker/PhotoKitAssetList.swift | 5 ++++ 2 files changed, 34 insertions(+) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index 07fb4ad..b63e843 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -378,6 +378,35 @@ extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver func photoLibraryDidChange(_ changeInstance: PHChange) { DispatchQueue.main.async { [weak self] in guard let self = self else { return } + + let changeDetails = self.photoKitAssetList.changeDetails(changeInstance) + if let beforeResult = changeDetails?.fetchResultBeforeChanges, + let afterResult = changeDetails?.fetchResultAfterChanges { + + var afterAssets: [PHAsset] = [] + var removedAssets: [PHAsset] = [] + for index in 0.. PHFetchResultChangeDetails? { + changeInstance.changeDetails(for: fetchResult) + } + } From f6f34edf9dd26e1d3d4e9f310d2a1418eb3f312a Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Tue, 23 Aug 2022 17:51:29 +0900 Subject: [PATCH 2/5] Removed some codes for debugging. --- .../AssetListSelectableDateSectionController.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index b63e843..d76aab9 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -389,22 +389,17 @@ extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver let asset = afterResult.object(at: index) afterAssets.append(asset) } - print("afterObjects ids: \(afterAssets.map { $0.localIdentifier })") for index in 0.. Date: Thu, 25 Aug 2022 10:34:30 +0900 Subject: [PATCH 3/5] Fixed logic to drop deselected photos in `NohanaImagePickerController`. --- ...tListSelectableDateSectionController.swift | 25 ++++++------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index d76aab9..f613db1 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -379,27 +379,16 @@ extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver DispatchQueue.main.async { [weak self] in guard let self = self else { return } - let changeDetails = self.photoKitAssetList.changeDetails(changeInstance) - if let beforeResult = changeDetails?.fetchResultBeforeChanges, - let afterResult = changeDetails?.fetchResultAfterChanges { - - var afterAssets: [PHAsset] = [] - var removedAssets: [PHAsset] = [] - for index in 0.. Date: Thu, 25 Aug 2022 13:21:47 +0900 Subject: [PATCH 4/5] Deleted an unnecessary function code. --- NohanaImagePicker/PhotoKitAssetList.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/NohanaImagePicker/PhotoKitAssetList.swift b/NohanaImagePicker/PhotoKitAssetList.swift index 025f046..d70bf5c 100644 --- a/NohanaImagePicker/PhotoKitAssetList.swift +++ b/NohanaImagePicker/PhotoKitAssetList.swift @@ -74,9 +74,4 @@ open class PhotoKitAssetList: ItemList { open var endIndex: Int { return fetchResult.count } - - open func changeDetails(_ changeInstance: PHChange) -> PHFetchResultChangeDetails? { - changeInstance.changeDetails(for: fetchResult) - } - } From c2475c1f19536d5dec26d0b6127a036696f433f3 Mon Sep 17 00:00:00 2001 From: NoodleKim Date: Thu, 25 Aug 2022 13:24:31 +0900 Subject: [PATCH 5/5] Fixed processing to update a toolbar's title when changing the number of selected photos. --- .../AssetListSelectableDateSectionController.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NohanaImagePicker/AssetListSelectableDateSectionController.swift b/NohanaImagePicker/AssetListSelectableDateSectionController.swift index f613db1..38cd8e8 100644 --- a/NohanaImagePicker/AssetListSelectableDateSectionController.swift +++ b/NohanaImagePicker/AssetListSelectableDateSectionController.swift @@ -390,6 +390,9 @@ extension AssetListSelectableDateSectionController: PHPhotoLibraryChangeObserver for removedAsset in removedAssets { self.nohanaImagePickerController.dropAsset(removedAsset) } + if !removedAssets.isEmpty { + self.setToolbarTitle(self.nohanaImagePickerController) + } self.photoKitAssetList = PhotoKitAssetList(album: self.photoKitAssetList.assetList, mediaType: self.photoKitAssetList.mediaType, ascending: false) self.dateSectionList = AssetDateSectionCreater().createSections(assetList: self.photoKitAssetList.assetList, options: PhotoKitAssetList.fetchOptions(self.photoKitAssetList.mediaType, ascending: false))