For #2655: Adds undo snackbar for closing all tabs
parent
f5a993a027
commit
a1d32127ab
|
@ -80,6 +80,7 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
|
|
||||||
private var homeMenu: HomeMenu? = null
|
private var homeMenu: HomeMenu? = null
|
||||||
|
|
||||||
|
var deleteAllSessionsJob: (suspend () -> Unit)? = null
|
||||||
var deleteSessionJob: (suspend () -> Unit)? = null
|
var deleteSessionJob: (suspend () -> Unit)? = null
|
||||||
var deleteCollectionJob: (suspend () -> Unit)? = null
|
var deleteCollectionJob: (suspend () -> Unit)? = null
|
||||||
|
|
||||||
|
@ -299,7 +300,7 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is TabAction.CloseAll -> {
|
is TabAction.CloseAll -> {
|
||||||
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(action.private)
|
removeAllTabsWithUndo(action.private)
|
||||||
}
|
}
|
||||||
is TabAction.PrivateBrowsingLearnMore -> {
|
is TabAction.PrivateBrowsingLearnMore -> {
|
||||||
(activity as HomeActivity).openToBrowserAndLoad(
|
(activity as HomeActivity).openToBrowserAndLoad(
|
||||||
|
@ -333,6 +334,14 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
deleteAllSessionsJob?.let {
|
||||||
|
launch {
|
||||||
|
it.invoke()
|
||||||
|
}.invokeOnCompletion {
|
||||||
|
deleteAllSessionsJob = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deleteCollectionJob?.let {
|
deleteCollectionJob?.let {
|
||||||
launch {
|
launch {
|
||||||
it.invoke()
|
it.invoke()
|
||||||
|
@ -493,6 +502,23 @@ class HomeFragment : Fragment(), CoroutineScope {
|
||||||
return observer
|
return observer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun removeAllTabsWithUndo(isPrivate: Boolean) {
|
||||||
|
getManagedEmitter<SessionControlChange>().onNext(SessionControlChange.TabsChange(listOf()))
|
||||||
|
deleteAllSessionsJob = {
|
||||||
|
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(isPrivate)
|
||||||
|
}
|
||||||
|
|
||||||
|
CoroutineScope(Dispatchers.Main).allowUndo(
|
||||||
|
view!!, getString(R.string.snackbar_tabs_deleted),
|
||||||
|
getString(R.string.snackbar_deleted_undo), {
|
||||||
|
deleteAllSessionsJob = null
|
||||||
|
emitSessionChanges()
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
requireComponents.useCases.tabsUseCases.removeAllTabsOfType.invoke(isPrivate)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun removeTabWithUndo(sessionId: String) {
|
private fun removeTabWithUndo(sessionId: String) {
|
||||||
val sessionManager = requireComponents.core.sessionManager
|
val sessionManager = requireComponents.core.sessionManager
|
||||||
|
|
||||||
|
|
|
@ -484,6 +484,8 @@
|
||||||
<string name="snackbar_collection_renamed">Collection renamed</string>
|
<string name="snackbar_collection_renamed">Collection renamed</string>
|
||||||
<!-- Text shown in snackbar when user deletes a tab -->
|
<!-- Text shown in snackbar when user deletes a tab -->
|
||||||
<string name="snackbar_tab_deleted">Tab deleted</string>
|
<string name="snackbar_tab_deleted">Tab deleted</string>
|
||||||
|
<!-- Text shown in snackbar when user deletes all tabs -->
|
||||||
|
<string name="snackbar_tabs_deleted">Tabs deleted</string>
|
||||||
<!-- Text for action to undo deleting a tab or collection shown in snackbar -->
|
<!-- Text for action to undo deleting a tab or collection shown in snackbar -->
|
||||||
<string name="snackbar_deleted_undo">UNDO</string>
|
<string name="snackbar_deleted_undo">UNDO</string>
|
||||||
<!-- QR code scanner prompt which appears after scanning a code, but before navigating to it
|
<!-- QR code scanner prompt which appears after scanning a code, but before navigating to it
|
||||||
|
|
Loading…
Reference in New Issue