parent
2de6a9aca7
commit
485ccba189
|
@ -80,6 +80,7 @@ import org.mozilla.fenix.ext.metrics
|
|||
import org.mozilla.fenix.ext.nav
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.getRootView
|
||||
import org.mozilla.fenix.isInExperiment
|
||||
import org.mozilla.fenix.quickactionsheet.QuickActionSheetBehavior
|
||||
import org.mozilla.fenix.settings.SupportUtils
|
||||
|
@ -165,8 +166,17 @@ abstract class BaseBrowserFragment : Fragment(), BackHandler, SessionManager.Obs
|
|||
|
||||
return getSessionById()?.also { session ->
|
||||
|
||||
// We need to show the snackbar while the browsing data is deleting(if "Delete
|
||||
// browsing data on quit" is activated). After the deletion is over, the snackbar
|
||||
// is dismissed.
|
||||
val snackbar: FenixSnackbar? = requireActivity().getRootView()?.let { v ->
|
||||
FenixSnackbar.make(v, Snackbar.LENGTH_INDEFINITE)
|
||||
.setText(v.context.getString(R.string.deleting_browsing_data_in_progress))
|
||||
}
|
||||
|
||||
val browserToolbarController = DefaultBrowserToolbarController(
|
||||
requireActivity(),
|
||||
snackbar,
|
||||
findNavController(),
|
||||
(activity as HomeActivity).browsingModeManager,
|
||||
findInPageLauncher = { findInPageIntegration.withFeature { it.launch() } },
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.mozilla.fenix.browser.BrowserFragmentDirections
|
|||
import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
||||
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
||||
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.ext.components
|
||||
import org.mozilla.fenix.ext.nav
|
||||
|
@ -54,6 +55,7 @@ interface BrowserToolbarController {
|
|||
@Suppress("LargeClass")
|
||||
class DefaultBrowserToolbarController(
|
||||
private val activity: Activity,
|
||||
private val snackbar: FenixSnackbar?,
|
||||
private val navController: NavController,
|
||||
private val browsingModeManager: BrowsingModeManager,
|
||||
private val findInPageLauncher: () -> Unit,
|
||||
|
@ -206,7 +208,7 @@ class DefaultBrowserToolbarController(
|
|||
// Close this activity since it is no longer displaying any session
|
||||
activity.finish()
|
||||
}
|
||||
ToolbarMenu.Item.Quit -> deleteAndQuit(activity, scope)
|
||||
ToolbarMenu.Item.Quit -> deleteAndQuit(activity, scope, snackbar)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -693,10 +693,18 @@ class HomeFragment : Fragment() {
|
|||
from = BrowserDirection.FromHome
|
||||
)
|
||||
}
|
||||
// We need to show the snackbar while the browsing data is deleting(if "Delete
|
||||
// browsing data on quit" is activated). After the deletion is over, the snackbar
|
||||
// is dismissed.
|
||||
HomeMenu.Item.Quit -> activity?.let { activity ->
|
||||
deleteAndQuit(
|
||||
activity,
|
||||
lifecycleScope
|
||||
lifecycleScope,
|
||||
view?.let { view ->
|
||||
FenixSnackbar.make(view, Snackbar.LENGTH_INDEFINITE)
|
||||
.setText(view.context.getString(R.string.deleting_browsing_data_in_progress))
|
||||
.setAnchorView(bottom_bar)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,16 +10,19 @@ import kotlinx.coroutines.Dispatchers.IO
|
|||
import kotlinx.coroutines.joinAll
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.ext.settings
|
||||
|
||||
/**
|
||||
* Deletes selected browsing data and finishes the activity.
|
||||
*/
|
||||
fun deleteAndQuit(activity: Activity, coroutineScope: CoroutineScope) {
|
||||
fun deleteAndQuit(activity: Activity, coroutineScope: CoroutineScope, snackbar: FenixSnackbar?) {
|
||||
coroutineScope.launch {
|
||||
val settings = activity.settings()
|
||||
val controller = DefaultDeleteBrowsingDataController(activity, coroutineContext)
|
||||
|
||||
snackbar?.show()
|
||||
|
||||
DeleteBrowsingDataOnQuitType.values().map { type ->
|
||||
launch {
|
||||
if (settings.getDeleteDataOnQuit(type)) {
|
||||
|
@ -28,6 +31,8 @@ fun deleteAndQuit(activity: Activity, coroutineScope: CoroutineScope) {
|
|||
}
|
||||
}.joinAll()
|
||||
|
||||
snackbar?.dismiss()
|
||||
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -740,6 +740,8 @@
|
|||
<string name="delete_browsing_data_prompt_allow">Delete</string>
|
||||
<!-- Text for the snackbar confirmation that the data was deleted -->
|
||||
<string name="preferences_delete_browsing_data_snackbar">Browsing data deleted</string>
|
||||
<!-- Text for the snackbar to show the user that the deletion of browsing data is in progress -->
|
||||
<string name="deleting_browsing_data_in_progress">Deleting browsing data…</string>
|
||||
|
||||
<!-- Onboarding -->
|
||||
<!-- Text for onboarding welcome message
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.mozilla.fenix.browser.browsingmode.BrowsingMode
|
|||
import org.mozilla.fenix.browser.browsingmode.BrowsingModeManager
|
||||
import org.mozilla.fenix.collections.CreateCollectionViewModel
|
||||
import org.mozilla.fenix.components.Analytics
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.metrics.Event
|
||||
import org.mozilla.fenix.components.metrics.MetricController
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
@ -77,6 +78,7 @@ class DefaultBrowserToolbarControllerTest {
|
|||
private val sessionUseCases: SessionUseCases = mockk(relaxed = true)
|
||||
private val scope: LifecycleCoroutineScope = mockk(relaxed = true)
|
||||
private val adjustBackgroundAndNavigate: (NavDirections) -> Unit = mockk(relaxed = true)
|
||||
private val snackbar = mockk<FenixSnackbar>(relaxed = true)
|
||||
|
||||
private lateinit var controller: DefaultBrowserToolbarController
|
||||
|
||||
|
@ -86,6 +88,7 @@ class DefaultBrowserToolbarControllerTest {
|
|||
|
||||
controller = DefaultBrowserToolbarController(
|
||||
activity = activity,
|
||||
snackbar = snackbar,
|
||||
navController = navController,
|
||||
browsingModeManager = browsingModeManager,
|
||||
findInPageLauncher = findInPageLauncher,
|
||||
|
@ -109,7 +112,7 @@ class DefaultBrowserToolbarControllerTest {
|
|||
mockkStatic(
|
||||
"org.mozilla.fenix.settings.deletebrowsingdata.DeleteAndQuitKt"
|
||||
)
|
||||
every { deleteAndQuit(any(), any()) } just Runs
|
||||
every { deleteAndQuit(any(), any(), snackbar) } just Runs
|
||||
|
||||
every { activity.components.analytics } returns analytics
|
||||
every { analytics.metrics } returns metrics
|
||||
|
@ -429,6 +432,7 @@ class DefaultBrowserToolbarControllerTest {
|
|||
fun handleToolbarOpenInFenixPress() {
|
||||
controller = DefaultBrowserToolbarController(
|
||||
activity = activity,
|
||||
snackbar = snackbar,
|
||||
navController = navController,
|
||||
browsingModeManager = browsingModeManager,
|
||||
findInPageLauncher = findInPageLauncher,
|
||||
|
@ -466,6 +470,6 @@ class DefaultBrowserToolbarControllerTest {
|
|||
|
||||
controller.handleToolbarItemInteraction(item)
|
||||
|
||||
verify { deleteAndQuit(activity, scope) }
|
||||
verify { deleteAndQuit(activity, scope, snackbar) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
|
|||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import io.mockk.verifyOrder
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.ObsoleteCoroutinesApi
|
||||
|
@ -28,6 +29,7 @@ import org.junit.Test
|
|||
import org.junit.runner.RunWith
|
||||
import org.mozilla.fenix.HomeActivity
|
||||
import org.mozilla.fenix.TestApplication
|
||||
import org.mozilla.fenix.components.FenixSnackbar
|
||||
import org.mozilla.fenix.components.PermissionStorage
|
||||
import org.mozilla.fenix.ext.clearAndCommit
|
||||
import org.mozilla.fenix.ext.components
|
||||
|
@ -49,6 +51,7 @@ class DeleteAndQuitTest {
|
|||
private val permissionStorage: PermissionStorage = mockk(relaxed = true)
|
||||
private val engine: Engine = mockk(relaxed = true)
|
||||
private val removeAllTabsUseCases: TabsUseCases.RemoveAllTabsUseCase = mockk(relaxed = true)
|
||||
private val snackbar = mockk<FenixSnackbar>(relaxed = true)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
|
@ -80,10 +83,12 @@ class DeleteAndQuitTest {
|
|||
// When
|
||||
settings.setDeleteDataOnQuit(DeleteBrowsingDataOnQuitType.TABS, true)
|
||||
|
||||
deleteAndQuit(activity, this)
|
||||
deleteAndQuit(activity, this, snackbar)
|
||||
|
||||
verify {
|
||||
verifyOrder {
|
||||
snackbar.show()
|
||||
removeAllTabsUseCases.invoke()
|
||||
snackbar.dismiss()
|
||||
activity.finish()
|
||||
}
|
||||
|
||||
|
@ -110,9 +115,11 @@ class DeleteAndQuitTest {
|
|||
settings.setDeleteDataOnQuit(it, true)
|
||||
}
|
||||
|
||||
deleteAndQuit(activity, this)
|
||||
deleteAndQuit(activity, this, snackbar)
|
||||
|
||||
verify(exactly = 1) {
|
||||
snackbar.show()
|
||||
|
||||
engine.clearData(Engine.BrowsingData.allCaches())
|
||||
|
||||
removeAllTabsUseCases.invoke()
|
||||
|
@ -134,6 +141,8 @@ class DeleteAndQuitTest {
|
|||
|
||||
historyStorage
|
||||
|
||||
snackbar.dismiss()
|
||||
|
||||
activity.finish()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue