2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-17 15:26:23 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/15181: Remove All Downloads From Settings

This commit is contained in:
Kate Glazko 2020-12-10 11:06:42 -08:00 committed by kglazko
parent 23496ce12b
commit e511381cf3
10 changed files with 62 additions and 7 deletions

View File

@ -24,6 +24,7 @@ fun deleteAndQuit(activity: Activity, coroutineScope: CoroutineScope, snackbar:
val settings = activity.settings()
val controller = DefaultDeleteBrowsingDataController(
activity.components.useCases.tabsUseCases.removeAllTabs,
activity.components.useCases.downloadUseCases.removeAllDownloads,
activity.components.core.historyStorage,
activity.components.core.permissionStorage,
activity.components.core.store,
@ -61,5 +62,6 @@ private suspend fun DeleteBrowsingDataController.deleteType(type: DeleteBrowsing
DeleteBrowsingDataOnQuitType.PERMISSIONS -> withContext(IO) {
deleteSitePermissions()
}
DeleteBrowsingDataOnQuitType.DOWNLOADS -> deleteDownloads()
}
}

View File

@ -12,6 +12,7 @@ import mozilla.components.browser.state.action.RecentlyClosedAction
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
import mozilla.components.concept.storage.HistoryStorage
import mozilla.components.feature.downloads.DownloadsUseCases
import mozilla.components.feature.tabs.TabsUseCases
import org.mozilla.fenix.components.PermissionStorage
import kotlin.coroutines.CoroutineContext
@ -22,10 +23,12 @@ interface DeleteBrowsingDataController {
suspend fun deleteCookies()
suspend fun deleteCachedFiles()
suspend fun deleteSitePermissions()
suspend fun deleteDownloads()
}
class DefaultDeleteBrowsingDataController(
private val removeAllTabs: TabsUseCases.RemoveAllTabsUseCase,
private val removeAllDownloads: DownloadsUseCases.RemoveAllDownloadsUseCase,
private val historyStorage: HistoryStorage,
private val permissionStorage: PermissionStorage,
private val store: BrowserStore,
@ -77,4 +80,10 @@ class DefaultDeleteBrowsingDataController(
}
permissionStorage.deleteAllSitePermissions()
}
override suspend fun deleteDownloads() {
withContext(coroutineContext) {
removeAllDownloads.invoke()
}
}
}

View File

@ -33,7 +33,7 @@ import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.utils.Settings
@SuppressWarnings("TooManyFunctions")
@SuppressWarnings("TooManyFunctions", "LargeClass")
class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_data) {
private lateinit var controller: DeleteBrowsingDataController
@ -42,9 +42,11 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val tabsUseCases = requireComponents.useCases.tabsUseCases
val downloadUseCases = requireComponents.useCases.downloadUseCases
controller = DefaultDeleteBrowsingDataController(
requireComponents.useCases.tabsUseCases.removeAllTabs,
tabsUseCases.removeAllTabs,
downloadUseCases.removeAllDownloads,
requireComponents.core.historyStorage,
requireComponents.core.permissionStorage,
requireComponents.core.store,
@ -67,6 +69,7 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
R.id.cookies_item -> settings.deleteCookies
R.id.cached_files_item -> settings.deleteCache
R.id.site_permissions_item -> settings.deleteSitePermissions
R.id.downloads_item -> settings.deleteDownloads
else -> true
}
}
@ -84,6 +87,7 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
R.id.cookies_item -> settings.deleteCookies = it.isChecked
R.id.cached_files_item -> settings.deleteCache = it.isChecked
R.id.site_permissions_item -> settings.deleteSitePermissions = it.isChecked
R.id.downloads_item -> settings.deleteDownloads = it.isChecked
else -> return
}
}
@ -151,6 +155,7 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
COOKIES_INDEX -> controller.deleteCookies()
CACHED_INDEX -> controller.deleteCachedFiles()
PERMS_INDEX -> controller.deleteSitePermissions()
DOWNLOADS_INDEX -> controller.deleteDownloads()
}
}
}
@ -262,7 +267,8 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
fragmentView.browsing_data_item,
fragmentView.cookies_item,
fragmentView.cached_files_item,
fragmentView.site_permissions_item
fragmentView.site_permissions_item,
fragmentView.downloads_item
)
}
@ -275,5 +281,6 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
private const val COOKIES_INDEX = 2
private const val CACHED_INDEX = 3
private const val PERMS_INDEX = 4
private const val DOWNLOADS_INDEX = 5
}
}

View File

@ -14,7 +14,8 @@ enum class DeleteBrowsingDataOnQuitType(@StringRes private val prefKey: Int) {
HISTORY(R.string.pref_key_delete_browsing_history_on_quit),
COOKIES(R.string.pref_key_delete_cookies_on_quit),
CACHE(R.string.pref_key_delete_caches_on_quit),
PERMISSIONS(R.string.pref_key_delete_permissions_on_quit);
PERMISSIONS(R.string.pref_key_delete_permissions_on_quit),
DOWNLOADS(R.string.pref_key_delete_downloads_on_quit);
fun getPreferenceKey(context: Context) = context.getPreferenceKey(prefKey)
}

View File

@ -532,6 +532,11 @@ class Settings(private val appContext: Context) : PreferencesHolder {
default = true
)
var deleteDownloads by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_delete_downloads_now),
default = true
)
var shouldUseBottomToolbar by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_toolbar_bottom),
// Default accessibility users to top toolbar

View File

@ -76,6 +76,15 @@
android:focusable="true"
android:visibility="gone"
app:deleteBrowsingDataItemTitle="@string/preferences_delete_browsing_data_site_permissions" />
<org.mozilla.fenix.settings.deletebrowsingdata.DeleteBrowsingDataItem
android:id="@+id/downloads_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:visibility="gone"
app:deleteBrowsingDataItemTitle="@string/preferences_delete_browsing_data_downloads" />
<com.google.android.material.button.MaterialButton
android:id="@+id/delete_data"
style="@style/DestructiveButton"

View File

@ -27,11 +27,13 @@
<string name="pref_key_delete_cookies_on_quit" translatable="false">pref_key_delete_cookies_on_quit</string>
<string name="pref_key_delete_caches_on_quit" translatable="false">pref_key_delete_caches_on_quit</string>
<string name="pref_key_delete_permissions_on_quit" translatable="false">pref_key_delete_permissions_on_quit</string>
<string name="pref_key_delete_downloads_on_quit" translatable="false">pref_key_delete_downloads_on_quit</string>
<string name="pref_key_delete_open_tabs_now" translatable="false">pref_key_delete_open_tabs_now</string>
<string name="pref_key_delete_browsing_history_now" translatable="false">pref_key_delete_browsing_history_now</string>
<string name="pref_key_delete_cookies_now" translatable="false">pref_key_delete_cookies_now</string>
<string name="pref_key_delete_caches_now" translatable="false">pref_key_delete_caches_now</string>
<string name="pref_key_delete_permissions_now" translatable="false">pref_key_delete_permissions_now</string>
<string name="pref_key_delete_downloads_now" translatable="false">pref_key_delete_downloads_now</string>
<string name="pref_key_delete_browsing_data_on_quit_categories" translatable="false">pref_key_delete_browsing_data_on_quit_categories</string>
<string name="pref_key_last_known_mode_private" translatable="false">pref_key_last_known_mode_private</string>
<string name="pref_key_addons" translatable="false">pref_key_addons</string>

View File

@ -1066,6 +1066,8 @@
<string name="preferences_delete_browsing_data_cached_files_subtitle">Frees up storage space</string>
<!-- Title for the site permissions item in Delete browsing data -->
<string name="preferences_delete_browsing_data_site_permissions">Site permissions</string>
<!-- Title for the downloads item in Delete browsing data -->
<string name="preferences_delete_browsing_data_downloads">Downloads</string>
<!-- Text for the button to delete browsing data -->
<string name="preferences_delete_browsing_data_button">Delete browsing data</string>
<!-- Title for the Delete browsing data on quit preference -->

View File

@ -37,5 +37,10 @@
android:key="@string/pref_key_delete_permissions_on_quit"
android:layout="@layout/checkbox_left_preference"
android:title="@string/preferences_delete_browsing_data_site_permissions" />
<CheckBoxPreference
android:key="@string/pref_key_delete_downloads_on_quit"
android:layout="@layout/checkbox_left_preference"
android:title="@string/preferences_delete_browsing_data_downloads" />
</PreferenceCategory>
</androidx.preference.PreferenceScreen>

View File

@ -18,6 +18,7 @@ import mozilla.components.browser.state.action.RecentlyClosedAction
import mozilla.components.browser.state.store.BrowserStore
import mozilla.components.concept.engine.Engine
import mozilla.components.concept.storage.HistoryStorage
import mozilla.components.feature.downloads.DownloadsUseCases
import mozilla.components.feature.tabs.TabsUseCases
import mozilla.components.support.test.rule.MainCoroutineRule
import org.junit.After
@ -35,6 +36,7 @@ class DefaultDeleteBrowsingDataControllerTest {
val coroutinesTestRule = MainCoroutineRule(testDispatcher)
private var removeAllTabs: TabsUseCases.RemoveAllTabsUseCase = mockk(relaxed = true)
private var removeAllDownloads: DownloadsUseCases.RemoveAllDownloadsUseCase = mockk(relaxed = true)
private var historyStorage: HistoryStorage = mockk(relaxed = true)
private var permissionStorage: PermissionStorage = mockk(relaxed = true)
private var store: BrowserStore = mockk(relaxed = true)
@ -46,6 +48,7 @@ class DefaultDeleteBrowsingDataControllerTest {
fun setup() {
controller = DefaultDeleteBrowsingDataController(
removeAllTabs = removeAllTabs,
removeAllDownloads = removeAllDownloads,
historyStorage = historyStorage,
store = store,
permissionStorage = permissionStorage,
@ -117,4 +120,14 @@ class DefaultDeleteBrowsingDataControllerTest {
permissionStorage.deleteAllSitePermissions()
}
}
@Test
fun deleteDownloads() = runBlockingTest {
controller.deleteDownloads()
verify {
removeAllDownloads.invoke()
}
}
}