Proper prompt when deleting media from All Media.

Also display confirmation toast after deleting media.
This commit is contained in:
Igor Solomennikov 2023-06-27 14:53:10 -07:00 committed by GitHub
parent 8f6c4df2a9
commit fbce05a8db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 14 deletions

View File

@ -1408,18 +1408,39 @@ extension MediaTileViewController: MediaGalleryPrimaryViewController {
return
}
let format = OWSLocalizedString("MEDIA_GALLERY_DELETE_MESSAGES_%d", tableName: "PluralAware",
comment: "Confirmation button text to delete selected media message(s) from the gallery")
let confirmationTitle = String.localizedStringWithFormat(format, indexPaths.count)
let actionSheetTitle = String.localizedStringWithFormat(
OWSLocalizedString(
"MEDIA_GALLERY_DELETE_MEDIA_TITLE",
tableName: "PluralAware",
comment: "Title for confirmation prompt when deleting N items in All Media screen."
),
indexPaths.count
)
let actionSheetMessage = OWSLocalizedString(
"MEDIA_GALLERY_DELETE_MEDIA_BODY",
comment: "Explanatory text displayed when deleting N items in All Media screen."
)
let toastText = String.localizedStringWithFormat(
OWSLocalizedString(
"MEDIA_GALLERY_DELETE_MEDIA_TOAST",
tableName: "PluralAware",
comment: "Toast displayed after successful deletion of N items in All Media screen."),
indexPaths.count
)
let deleteAction = ActionSheetAction(title: confirmationTitle, style: .destructive) { _ in
let galleryIndexPaths = indexPaths.map { self.mediaGalleryIndexPath($0) }
self.mediaGallery.delete(items: items, atIndexPaths: galleryIndexPaths, initiatedBy: self)
self.accessoriesHelper.endSelectMode()
}
let actionSheet = ActionSheetController(title: nil, message: nil)
actionSheet.addAction(deleteAction)
let actionSheet = ActionSheetController(title: actionSheetTitle, message: actionSheetMessage)
actionSheet.addAction(ActionSheetAction(
title: CommonStrings.deleteButton,
style: .destructive,
handler: { [self] _ in
let galleryIndexPaths = indexPaths.map { self.mediaGalleryIndexPath($0) }
self.mediaGallery.delete(items: items, atIndexPaths: galleryIndexPaths, initiatedBy: self)
self.accessoriesHelper.endSelectMode()
DispatchQueue.main.async {
self.presentToast(text: toastText, extraVInset: self.collectionView.contentInset.bottom)
}
}
))
actionSheet.addAction(OWSActionSheets.cancelAction)
presentActionSheet(actionSheet)

View File

@ -3538,6 +3538,9 @@
/* Shown in place of message input text in media editor when 'View Once' is on. */
"MEDIA_EDITOR_TEXT_FIELD_VIEW_ONCE_MEDIA" = "View Once Media";
/* Explanatory text displayed when deleting N items in All Media screen. */
"MEDIA_GALLERY_DELETE_MEDIA_BODY" = "This will permanently delete the selected files. Any message text associated with these items will also be deleted.";
/* Format for the 'more items' indicator for media galleries. Embeds {{the number of additional items}}. */
"MEDIA_GALLERY_MORE_ITEMS_FORMAT" = "+%@";

View File

@ -653,7 +653,7 @@
<string>%d groups in common</string>
</dict>
</dict>
<key>MEDIA_GALLERY_DELETE_MESSAGES_%d</key>
<key>MEDIA_GALLERY_DELETE_MEDIA_TITLE</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@text@</string>
@ -664,9 +664,25 @@
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>Delete %d Message</string>
<string>Delete %d Item?</string>
<key>other</key>
<string>Delete %d Messages</string>
<string>Delete %d Items?</string>
</dict>
</dict>
<key>MEDIA_GALLERY_DELETE_MEDIA_TOAST</key>
<dict>
<key>NSStringLocalizedFormatKey</key>
<string>%#@text@</string>
<key>text</key>
<dict>
<key>NSStringFormatSpecTypeKey</key>
<string>NSStringPluralRuleType</string>
<key>NSStringFormatValueTypeKey</key>
<string>d</string>
<key>one</key>
<string>One item deleted</string>
<key>other</key>
<string>%d items deleted</string>
</dict>
</dict>
<key>MEDIA_GALLERY_ITEM_IMAGE_COUNT_%d</key>