Skip to content

Commit

Permalink
Add toggle to disable "Press back again to exit"
Browse files Browse the repository at this point in the history
Add toggle to settings activity for the "Press back again to exit" functionality. Defaults to true (current behavior).
  • Loading branch information
tkterris committed May 7, 2021
1 parent a92c908 commit 2e05c24
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class SettingsActivity : SimpleActivity() {
setupChangeDateTimeFormat()
setupFontSize()
setupShowHidden()
setupPressBackTwice()
setupHiddenItemPasswordProtection()
setupAppPasswordProtection()
setupFileDeletionPasswordProtection()
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down

0 comments on commit 2e05c24

Please sign in to comment.