Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #9229: Remember options for delete browsing data.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcarare committed Jun 18, 2020
1 parent 6c827bd commit 22951e3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,56 @@ import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.ext.showToolbar
import org.mozilla.fenix.utils.Settings

@SuppressWarnings("TooManyFunctions")
class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_data) {

private lateinit var controller: DeleteBrowsingDataController
private var scope: CoroutineScope? = null
private lateinit var settings: Settings

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

controller = DefaultDeleteBrowsingDataController(requireContext())
settings = requireContext().settings()

getCheckboxes().forEach {
it.onCheckListener = { _ -> updateDeleteButton() }
it.onCheckListener = { _ ->
updateDeleteButton()
updatePreference(it)
}
}

getCheckboxes().forEach { it.isChecked = true }
getCheckboxes().forEach {
it.isChecked = when (it.id) {
R.id.open_tabs_item -> settings.deleteOpenTabs
R.id.browsing_data_item -> settings.deleteBrowsingHistory
R.id.cookies_item -> settings.deleteCookies
R.id.cached_files_item -> settings.deleteCache
R.id.site_permissions_item -> settings.deleteSitePermissions
else -> true
}
}

view.delete_data?.setOnClickListener {
askToDelete()
}
updateDeleteButton()
}

private fun updatePreference(it: DeleteBrowsingDataItem) {
when (it.id) {
R.id.open_tabs_item -> settings.deleteOpenTabs = it.isChecked
R.id.browsing_data_item -> settings.deleteBrowsingHistory = it.isChecked
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
else -> return
}
}

@ExperimentalCoroutinesApi
Expand Down Expand Up @@ -138,10 +166,6 @@ class DeleteBrowsingDataFragment : Fragment(R.layout.fragment_delete_browsing_da
delete_browsing_data_wrapper.isClickable = true
delete_browsing_data_wrapper.alpha = ENABLED_ALPHA

getCheckboxes().forEach {
it.isChecked = false
}

updateItemCounts()

FenixSnackbar.make(
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/org/mozilla/fenix/utils/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,31 @@ class Settings private constructor(
default = false
)

var deleteOpenTabs by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_delete_open_tabs_now),
default = true
)

var deleteBrowsingHistory by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_delete_browsing_history_now),
default = true
)

var deleteCookies by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_delete_cookies_now),
default = true
)

var deleteCache by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_delete_caches_now),
default = true
)

var deleteSitePermissions by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_delete_permissions_now),
default = true
)

var shouldUseBottomToolbar by booleanPreference(
appContext.getPreferenceKey(R.string.pref_key_toolbar_bottom),
// Default accessibility users to top toolbar
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/preference_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<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_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_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>
Expand Down

0 comments on commit 22951e3

Please sign in to comment.