Add toggle to disable "Press back again to exit"

Add toggle to settings activity for the "Press back again to exit" functionality. Defaults to true (current behavior).
This commit is contained in:
Trevor Terris 2021-05-07 15:34:13 -04:00
parent a92c90861c
commit 2e05c24b4d
6 changed files with 49 additions and 1 deletions

View File

@ -330,7 +330,7 @@ class MainActivity : SimpleActivity() {
override fun onBackPressed() {
if (fragment.mView.breadcrumbs.childCount <= 1) {
if (!wasBackJustPressed) {
if (!wasBackJustPressed && config.pressBackTwice) {
wasBackJustPressed = true
toast(R.string.press_back_again)
Handler().postDelayed({

View File

@ -31,6 +31,7 @@ class SettingsActivity : SimpleActivity() {
setupChangeDateTimeFormat()
setupFontSize()
setupShowHidden()
setupPressBackTwice()
setupHiddenItemPasswordProtection()
setupAppPasswordProtection()
setupFileDeletionPasswordProtection()
@ -115,6 +116,24 @@ class SettingsActivity : SimpleActivity() {
config.showHidden = settings_show_hidden.isChecked
}
private fun setupPressBackTwice() {
settings_press_back_twice.isChecked = config.pressBackTwice
settings_press_back_twice_holder.setOnClickListener {
if (config.pressBackTwice) {
togglePressBackTwice()
} else {
handleHiddenFolderPasswordProtection {
togglePressBackTwice()
}
}
}
}
private fun togglePressBackTwice() {
settings_press_back_twice.toggle()
config.pressBackTwice = settings_press_back_twice.isChecked
}
private fun setupHiddenItemPasswordProtection() {
settings_password_protection.isChecked = config.isHiddenPasswordProtectionOn
settings_password_protection_holder.setOnClickListener {

View File

@ -22,6 +22,10 @@ class Config(context: Context) : BaseConfig(context) {
var shouldShowHidden = showHidden || temporarilyShowHidden
var pressBackTwice: Boolean
get() = prefs.getBoolean(PRESS_BACK_TWICE, true)
set(pressBackTwice) = prefs.edit().putBoolean(PRESS_BACK_TWICE, pressBackTwice).apply()
var homeFolder: String
get(): String {
var path = prefs.getString(HOME_FOLDER, "")!!

View File

@ -5,6 +5,7 @@ const val MAX_COLUMN_COUNT = 20
// shared preferences
const val SHOW_HIDDEN = "show_hidden"
const val PRESS_BACK_TWICE = "press_back_twice"
const val HOME_FOLDER = "home_folder"
const val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
const val IS_ROOT_AVAILABLE = "is_root_available"

View File

@ -129,6 +129,29 @@
</RelativeLayout>
<RelativeLayout
android:id="@+id/settings_press_back_twice_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/medium_margin"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/normal_margin"
android:paddingTop="@dimen/activity_margin"
android:paddingEnd="@dimen/normal_margin"
android:paddingBottom="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MySwitchCompat
android:id="@+id/settings_press_back_twice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:clickable="false"
android:paddingStart="@dimen/medium_margin"
android:text="@string/press_back_twice"
app:switchPadding="@dimen/medium_margin" />
</RelativeLayout>
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/visibility_label"
android:layout_width="wrap_content"

View File

@ -43,6 +43,7 @@
<!-- Settings -->
<string name="enable_root_access">Enable root access</string>
<string name="press_back_twice" translatable="false">Press back twice to exit</string>
<!-- Strings displayed only on Google Play Store. Optional, but good to have -->
<!-- App title has to have less than 50 characters. If you cannot squeeze it, just remove a part of it -->