From e25076b7678a7cd59a86d4bda11e6be8aa8b2ba6 Mon Sep 17 00:00:00 2001 From: Soner YUKSEL Date: Thu, 26 Oct 2023 12:47:25 -0400 Subject: [PATCH] Fix brave/brave-ios#8236: Adding export fail case and alert for success (brave/brave-ios#8315) --- .../Bookmarks/BookmarksViewController.swift | 46 ++++++++++++++----- Sources/BraveStrings/BraveStrings.swift | 10 +++- 2 files changed, 44 insertions(+), 12 deletions(-) diff --git a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift index bf8a4c3fbaf8..781000adbe04 100644 --- a/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift +++ b/Sources/Brave/Frontend/Browser/Toolbars/BottomToolbar/Menu/Bookmarks/BookmarksViewController.swift @@ -81,6 +81,8 @@ class BookmarksViewController: SiteTableViewController, ToolbarUrlActionsProtoco private var bookmarksSearchQuery = "" private lazy var noSearchResultOverlayView = EmptyStateOverlayView( overlayDetails: EmptyOverlayStateDetails(title: Strings.noSearchResultsfound)) + + private var bookmarksExportSuccessful = false // MARK: Lifecycle @@ -812,6 +814,17 @@ extension BookmarksViewController: UIDocumentPickerDelegate, UIDocumentInteracti try? FileManager.default.removeItem(at: url) } self.documentInteractionController = nil + + if bookmarksExportSuccessful { + bookmarksExportSuccessful = false + + let alert = UIAlertController( + title: Strings.Sync.bookmarksImportExportPopupTitle, + message: Strings.Sync.bookmarksExportPopupSuccessMessage, + preferredStyle: .alert) + alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: nil)) + self.present(alert, animated: true, completion: nil) + } } func documentInteractionControllerDidDismissOpenInMenu(_ controller: UIDocumentInteractionController) { @@ -835,7 +848,7 @@ extension BookmarksViewController { self.isLoading = false let alert = UIAlertController( - title: Strings.Sync.bookmarksImportPopupErrorTitle, + title: Strings.Sync.bookmarksImportExportPopupTitle, message: success ? Strings.Sync.bookmarksImportPopupSuccessMessage : Strings.Sync.bookmarksImportPopupFailureMessage, preferredStyle: .alert) alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: nil)) @@ -850,16 +863,27 @@ extension BookmarksViewController { guard let self = self else { return } self.isLoading = false - - // Controller must be retained otherwise `AirDrop` and other sharing options will fail! - self.documentInteractionController = UIDocumentInteractionController(url: url) - guard let vc = self.documentInteractionController else { return } - vc.uti = UTType.html.identifier - vc.name = "Bookmarks.html" - vc.delegate = self - - guard let importExportButton = self.importExportButton else { return } - vc.presentOptionsMenu(from: importExportButton, animated: true) + + if success { + self.bookmarksExportSuccessful = true + + // Controller must be retained otherwise `AirDrop` and other sharing options will fail! + self.documentInteractionController = UIDocumentInteractionController(url: url) + guard let vc = self.documentInteractionController else { return } + vc.uti = UTType.html.identifier + vc.name = "Bookmarks.html" + vc.delegate = self + + guard let importExportButton = self.importExportButton else { return } + vc.presentOptionsMenu(from: importExportButton, animated: true) + } else { + let alert = UIAlertController( + title: Strings.Sync.bookmarksImportExportPopupTitle, + message: Strings.Sync.bookmarksExportPopupFailureMessage, + preferredStyle: .alert) + alert.addAction(UIAlertAction(title: Strings.OKString, style: .default, handler: nil)) + self.present(alert, animated: true, completion: nil) + } } } diff --git a/Sources/BraveStrings/BraveStrings.swift b/Sources/BraveStrings/BraveStrings.swift index 3fc51d1e5293..de7659c1cbde 100644 --- a/Sources/BraveStrings/BraveStrings.swift +++ b/Sources/BraveStrings/BraveStrings.swift @@ -3227,7 +3227,7 @@ extension Strings { NSLocalizedString("sync.syncV1DeprecationText", tableName: "BraveShared", bundle: .module, value: "A new Brave Sync is coming and will affect your setup. Get ready for the upgrade.", comment: "Text that informs a user about Brave Sync service deprecation.") - public static let bookmarksImportPopupErrorTitle = + public static let bookmarksImportExportPopupTitle = NSLocalizedString("sync.bookmarksImportPopupErrorTitle", tableName: "BraveShared", bundle: .module, value: "Bookmarks", comment: "Title of the bookmark import popup.") @@ -3235,6 +3235,14 @@ extension Strings { NSLocalizedString("sync.bookmarksImportPopupSuccessMessage", tableName: "BraveShared", bundle: .module, value: "Bookmarks Imported Successfully", comment: "Message of the popup if bookmark import succeeds.") + public static let bookmarksExportPopupSuccessMessage = + NSLocalizedString("sync.bookmarksExportPopupSuccessMessage", tableName: "BraveShared", bundle: .module, + value: "Bookmarks Exported Successfully", + comment: "Message of the popup if bookmark export succeeds.") + public static let bookmarksExportPopupFailureMessage = + NSLocalizedString("sync.bookmarksIExportPopupFailureMessage", tableName: "BraveShared", bundle: .module, + value: "Bookmark Export Failed", + comment: "Message of the popup if bookmark export fails.") public static let bookmarksImportPopupFailureMessage = NSLocalizedString("sync.bookmarksImportPopupFailureMessage", tableName: "BraveShared", bundle: .module, value: "Bookmark Import Failed",