Rework exit logic

- If drawer is open, always close it first (existing)
- If drawer is closed, quick exit is enabled, close the app (only on apps, games or updates fragment)
- If drawer is closed, quick exit is disabled, ask to press back twice (existing)

Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
Aayush Gupta
2023-04-20 11:47:27 +05:30
parent a78287c006
commit 797f0eb2b0

View File

@@ -213,12 +213,11 @@ class MainActivity : BaseActivity() {
return navController.navigateUp()
}
@Deprecated("Deprecated in Java")
override fun onBackPressed() {
if (B.drawerLayout.isDrawerOpen(GravityCompat.START)) {
B.drawerLayout.close()
} else if (!navController.navigateUp()) {
if (!B.drawerLayout.isDrawerOpen(GravityCompat.START)) {
if (Preferences.getBoolean(this, Preferences.PREFERENCE_QUICK_EXIT)) {
super.onBackPressed()
this.finish()
} else {
if (lastBackPressed + 1000 > System.currentTimeMillis()) {
super.onBackPressed()
@@ -227,6 +226,8 @@ class MainActivity : BaseActivity() {
Toast.makeText(this, getString(R.string.toast_double_press_to_exit), Toast.LENGTH_SHORT).show()
}
}
} else {
B.drawerLayout.close()
}
}