diff options
author | Petar Kukolj <petarkukolj3@yahoo.com> | 2018-11-14 16:18:58 +0100 |
---|---|---|
committer | Petar Kukolj <petarkukolj3@yahoo.com> | 2018-11-14 16:40:59 +0100 |
commit | b3fbb0ec7574cf1090bfb410589753ba8ef51bbb (patch) | |
tree | 740faa9df0b769deca7e4d7f3c78c43657413a62 /app/src/main/java | |
parent | 68b245701e2ff11f23d2bdf1145e8189dc3709ac (diff) | |
download | AntennaPod-b3fbb0ec7574cf1090bfb410589753ba8ef51bbb.zip |
Add configurable behavior of the back button
This PR allows users to change how the back button functions. Closes #2196
Possible choices are following:
- **Default** - back button functions how it currently functions (closes the app if there is nowhere to go back to)
- **Open navigation drawer** - back button always opens the navigation drawer instead of closing the app
- **Double tap to exit** - like default, but requires two taps to close the app
- **Confirm to exit** - like default, but prompts user if they really want to exit
Diffstat (limited to 'app/src/main/java')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index f506921d2..fffd751c9 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -27,6 +27,7 @@ import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; +import android.widget.Toast; import com.bumptech.glide.Glide; @@ -123,6 +124,8 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi private Subscription subscription; + private long lastBackButtonPressTime = 0; + @Override public void onCreate(Bundle savedInstanceState) { setTheme(UserPreferences.getNoTitleTheme()); @@ -646,7 +649,33 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi if(isDrawerOpen()) { drawerLayout.closeDrawer(navDrawer); } else { - super.onBackPressed(); + switch (UserPreferences.getBackButtonBehavior()) { + case OPEN_DRAWER: + drawerLayout.openDrawer(navDrawer); + break; + case SHOW_PROMPT: + new AlertDialog.Builder(this) + .setMessage(R.string.close_prompt) + .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + MainActivity.super.onBackPressed(); + } + }) + .setNegativeButton(R.string.no, null) + .setCancelable(false) + .show(); + break; + case DOUBLE_TAP: + if(lastBackButtonPressTime < System.currentTimeMillis() - 2000) { + Toast.makeText(this, R.string.double_tap_toast, Toast.LENGTH_SHORT).show(); + lastBackButtonPressTime = System.currentTimeMillis(); + } else { + super.onBackPressed(); + } + break; + default: super.onBackPressed(); + } } } |