Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If haven't any new tabs show alert to open new tabs when tap Bookmark all button [TabView] #3668

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 33 additions & 13 deletions DuckDuckGo/TabSwitcherViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,37 @@ class TabSwitcherViewController: UIViewController {
}

@IBAction func onBookmarkAllOpenTabsPressed(_ sender: UIButton) {

let alert = UIAlertController(title: UserText.alertBookmarkAllTitle,
message: UserText.alertBookmarkAllMessage,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: UserText.actionCancel, style: .cancel))
alert.addAction(title: UserText.actionBookmark, style: .default) {
let model = MenuBookmarksViewModel(bookmarksDatabase: self.bookmarksDatabase, syncService: self.syncService)
model.favoritesDisplayMode = AppDependencyProvider.shared.appSettings.favoritesDisplayMode
let result = self.bookmarkAll(viewModel: model)
self.displayBookmarkAllStatusMessage(with: result, openTabsCount: self.tabsModel.tabs.count)
}

present(alert, animated: true, completion: nil)

let alert = UIAlertController(title: UserText.alertBookmarkAllTitle,
message: UserText.alertBookmarkAllMessage,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: UserText.actionCancel, style: .cancel))
alert.addAction(title: UserText.actionBookmark, style: .default) {

let model = MenuBookmarksViewModel(bookmarksDatabase: self.bookmarksDatabase, syncService: self.syncService)
model.favoritesDisplayMode = AppDependencyProvider.shared.appSettings.favoritesDisplayMode
let result = self.bookmarkAll(viewModel: model)

if result.newCount > 0 {
self.displayBookmarkAllStatusMessage(with: result, openTabsCount: self.tabsModel.tabs.count)

} else {
let alert = UIAlertController(title: UserText.alertAlreadyBookmarkedAllTitle,
message: UserText.alertAlreadyBookmarkAllMessage,
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: UserText.actionCancel, style: .cancel))
alert.addAction(title: UserText.actionNewTab, style: .default) {
self.makeActionOnAddPressed()
}
self.present(alert, animated: true, completion: nil)
}

}

present(alert, animated: true, completion: nil)
}


private func bookmarkAll(viewModel: MenuBookmarksInteracting) -> BookmarkAllResult {
let tabs = self.tabsModel.tabs
var newCount = 0
Expand Down Expand Up @@ -292,6 +308,10 @@ class TabSwitcherViewController: UIViewController {
}

@IBAction func onAddPressed(_ sender: UIBarButtonItem) {
self.makeActionOnAddPressed()
}

private func makeActionOnAddPressed() {
guard !isProcessingUpdates else { return }

Pixel.fire(pixel: .tabSwitcherNewTab)
Expand Down
4 changes: 3 additions & 1 deletion DuckDuckGo/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ public struct UserText {
public static let alertSaveFavorite = NSLocalizedString("alert.title.save.favorite", value: "Save Favorite", comment: "Save Favorite action")
public static let alertBookmarkAllTitle = NSLocalizedString("alert.title.bookmarkAll", value: "Bookmark All Tabs?", comment: "Question from confirmation dialog")
public static let alertBookmarkAllMessage = NSLocalizedString("alert.message.bookmarkAll", value: "Existing bookmarks will not be duplicated.", comment: "")

public static let alertAlreadyBookmarkedAllTitle = NSLocalizedString("alert.title.alreadyBookmarkAll", value: "Already BookMarked!", comment: "Question from confirmation dialog")
public static let alertAlreadyBookmarkAllMessage = NSLocalizedString("alert.message.alreadyBookmarkAll", value: "All tabs are already bookmarked. Please add new tab", comment: "")

public static let alertDisableProtection = NSLocalizedString("alert.title.disable.protection", value: "Add to Unprotected Sites", comment: "Disable protection alert")
public static let alertDisableProtectionPlaceholder = NSLocalizedString("alert.title.disable.protection.placeholder", value: "www.example.com", comment: "Disable potection alert placeholder - leave as it is")
public static let messageProtectionDisabled = NSLocalizedString("toast.protection.disabled", value: "Privacy Protection disabled for %@", comment: "Confirmation of an action - populated with a domain name")
Expand Down
6 changes: 6 additions & 0 deletions DuckDuckGo/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@
/* No comment provided by engineer. */
"addWidget.title" = "One tap to your favorite sites.";

/* No comment provided by engineer. */
"alert.message.alreadyBookmarkAll" = "All tabs are already bookmarked. Please add new tab";

/* No comment provided by engineer. */
"alert.message.bookmarkAll" = "Existing bookmarks will not be duplicated.";

Expand Down Expand Up @@ -184,6 +187,9 @@
/* Title of the warning message */
"alert.sync.warning.sync-paused" = "Sync & Backup is Paused";

/* Question from confirmation dialog */
"alert.title.alreadyBookmarkAll" = "Already BookMarked!";

/* Question from confirmation dialog */
"alert.title.bookmarkAll" = "Bookmark All Tabs?";

Expand Down