From 580d46b51a2f349fee4e15b2c2eb8bc7269f1631 Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 17 Mar 2018 22:33:07 +0100 Subject: #8878 fix back button behavior for about and log screen --- .../java/se/leap/bitmaskclient/MainActivity.java | 22 ++++++++++++++++++++-- .../drawer/NavigationDrawerFragment.java | 4 +++- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java index 4d57b6bc..d9917799 100644 --- a/app/src/main/java/se/leap/bitmaskclient/MainActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/MainActivity.java @@ -140,6 +140,22 @@ public class MainActivity extends AppCompatActivity implements Observer { bindOpenVpnService(); } + @Override + public void onBackPressed() { + FragmentManagerEnhanced fragmentManagerEnhanced = new FragmentManagerEnhanced(getSupportFragmentManager()); + if (fragmentManagerEnhanced.findFragmentByTag(EipFragment.TAG) == null) { + Fragment fragment = new EipFragment(); + Bundle bundle = new Bundle(); + bundle.putParcelable(PROVIDER_KEY, provider); + fragment.setArguments(bundle); + fragmentManagerEnhanced.beginTransaction() + .replace(R.id.container, fragment, EipFragment.TAG) + .commit(); + } else { + super.onBackPressed(); + } + } + @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); @@ -152,10 +168,12 @@ public class MainActivity extends AppCompatActivity implements Observer { return; } + String fragmentTag = null; Fragment fragment = null; switch (intent.getAction()) { case ACTION_SHOW_VPN_FRAGMENT: fragment = new EipFragment(); + fragmentTag = EipFragment.TAG; Bundle bundle = new Bundle(); if (intent.hasExtra(ASK_TO_CANCEL_VPN)) { bundle.putBoolean(ASK_TO_CANCEL_VPN, true); @@ -175,7 +193,7 @@ public class MainActivity extends AppCompatActivity implements Observer { if (fragment != null) { new FragmentManagerEnhanced(getSupportFragmentManager()).beginTransaction() - .replace(R.id.container, fragment) + .replace(R.id.container, fragment, fragmentTag) .commit(); } } @@ -214,7 +232,7 @@ public class MainActivity extends AppCompatActivity implements Observer { arguments.putParcelable(PROVIDER_KEY, provider); fragment.setArguments(arguments); new FragmentManagerEnhanced(getSupportFragmentManager()).beginTransaction() - .replace(R.id.container, fragment) + .replace(R.id.container, fragment, EipFragment.TAG) .commit(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java index 9256c136..e7a5e460 100644 --- a/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/drawer/NavigationDrawerFragment.java @@ -418,10 +418,12 @@ public class NavigationDrawerFragment extends Fragment { // update the main content by replacing fragments FragmentManager fragmentManager = getFragmentManager(); Fragment fragment = null; + String fragmentTag = null; if (parent == mDrawerAccountsListView) { mTitle = getString(R.string.vpn_fragment_title); fragment = new EipFragment(); + fragmentTag = EipFragment.TAG; Bundle arguments = new Bundle(); Provider currentProvider = ConfigHelper.getSavedProviderFromSharedPreferences(preferences); arguments.putParcelable(PROVIDER_KEY, currentProvider); @@ -457,7 +459,7 @@ public class NavigationDrawerFragment extends Fragment { if (fragment != null) { fragmentManager.beginTransaction() - .replace(R.id.container, fragment) + .replace(R.id.container, fragment, fragmentTag) .commit(); } -- cgit v1.2.3