diff options
author | cyBerta <cyberta@riseup.net> | 2024-04-26 18:52:43 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2024-04-26 18:52:43 +0200 |
commit | ac5b6bd42ab100661830f8f64ba2291606866c6c (patch) | |
tree | fd7797e3c3f9e1c78bc8d3d1ddaa21c1212087e1 /app/src/main/java/se/leap/bitmaskclient | |
parent | 19da621bebb11c1ca6723959e668ad0258929097 (diff) |
allow during the initial setup to re-launch the app and resume in the configuration UI
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient')
5 files changed, 28 insertions, 15 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java index 15180c30..5363f16e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java @@ -51,6 +51,7 @@ import se.leap.bitmaskclient.base.models.ProviderObservable; import se.leap.bitmaskclient.base.utils.DateHelper; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.eip.EipCommand; +import se.leap.bitmaskclient.providersetup.ProviderSetupObservable; import se.leap.bitmaskclient.providersetup.activities.SetupActivity; /** @@ -268,6 +269,7 @@ public class StartActivity extends Activity{ } private void showNextActivity(Provider provider) { + ProviderSetupObservable.cancel(); if (provider.shouldShowMotdSeen()) { try { IMessages messages = Motd.newMessages(provider.getMotdJsonString()); diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java index e96ded90..adb0fdc7 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EipSetupObserver.java @@ -244,7 +244,7 @@ public class EipSetupObserver extends BroadcastReceiver implements VpnStatus.Sta Log.d(TAG, "PROVIDER OK - FETCH SUCCESSFUL"); //no break, continue with next case case CORRECTLY_DOWNLOADED_VPN_CERTIFICATE: - if (ProviderSetupObservable.getProgress() > 0 && !activityForeground.get()) { + if (ProviderSetupObservable.isSetupRunning() && !activityForeground.get()) { ProviderSetupObservable.storeLastResult(resultCode, resultData); } break; diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupObservable.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupObservable.java index 1446d5ec..237f5bd2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupObservable.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupObservable.java @@ -117,6 +117,10 @@ public class ProviderSetupObservable { return getInstance().progress; } + public static boolean isSetupRunning() { + return getInstance().progress > 0; + } + public static void reset() { getInstance().progress = 0; getInstance().resultCode = 0; @@ -136,6 +140,7 @@ public class ProviderSetupObservable { public static void startSetup() { getInstance().canceled = false; getInstance().resultCode = 0; + getInstance().progress = 1; getInstance().resultData = new Bundle(); } diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SetupActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SetupActivity.java index 9235daad..9a0bf7b7 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SetupActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SetupActivity.java @@ -3,6 +3,7 @@ package se.leap.bitmaskclient.providersetup.activities; import static android.view.View.GONE; import static android.view.View.VISIBLE; import static androidx.appcompat.app.ActionBar.DISPLAY_SHOW_CUSTOM; +import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.base.utils.BuildConfigHelper.isDefaultBitmask; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.deleteProviderDetailsFromPreferences; import static se.leap.bitmaskclient.providersetup.fragments.SetupFragmentFactory.CONFIGURE_PROVIDER_FRAGMENT; @@ -139,7 +140,7 @@ public class SetupActivity extends AppCompatActivity implements SetupActivityCal }); binding.viewPager.setAdapter(adapter); binding.viewPager.setUserInputEnabled(false); - binding.viewPager.setCurrentItem(currentPosition, false); + binding.setupNextButton.setOnClickListener(v -> { int currentPos = binding.viewPager.getCurrentItem(); @@ -153,6 +154,14 @@ public class SetupActivity extends AppCompatActivity implements SetupActivityCal cancel(); }); setupActionBar(); + + if (ProviderSetupObservable.isSetupRunning()) { + provider = ProviderSetupObservable.getResultData().getParcelable(PROVIDER_KEY); + if (provider != null) { + currentPosition = adapter.getFragmentPostion(CONFIGURE_PROVIDER_FRAGMENT); + } + } + binding.viewPager.setCurrentItem(currentPosition, false); } @Override diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java index 078b2e41..621cb41a 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/fragments/ConfigureProviderFragment.java @@ -111,14 +111,6 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop } @Override - public void onResume() { - super.onResume(); - if (ProviderSetupObservable.getProgress() > 0) { - handleResult(ProviderSetupObservable.getResultCode(), ProviderSetupObservable.getResultData()); - } - } - - @Override public void onDestroyView() { setupActivityCallback.removeCancelCallback(this); ProviderSetupObservable.getInstance().deleteObserver(this); @@ -140,8 +132,12 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop binding.progressSpinner.update(ProviderSetupObservable.getProgress()); setupActivityCallback.setNavigationButtonHidden(true); setupActivityCallback.setCancelButtonHidden(false); - ProviderSetupObservable.startSetup(); - ProviderAPICommand.execute(getContext(), SET_UP_PROVIDER, setupActivityCallback.getSelectedProvider()); + if (ProviderSetupObservable.isSetupRunning()) { + handleResult(ProviderSetupObservable.getResultCode(), ProviderSetupObservable.getResultData(), true); + } else { + ProviderSetupObservable.startSetup(); + ProviderAPICommand.execute(getContext(), SET_UP_PROVIDER, setupActivityCallback.getSelectedProvider()); + } } protected void showConnectionDetails() { @@ -211,10 +207,10 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop if (resultData == null) { resultData = Bundle.EMPTY; } - handleResult(resultCode, resultData); + handleResult(resultCode, resultData, false); } - private void handleResult(int resultCode, Bundle resultData) { + private void handleResult(int resultCode, Bundle resultData, boolean resumeSetup) { Provider provider = resultData.getParcelable(PROVIDER_KEY); if (ignoreProviderAPIUpdates || provider == null || @@ -225,6 +221,7 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop switch (resultCode) { case PROVIDER_OK: + setupActivityCallback.onProviderSelected(provider); if (provider.allowsAnonymous()) { ProviderAPICommand.execute(this.getContext(), DOWNLOAD_VPN_CERTIFICATE, provider); } else { @@ -241,7 +238,7 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop // callback disappeared in the meanwhile } } - }, 750); + }, resumeSetup ? 0 : 750); break; case PROVIDER_NOK: case INCORRECTLY_DOWNLOADED_VPN_CERTIFICATE: |