diff --git a/Signal/src/ViewControllers/Photos/ImagePickerController.swift b/Signal/src/ViewControllers/Photos/ImagePickerController.swift index fdb0323f0..d1b784fd3 100644 --- a/Signal/src/ViewControllers/Photos/ImagePickerController.swift +++ b/Signal/src/ViewControllers/Photos/ImagePickerController.swift @@ -8,6 +8,7 @@ import PromiseKit protocol ImagePickerGridControllerDelegate: AnyObject { func imagePickerDidCompleteSelection(_ imagePicker: ImagePickerGridController) + func imagePickerDidCancel(_ imagePicker: ImagePickerGridController) func imagePicker(_ imagePicker: ImagePickerGridController, isAssetSelected asset: PHAsset) -> Bool func imagePicker(_ imagePicker: ImagePickerGridController, didSelectAsset asset: PHAsset, attachmentPromise: Promise) @@ -273,7 +274,7 @@ class ImagePickerGridController: UICollectionViewController, PhotoLibraryDelegat @objc func didPressCancel(sender: UIBarButtonItem) { - self.dismiss(animated: true) + self.delegate?.imagePickerDidCancel(self) } // MARK: - Layout diff --git a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift index e2e7a41b7..cb234fe22 100644 --- a/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift +++ b/Signal/src/ViewControllers/Photos/SendMediaNavigationController.swift @@ -214,6 +214,31 @@ class SendMediaNavigationController: OWSNavigationController { pushViewController(approvalViewController, animated: true) updateButtons() } + + private func didRequestExit(dontAbandonText: String) { + if attachmentDraftCollection.count == 0 { + self.sendMediaNavDelegate?.sendMediaNavDidCancel(self) + } else { + let alertTitle = NSLocalizedString("SEND_MEDIA_ABANDON_TITLE", comment: "alert title when user attempts to leave the send media flow when they have an in-progress album") + + let alert = UIAlertController(title: alertTitle, message: nil, preferredStyle: .alert) + + let confirmAbandonText = NSLocalizedString("SEND_MEDIA_CONFIRM_ABANDON_ALBUM", comment: "alert action, confirming the user wants to exit the media flow and abandon any photos they've taken") + let confirmAbandonAction = UIAlertAction(title: confirmAbandonText, + style: .destructive, + handler: { [weak self] _ in + guard let self = self else { return } + self.sendMediaNavDelegate?.sendMediaNavDidCancel(self) + }) + alert.addAction(confirmAbandonAction) + let dontAbandonAction = UIAlertAction(title: dontAbandonText, + style: .default, + handler: { _ in }) + alert.addAction(dontAbandonAction) + + self.presentAlert(alert) + } + } } extension SendMediaNavigationController: UINavigationControllerDelegate { @@ -266,7 +291,8 @@ extension SendMediaNavigationController: PhotoCaptureViewControllerDelegate { } func photoCaptureViewControllerDidCancel(_ photoCaptureViewController: PhotoCaptureViewController) { - self.sendMediaNavDelegate?.sendMediaNavDidCancel(self) + let dontAbandonText = NSLocalizedString("SEND_MEDIA_RETURN_TO_CAMERA", comment: "alert action when the user decides not to cancel the media flow after all.") + didRequestExit(dontAbandonText: dontAbandonText) } } @@ -276,6 +302,11 @@ extension SendMediaNavigationController: ImagePickerGridControllerDelegate { showApprovalAfterProcessingAnyMediaLibrarySelections() } + func imagePickerDidCancel(_ imagePicker: ImagePickerGridController) { + let dontAbandonText = NSLocalizedString("SEND_MEDIA_RETURN_TO_MEDIA_LIBRARY", comment: "alert action when the user decides not to cancel the media flow after all.") + didRequestExit(dontAbandonText: dontAbandonText) + } + func showApprovalAfterProcessingAnyMediaLibrarySelections() { let mediaLibrarySelections: [MediaLibrarySelection] = self.mediaLibrarySelections.orderedValues diff --git a/Signal/translations/en.lproj/Localizable.strings b/Signal/translations/en.lproj/Localizable.strings index c5585ead8..3066ce983 100644 --- a/Signal/translations/en.lproj/Localizable.strings +++ b/Signal/translations/en.lproj/Localizable.strings @@ -1991,6 +1991,18 @@ /* Text for button to send a Signal invite via SMS. %@ is placeholder for the recipient's phone number. */ "SEND_INVITE_VIA_SMS_BUTTON_FORMAT" = "Invite via SMS: %@"; +/* alert title when user attempts to leave the send media flow when they have an in-progress album */ +"SEND_MEDIA_ABANDON_TITLE" = "Discard Media?"; + +/* alert action, confirming the user wants to exit the media flow and abandon any photos they've taken */ +"SEND_MEDIA_CONFIRM_ABANDON_ALBUM" = "Discard Media"; + +/* alert action when the user decides not to cancel the media flow after all. */ +"SEND_MEDIA_RETURN_TO_CAMERA" = "Return to Camera"; + +/* alert action when the user decides not to cancel the media flow after all. */ +"SEND_MEDIA_RETURN_TO_MEDIA_LIBRARY" = "Return to Media Library"; + /* No comment provided by engineer. */ "SEND_SMS_CONFIRM_TITLE" = "Invite a friend via insecure SMS?";