Skip to content

Commit

Permalink
Fix brave/brave-ios#8236: Adding export fail case and alert for succe…
Browse files Browse the repository at this point in the history
  • Loading branch information
soner-yuksel authored Oct 26, 2023
1 parent 7544539 commit e25076b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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) {
Expand All @@ -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))
Expand All @@ -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)
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion Sources/BraveStrings/BraveStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3227,14 +3227,22 @@ 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.")
public static let bookmarksImportPopupSuccessMessage =
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",
Expand Down

0 comments on commit e25076b

Please sign in to comment.