mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-04 21:41:45 +00:00
Attachment menu improvements
This commit is contained in:
parent
702f254783
commit
17b40e2498
@ -41,6 +41,7 @@
|
||||
- (SSignal *)selectionChangedSignal;
|
||||
|
||||
- (void)enumerateSelectedItems:(void (^)(id<TGMediaSelectableItem>))enumerationBlock;
|
||||
- (void)enumerateDeselectedItems:(void (^)(id<TGMediaSelectableItem>))enumerationBlock;
|
||||
|
||||
- (NSOrderedSet *)selectedItemsIdentifiers;
|
||||
- (NSArray *)selectedItems;
|
||||
|
||||
@ -188,7 +188,7 @@
|
||||
if (enumerationBlock == nil)
|
||||
return;
|
||||
|
||||
for (NSArray *identifier in _selectedIdentifiers)
|
||||
for (NSString *identifier in _selectedIdentifiers)
|
||||
{
|
||||
NSObject<TGMediaSelectableItem> *item = _selectionMap[identifier];
|
||||
if (item != nil) {
|
||||
@ -197,6 +197,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)enumerateDeselectedItems:(void (^)(id<TGMediaSelectableItem>))enumerationBlock
|
||||
{
|
||||
if (enumerationBlock == nil || _savedSelectedIdentifiers == nil)
|
||||
return;
|
||||
|
||||
for (NSString *identifier in _savedSelectedIdentifiers)
|
||||
{
|
||||
if (![_selectedIdentifiers containsObject:identifier]) {
|
||||
NSObject<TGMediaSelectableItem> *item = _selectionMap[identifier];
|
||||
if (item != nil) {
|
||||
enumerationBlock(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSOrderedSet *)selectedItemsIdentifiers
|
||||
{
|
||||
return [[NSOrderedSet alloc] initWithArray:_selectedIdentifiers];
|
||||
|
||||
@ -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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user