1
0
Fork 0

For #11763: Shows confirmation dialog when deleting last tab from collection

master
ValentinTimisica 2020-06-24 11:16:45 +03:00 committed by Emily Kager
parent c3acde438a
commit e39d5b6de7
4 changed files with 18 additions and 12 deletions

View File

@ -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) {

View File

@ -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()

View File

@ -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) {

View File

@ -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 -->