For #3700 - Add Setting to Delete Data on "Quit" menu action #5098
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -260,7 +260,7 @@ sealed class Event { | |
enum class Item { | ||
SETTINGS, LIBRARY, HELP, DESKTOP_VIEW_ON, DESKTOP_VIEW_OFF, FIND_IN_PAGE, NEW_TAB, | ||
NEW_PRIVATE_TAB, SHARE, REPORT_SITE_ISSUE, BACK, FORWARD, RELOAD, STOP, OPEN_IN_FENIX, | ||
SAVE_TO_COLLECTION, ADD_TO_HOMESCREEN | ||
SAVE_TO_COLLECTION, ADD_TO_HOMESCREEN, QUIT | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @boek how do new events get into the metrics.md file? Do you have to change more files, or does the documentation automatically get added when you just add an event? Should these be updated in the metrics.md file as part of the PR? At a quick glance I also didn't see save_to_collection or add_to_homescreen, so I'm wondering if I'm looking in the wrong place. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need to manually add this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated, @boek does this mean open_in_fenix, save_to_collection, and add_to_homescreen did not get data review, or need to be updated? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @liuche that is correct |
||
} | ||
|
||
override val extras: Map<Events.browserMenuActionKeys, String>? | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.settings | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.preference.CheckBoxPreference | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import androidx.preference.SwitchPreference | ||
import org.mozilla.fenix.R | ||
import org.mozilla.fenix.ext.getPreferenceKey | ||
import org.mozilla.fenix.utils.Settings | ||
|
||
class DeleteBrowsingDataOnQuitFragment : PreferenceFragmentCompat() { | ||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
setPreferencesFromResource(R.xml.delete_browsing_data_quit_preferences, rootKey) | ||
} | ||
|
||
@Suppress("ComplexMethod") | ||
override fun onResume() { | ||
super.onResume() | ||
activity?.title = getString(R.string.preferences_delete_browsing_data_on_quit) | ||
(activity as AppCompatActivity).supportActionBar?.show() | ||
|
||
val checkboxUpdater = object : SharedPreferenceUpdater() { | ||
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { | ||
super.onPreferenceChange(preference, newValue) | ||
if (!Settings.getInstance(preference.context).shouldDeleteAnyDataOnQuit()) { | ||
findPreference<SwitchPreference>( | ||
getPreferenceKey(R.string.pref_key_delete_browsing_data_on_quit) | ||
)?.apply { | ||
isChecked = false | ||
} | ||
Settings.getInstance(preference.context).preferences.edit().putBoolean( | ||
getString(R.string.pref_key_delete_browsing_data_on_quit), | ||
false | ||
).apply() | ||
} | ||
return true | ||
} | ||
} | ||
|
||
val switchUpdater = object : SharedPreferenceUpdater() { | ||
override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean { | ||
setAllCheckboxes(newValue as Boolean) | ||
return super.onPreferenceChange(preference, newValue) | ||
} | ||
} | ||
|
||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_open_tabs_on_quit))?.apply { | ||
onPreferenceChangeListener = checkboxUpdater | ||
} | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_browsing_history_on_quit))?.apply { | ||
onPreferenceChangeListener = checkboxUpdater | ||
} | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_caches_on_quit))?.apply { | ||
onPreferenceChangeListener = checkboxUpdater | ||
} | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_permissions_on_quit))?.apply { | ||
onPreferenceChangeListener = checkboxUpdater | ||
} | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_cookies_on_quit))?.apply { | ||
onPreferenceChangeListener = checkboxUpdater | ||
} | ||
|
||
// Delete Browsing Data on Quit Switch | ||
val deleteOnQuitKey = getPreferenceKey(R.string.pref_key_delete_browsing_data_on_quit) | ||
findPreference<SwitchPreference>(deleteOnQuitKey)?.apply { | ||
onPreferenceChangeListener = switchUpdater | ||
isChecked = Settings.getInstance(context!!).shouldDeleteBrowsingDataOnQuit | ||
} | ||
} | ||
|
||
private fun setAllCheckboxes(newValue: Boolean) { | ||
val openTabs = | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_open_tabs_on_quit)) | ||
val history = | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_browsing_history_on_quit)) | ||
val cache = | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_caches_on_quit)) | ||
val permissions = | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_permissions_on_quit)) | ||
val cookies = | ||
findPreference<CheckBoxPreference>(getPreferenceKey(R.string.pref_key_delete_cookies_on_quit)) | ||
|
||
openTabs?.isChecked = newValue | ||
history?.isChecked = newValue | ||
cache?.isChecked = newValue | ||
permissions?.isChecked = newValue | ||
cookies?.isChecked = newValue | ||
|
||
Settings.getInstance(context!!).preferences.edit().putBoolean(openTabs?.key, newValue) | ||
.apply() | ||
Settings.getInstance(context!!).preferences.edit().putBoolean(history?.key, newValue) | ||
.apply() | ||
Settings.getInstance(context!!).preferences.edit().putBoolean(cache?.key, newValue).apply() | ||
Settings.getInstance(context!!).preferences.edit().putBoolean(permissions?.key, newValue) | ||
.apply() | ||
Settings.getInstance(context!!).preferences.edit().putBoolean(cookies?.key, newValue) | ||
.apply() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.utils | ||
|
||
import android.content.Context | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.runBlocking | ||
import org.mozilla.fenix.ext.asActivity | ||
import org.mozilla.fenix.settings.DefaultDeleteBrowsingDataController | ||
|
||
/** | ||
* Deletes selected browsing data and finishes the activity | ||
*/ | ||
fun Context.deleteAndQuit(coroutineScope: CoroutineScope) { | ||
coroutineScope.launch { | ||
runBlocking { | ||
val controller = | ||
DefaultDeleteBrowsingDataController(this@deleteAndQuit, coroutineContext) | ||
if (Settings.getInstance(this@deleteAndQuit).deleteCacheOnQuit) { | ||
controller.deleteCachedFiles() | ||
} | ||
if (Settings.getInstance(this@deleteAndQuit).deleteTabsOnQuit) { | ||
controller.deleteTabs() | ||
} | ||
if (Settings.getInstance(this@deleteAndQuit).deletePermissionsOnQuit) { | ||
launch(Dispatchers.IO) { | ||
controller.deleteSitePermissions() | ||
} | ||
} | ||
if (Settings.getInstance(this@deleteAndQuit).deleteCookiesOnQuit) { | ||
controller.deleteCookies() | ||
} | ||
if (Settings.getInstance(this@deleteAndQuit).deleteHistoryOnQuit) { | ||
controller.deleteHistoryAndDOMStorages() | ||
} | ||
} | ||
this@deleteAndQuit.asActivity()?.finish() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a link to this PR for this data review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just did!