diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/MainActivity.kt b/app/src/main/java/com/amaze/fileutilities/home_page/MainActivity.kt index ae561b4e..0b3fb3e8 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/MainActivity.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/MainActivity.kt @@ -429,7 +429,11 @@ class MainActivity : } private fun exit() { - if (getFilesModel().backPressedToExitOnce) { + val confirmBeforeExitPref = getAppCommonSharedPreferences().getBoolean( + PreferencesConstants.KEY_CONFIRM_BEFORE_EXIT, + PreferencesConstants.DEFAULT_CONFIRM_BEFORE_EXIT + ) + if (!confirmBeforeExitPref || getFilesModel().backPressedToExitOnce) { finish() } else { getFilesModel().backPressedToExitOnce = true diff --git a/app/src/main/java/com/amaze/fileutilities/home_page/ui/settings/AppearancePrefFragment.kt b/app/src/main/java/com/amaze/fileutilities/home_page/ui/settings/AppearancePrefFragment.kt index 50f1b233..9c7747cb 100644 --- a/app/src/main/java/com/amaze/fileutilities/home_page/ui/settings/AppearancePrefFragment.kt +++ b/app/src/main/java/com/amaze/fileutilities/home_page/ui/settings/AppearancePrefFragment.kt @@ -24,6 +24,7 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.preference.CheckBoxPreference import androidx.preference.Preference import androidx.preference.PreferenceFragmentCompat import com.amaze.fileutilities.R @@ -35,6 +36,7 @@ class AppearancePrefFragment : PreferenceFragmentCompat(), Preference.OnPreferen companion object { private const val KEY_COLUMNS = "columns" + private const val KEY_CONFIRM_ON_EXIT = "pref_confirm_before_exit" private val KEYS = listOf( KEY_COLUMNS ) @@ -43,6 +45,21 @@ class AppearancePrefFragment : PreferenceFragmentCompat(), Preference.OnPreferen override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { // Load the preferences from an XML resource addPreferencesFromResource(R.xml.appearance_prefs) + val sharedPrefs = requireContext().getAppCommonSharedPreferences() + val enableConfirmOnExitChange = Preference.OnPreferenceChangeListener { pref, newValue -> + sharedPrefs.edit().putBoolean( + PreferencesConstants.KEY_CONFIRM_BEFORE_EXIT, newValue as Boolean + ).apply() + true + } + val confirmOnExitCheckbox = findPreference(KEY_CONFIRM_ON_EXIT) + confirmOnExitCheckbox?.setDefaultValue( + sharedPrefs.getBoolean( + PreferencesConstants.KEY_CONFIRM_BEFORE_EXIT, + PreferencesConstants.DEFAULT_CONFIRM_BEFORE_EXIT + ) + ) + confirmOnExitCheckbox?.onPreferenceChangeListener = enableConfirmOnExitChange KEYS.forEach { findPreference(it)?.onPreferenceClickListener = this } diff --git a/app/src/main/java/com/amaze/fileutilities/utilis/PreferencesConstants.kt b/app/src/main/java/com/amaze/fileutilities/utilis/PreferencesConstants.kt index 52d2d493..fa1893df 100644 --- a/app/src/main/java/com/amaze/fileutilities/utilis/PreferencesConstants.kt +++ b/app/src/main/java/com/amaze/fileutilities/utilis/PreferencesConstants.kt @@ -57,6 +57,7 @@ class PreferencesConstants { const val KEY_TRASH_BIN_RETENTION_BYTES = "trash_bin_retention_bytes" const val KEY_TRASH_BIN_RETENTION_NUM_OF_FILES = "trash_bin_retention_num_of_files" const val KEY_TRASH_BIN_CLEANUP_INTERVAL_HOURS = "trash_bin_cleanup_interval_hours" + const val KEY_CONFIRM_BEFORE_EXIT = "pref_confirm_before_exit" const val VAL_SEARCH_DUPLICATES_MEDIA_STORE = 0 const val VAL_SEARCH_DUPLICATES_INTERNAL_SHALLOW = 1 @@ -95,6 +96,7 @@ class PreferencesConstants { const val DEFAULT_NEWLY_INSTALLED_APPS_DAYS = 7 const val DEFAULT_RECENTLY_UPDATED_APPS_DAYS = 7 const val DEFAULT_LARGE_SIZE_DIFF_APPS_DAYS = 7 + const val DEFAULT_CONFIRM_BEFORE_EXIT = true // max days that the size is stored in database and // therefore the max days that the size diff can be calculated diff --git a/app/src/main/play/release-notes/en-US/production.txt b/app/src/main/play/release-notes/en-US/production.txt index befb3876..c0129e7f 100644 --- a/app/src/main/play/release-notes/en-US/production.txt +++ b/app/src/main/play/release-notes/en-US/production.txt @@ -1,5 +1,4 @@ Changelog: -- Add support for Android 13 - Bugfixes in video and audio players - Analyse list of apps growing in size - Improved performance diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 31da1269..600e648b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1045,4 +1045,8 @@ Terms and Conditions Usage (hrs) + + Confirm before exit + + Control general app behaviour diff --git a/app/src/main/res/xml/appearance_prefs.xml b/app/src/main/res/xml/appearance_prefs.xml index 51cd6d12..23a13761 100644 --- a/app/src/main/res/xml/appearance_prefs.xml +++ b/app/src/main/res/xml/appearance_prefs.xml @@ -1,8 +1,13 @@ + + app:title="@string/appearance">