diff options
author | cyBerta <cyberta@riseup.net> | 2024-04-24 10:22:13 +0200 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2024-04-24 10:22:13 +0200 |
commit | 19da621bebb11c1ca6723959e668ad0258929097 (patch) | |
tree | 6f9ee28f9d060d4d5ee42944f8771185d310f13b /app/src/main/java/se/leap/bitmaskclient/providersetup | |
parent | 2b91434f585e52fbfc229a50a36a04ef6cb8ce76 (diff) |
temporary workaround that stores provider setup updates if app is in background during setup. Fixes an app crash during provider setup while app is in background
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/providersetup')
2 files changed, 38 insertions, 2 deletions
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 c882b0bb..1446d5ec 100644 --- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupObservable.java +++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderSetupObservable.java @@ -16,6 +16,8 @@ package se.leap.bitmaskclient.providersetup; * along with this program. If not, see <http://www.gnu.org/licenses/>. */ +import android.os.Bundle; + import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -45,13 +47,15 @@ public class ProviderSetupObservable { public static final String PROPERTY_CHANGE = "ProviderSetupObservable"; private final HandlerInterface handler; private long lastUpdate = 0; + private int resultCode = 0; + private Bundle resultData; private ProviderSetupObservable() { handler = HandlerProvider.get(); changeSupport = new PropertyChangeSupport(this); - + resultData = new Bundle(); } public void addObserver(PropertyChangeListener propertyChangeListener) { @@ -70,6 +74,14 @@ public class ProviderSetupObservable { return instance; } + public static void storeLastResult(int resultCode, Bundle resultData) { + if (getInstance().canceled) { + return; + } + getInstance().resultCode = resultCode; + getInstance().resultData = resultData; + } + public static void updateProgress(int progress) { if (getInstance().canceled) { return; @@ -107,6 +119,8 @@ public class ProviderSetupObservable { public static void reset() { getInstance().progress = 0; + getInstance().resultCode = 0; + getInstance().resultData = new Bundle(); getInstance().changeSupport.firePropertyChange(PROPERTY_CHANGE, null, getInstance()); } @@ -121,5 +135,15 @@ public class ProviderSetupObservable { public static void startSetup() { getInstance().canceled = false; + getInstance().resultCode = 0; + getInstance().resultData = new Bundle(); + } + + public static int getResultCode() { + return getInstance().resultCode; + } + + public static Bundle getResultData() { + return getInstance().resultData; } } 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 f20bc9b6..078b2e41 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,6 +111,14 @@ 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); @@ -203,11 +211,15 @@ public class ConfigureProviderFragment extends BaseSetupFragment implements Prop if (resultData == null) { resultData = Bundle.EMPTY; } + handleResult(resultCode, resultData); + } + + private void handleResult(int resultCode, Bundle resultData) { Provider provider = resultData.getParcelable(PROVIDER_KEY); if (ignoreProviderAPIUpdates || provider == null || (setupActivityCallback.getSelectedProvider() != null && - !setupActivityCallback.getSelectedProvider().getMainUrlString().equals(provider.getMainUrlString()))) { + !setupActivityCallback.getSelectedProvider().getMainUrlString().equals(provider.getMainUrlString()))) { return; } |