diff --git a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaSelectionContext.h b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaSelectionContext.h index 7b9c10199c..5770bf78b9 100644 --- a/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaSelectionContext.h +++ b/submodules/LegacyComponents/PublicHeaders/LegacyComponents/TGMediaSelectionContext.h @@ -41,6 +41,7 @@ - (SSignal *)selectionChangedSignal; - (void)enumerateSelectedItems:(void (^)(id))enumerationBlock; +- (void)enumerateDeselectedItems:(void (^)(id))enumerationBlock; - (NSOrderedSet *)selectedItemsIdentifiers; - (NSArray *)selectedItems; diff --git a/submodules/LegacyComponents/Sources/TGMediaSelectionContext.m b/submodules/LegacyComponents/Sources/TGMediaSelectionContext.m index e5ba124a3b..dcb967ce39 100644 --- a/submodules/LegacyComponents/Sources/TGMediaSelectionContext.m +++ b/submodules/LegacyComponents/Sources/TGMediaSelectionContext.m @@ -188,7 +188,7 @@ if (enumerationBlock == nil) return; - for (NSArray *identifier in _selectedIdentifiers) + for (NSString *identifier in _selectedIdentifiers) { NSObject *item = _selectionMap[identifier]; if (item != nil) { @@ -197,6 +197,22 @@ } } +- (void)enumerateDeselectedItems:(void (^)(id))enumerationBlock +{ + if (enumerationBlock == nil || _savedSelectedIdentifiers == nil) + return; + + for (NSString *identifier in _savedSelectedIdentifiers) + { + if (![_selectedIdentifiers containsObject:identifier]) { + NSObject *item = _selectionMap[identifier]; + if (item != nil) { + enumerationBlock(item); + } + } + } +} + - (NSOrderedSet *)selectedItemsIdentifiers { return [[NSOrderedSet alloc] initWithArray:_selectedIdentifiers]; diff --git a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift index 6c5d9679a1..381c666358 100644 --- a/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift +++ b/submodules/MediaPickerUI/Sources/MediaPickerScreen.swift @@ -1156,7 +1156,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { selectionState.setItem(item, selected: value) if showUndo { - strongSelf.showSelectionUndo(item: item, count: Int32(selectionState.savedStateDifference())) + strongSelf.showSelectionUndo(item: item) } } }, sendSelected: { [weak self] currentItem, silently, scheduleTime, animated, completion in @@ -1199,7 +1199,7 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { } private weak var undoOverlayController: UndoOverlayController? - private func showSelectionUndo(item: TGMediaSelectableItem, count: Int32) { + private func showSelectionUndo(item: TGMediaSelectableItem) { var asset: PHAsset? if let item = item as? TGMediaAsset { asset = item.backingAsset @@ -1219,12 +1219,36 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { return } + var photosCount = 0 + var videosCount = 0 + strongSelf.interaction?.selectionState?.enumerateDeselectedItems({ item in + if let item = item as? TGMediaAsset { + if item.isVideo { + videosCount += 1 + } else { + photosCount += 1 + } + } else if let _ = item as? TGCameraCapturedVideo { + videosCount += 1 + } + }) + let totalCount = Int32(photosCount + videosCount) + let presentationData = strongSelf.presentationData + let text: String + if photosCount > 0 && videosCount > 0 { + text = presentationData.strings.Attachment_DeselectedItems(totalCount) + } else if photosCount > 0 { + text = presentationData.strings.Attachment_DeselectedPhotos(totalCount) + } else if videosCount > 0 { + text = presentationData.strings.Attachment_DeselectedVideos(totalCount) + } else { + text = presentationData.strings.Attachment_DeselectedItems(totalCount) + } + if let undoOverlayController = strongSelf.undoOverlayController { - let text = presentationData.strings.Attachment_DeselectedItems(count) undoOverlayController.content = .image(image: image ?? UIImage(), text: text) } else { - let text = presentationData.strings.Attachment_DeselectedItems(count) let undoOverlayController = UndoOverlayController(presentationData: presentationData, content: .image(image: image ?? UIImage(), text: text), elevatedLayout: true, action: { [weak self] action in guard let strongSelf = self else { return true @@ -1287,7 +1311,8 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable { if let selectionState = self.interaction?.selectionState, selectionState.count() > 0 { let controller = textAlertController(context: self.context, title: nil, text: self.presentationData.strings.Attachment_CancelSelectionAlertText, actions: [TextAlertAction(type: .genericAction, title: self.presentationData.strings.Attachment_CancelSelectionAlertNo, action: { - }), TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Attachment_CancelSelectionAlertYes, action: { + }), TextAlertAction(type: .defaultAction, title: self.presentationData.strings.Attachment_CancelSelectionAlertYes, action: { [weak self] in + self?.dismissAllTooltips() completion() })]) self.present(controller, in: .window(.root))