Improve back navigation

This commit is contained in:
topjohnwu 2018-04-07 01:40:20 +08:00
parent 383c97c303
commit 41499d4b3c

View File

@ -30,6 +30,7 @@ public class MainActivity extends Activity
private final Handler mDrawerHandler = new Handler(); private final Handler mDrawerHandler = new Handler();
private int mDrawerItem; private int mDrawerItem;
private boolean fromShortcut = true;
@BindView(R.id.toolbar) Toolbar toolbar; @BindView(R.id.toolbar) Toolbar toolbar;
@BindView(R.id.drawer_layout) DrawerLayout drawer; @BindView(R.id.drawer_layout) DrawerLayout drawer;
@ -108,7 +109,7 @@ public class MainActivity extends Activity
public void onBackPressed() { public void onBackPressed() {
if (drawer.isDrawerOpen(navigationView)) { if (drawer.isDrawerOpen(navigationView)) {
drawer.closeDrawer(navigationView); drawer.closeDrawer(navigationView);
} else if (mDrawerItem != R.id.magisk) { } else if (mDrawerItem != R.id.magisk && !fromShortcut) {
navigate(R.id.magisk); navigate(R.id.magisk);
} else { } else {
finish(); finish();
@ -152,9 +153,6 @@ public class MainActivity extends Activity
int itemId = R.id.magisk; int itemId = R.id.magisk;
if (item != null) { if (item != null) {
switch (item) { switch (item) {
case "magisk":
itemId = R.id.magisk;
break;
case "superuser": case "superuser":
itemId = R.id.superuser; itemId = R.id.superuser;
break; break;
@ -187,6 +185,7 @@ public class MainActivity extends Activity
navigationView.setCheckedItem(itemId); navigationView.setCheckedItem(itemId);
switch (itemId) { switch (itemId) {
case R.id.magisk: case R.id.magisk:
fromShortcut = false;
displayFragment(new MagiskFragment(), true); displayFragment(new MagiskFragment(), true);
break; break;
case R.id.superuser: case R.id.superuser: