For #11763: Shows confirmation dialog when deleting last tab from collection
parent
c3acde438a
commit
e39d5b6de7
|
@ -84,11 +84,7 @@ class TabCollectionStorage(
|
|||
}
|
||||
|
||||
fun removeTabFromCollection(tabCollection: TabCollection, tab: Tab) {
|
||||
if (tabCollection.tabs.size == 1) {
|
||||
removeCollection(tabCollection)
|
||||
} else {
|
||||
collectionStorage.removeTabFromCollection(tabCollection, tab)
|
||||
}
|
||||
collectionStorage.removeTabFromCollection(tabCollection, tab)
|
||||
}
|
||||
|
||||
fun renameCollection(tabCollection: TabCollection, title: String) {
|
||||
|
|
|
@ -470,11 +470,10 @@ class HomeFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun showDeleteCollectionPrompt(tabCollection: TabCollection) {
|
||||
private fun showDeleteCollectionPrompt(tabCollection: TabCollection, title: String?, message: String) {
|
||||
val context = context ?: return
|
||||
AlertDialog.Builder(context).apply {
|
||||
val message =
|
||||
context.getString(R.string.tab_collection_dialog_message, tabCollection.title)
|
||||
setTitle(title)
|
||||
setMessage(message)
|
||||
setNegativeButton(R.string.tab_collection_dialog_negative) { dialog: DialogInterface, _ ->
|
||||
dialog.cancel()
|
||||
|
|
|
@ -136,7 +136,7 @@ class DefaultSessionControlController(
|
|||
private val getListOfTabs: () -> List<Tab>,
|
||||
private val hideOnboarding: () -> Unit,
|
||||
private val registerCollectionStorageObserver: () -> Unit,
|
||||
private val showDeleteCollectionPrompt: (tabCollection: TabCollection) -> Unit,
|
||||
private val showDeleteCollectionPrompt: (tabCollection: TabCollection, title: String?, message: String) -> Unit,
|
||||
private val openSettingsScreen: () -> Unit,
|
||||
private val openWhatsNewLink: () -> Unit,
|
||||
private val openPrivacyNotice: () -> Unit,
|
||||
|
@ -196,8 +196,14 @@ class DefaultSessionControlController(
|
|||
override fun handleCollectionRemoveTab(collection: TabCollection, tab: ComponentTab) {
|
||||
metrics.track(Event.CollectionTabRemoved)
|
||||
|
||||
viewLifecycleScope.launch(Dispatchers.IO) {
|
||||
tabCollectionStorage.removeTabFromCollection(collection, tab)
|
||||
if (collection.tabs.size == 1) {
|
||||
val title = activity.resources.getString(R.string.delete_tab_and_collection_dialog_title, collection.title)
|
||||
val message = activity.resources.getString(R.string.delete_tab_and_collection_dialog_message)
|
||||
showDeleteCollectionPrompt(collection, title, message)
|
||||
} else {
|
||||
viewLifecycleScope.launch(Dispatchers.IO) {
|
||||
tabCollectionStorage.removeTabFromCollection(collection, tab)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -207,7 +213,8 @@ class DefaultSessionControlController(
|
|||
}
|
||||
|
||||
override fun handleDeleteCollectionTapped(collection: TabCollection) {
|
||||
showDeleteCollectionPrompt(collection)
|
||||
val message = activity.resources.getString(R.string.tab_collection_dialog_message, collection.title)
|
||||
showDeleteCollectionPrompt(collection, null, message)
|
||||
}
|
||||
|
||||
override fun handleOpenInPrivateTabClicked(topSite: TopSite) {
|
||||
|
|
|
@ -819,6 +819,10 @@
|
|||
<string name="qr_scanner_dialog_negative">DENY</string>
|
||||
<!-- Tab collection deletion prompt dialog message. Placeholder will be replaced with the collection name -->
|
||||
<string name="tab_collection_dialog_message">Are you sure you want to delete %1$s?</string>
|
||||
<!-- Collection and tab deletion prompt dialog message. This will show when the last tab from a collection is deleted -->
|
||||
<string name="delete_tab_and_collection_dialog_message">Deleting this tab will delete the entire collection. You can create new collections at any time.</string>
|
||||
<!-- Collection and tab deletion prompt dialog title. Placeholder will be replaced with the collection name. This will show when the last tab from a collection is deleted -->
|
||||
<string name="delete_tab_and_collection_dialog_title">Delete collection %1$s?</string>
|
||||
<!-- Tab collection deletion prompt dialog option to delete the collection -->
|
||||
<string name="tab_collection_dialog_positive">Delete</string>
|
||||
<!-- Tab collection deletion prompt dialog option to cancel deleting the collection -->
|
||||
|
|
Loading…
Reference in New Issue