diff options
author | cyberta <cyberta@riseup.net> | 2020-07-25 07:58:05 -0700 |
---|---|---|
committer | cyberta <cyberta@riseup.net> | 2020-07-25 07:58:05 -0700 |
commit | 9d1a59edb383b8d953109c53ada849ed8649b731 (patch) | |
tree | a2ba701205a0ab4ad008fe92f080618561e39b1a /app/src | |
parent | 81abcb0ea1326464d6b34e18ba27c1ccc4587c45 (diff) | |
parent | 82c0590775493e983239be49e8dc27eb94b835e2 (diff) |
Merge branch 'improve_provider_setup_UI' into 'master'
Improve provider setup ui
Closes #8990
See merge request leap/bitmask_android!109
Diffstat (limited to 'app/src')
8 files changed, 21 insertions, 122 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/CustomProviderSetupActivity.java b/app/src/main/java/se/leap/bitmaskclient/CustomProviderSetupActivity.java index 8f17d482..29d1b09e 100644 --- a/app/src/main/java/se/leap/bitmaskclient/CustomProviderSetupActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/CustomProviderSetupActivity.java @@ -107,11 +107,6 @@ public class CustomProviderSetupActivity extends ProviderSetupBaseActivity { } @Override - public void onReceiveResult(int resultCode, Bundle resultData) { - - } - - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) { setResult(resultCode, data); diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java index 767e6a78..4058b824 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderAPI.java @@ -62,8 +62,7 @@ public class ProviderAPI extends JobIntentService implements ProviderApiManagerB BACKEND_ERROR_KEY = "error", BACKEND_ERROR_MESSAGE = "message", USER_MESSAGE = "userMessage", - DOWNLOAD_SERVICE_JSON = "ProviderAPI.DOWNLOAD_SERVICE_JSON", - PROVIDER_SET_UP = "ProviderAPI.PROVIDER_SET_UP"; + DOWNLOAD_SERVICE_JSON = "ProviderAPI.DOWNLOAD_SERVICE_JSON"; final public static int SUCCESSFUL_LOGIN = 3, diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java b/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java deleted file mode 100644 index 9b777e5a..00000000 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderAPIResultReceiver.java +++ /dev/null @@ -1,57 +0,0 @@ -/**
- * Copyright (c) 2013 LEAP Encryption Access Project and contributers
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-package se.leap.bitmaskclient;
-
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.ResultReceiver;
-
-/**
- * Implements the ResultReceiver needed by Activities using ProviderAPI to receive the results of its operations.
- *
- * @author parmegv
- */
-public class ProviderAPIResultReceiver extends ResultReceiver {
- private Receiver mReceiver;
-
- public ProviderAPIResultReceiver(Handler handler, Receiver receiver) {
- super(handler);
- setReceiver(receiver);
- // TODO Auto-generated constructor stub
- }
-
- public void setReceiver(Receiver receiver) {
- mReceiver = receiver;
- }
-
- /**
- * Interface to enable ProviderAPIResultReceiver to receive results from the ProviderAPI IntentService.
- *
- * @author parmegv
- */
- public interface Receiver {
- public void onReceiveResult(int resultCode, Bundle resultData);
- }
-
- @Override
- protected void onReceiveResult(int resultCode, Bundle resultData) {
- if (mReceiver != null) {
- mReceiver.onReceiveResult(resultCode, resultData);
- }
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java index e5ca184f..8825a818 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiManagerBase.java @@ -92,7 +92,6 @@ import static se.leap.bitmaskclient.ProviderAPI.LOG_OUT; import static se.leap.bitmaskclient.ProviderAPI.PARAMETERS; import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_NOK; import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_OK; -import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_SET_UP; import static se.leap.bitmaskclient.ProviderAPI.RECEIVER_KEY; import static se.leap.bitmaskclient.ProviderAPI.SET_UP_PROVIDER; import static se.leap.bitmaskclient.ProviderAPI.SIGN_UP; @@ -249,15 +248,6 @@ public abstract class ProviderApiManagerBase { } ProviderObservable.getInstance().getProviderForDns(); break; - case PROVIDER_SET_UP: - if(provider.hasEIP() && provider.hasCaCert() && provider.hasDefinition()) { - if(receiver!= null) { - result.putParcelable(PROVIDER_KEY, provider); - receiver.send(PROVIDER_OK, result); - } - } - break; - case DOWNLOAD_GEOIP_JSON: if (!provider.getGeoipUrl().isDefault()) { boolean startEIP = parameters.getBoolean(EIP_ACTION_START); diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java b/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java index 0a2e2538..890d3b67 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderApiSetupBroadcastReceiver.java @@ -22,6 +22,8 @@ import android.content.Intent; import android.os.Bundle; import android.util.Log; +import java.lang.ref.WeakReference; + import se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState; /** @@ -33,18 +35,18 @@ import se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState; */ public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver { - private final ProviderSetupInterface setupInterface; + private WeakReference<ProviderSetupInterface> setupInterfaceRef; public ProviderApiSetupBroadcastReceiver(ProviderSetupInterface setupInterface) { - this.setupInterface = setupInterface; + this.setupInterfaceRef = new WeakReference<>(setupInterface); } @Override public void onReceive(Context context, Intent intent) { Log.d(ProviderListBaseActivity.TAG, "received Broadcast"); - + ProviderSetupInterface setupInterface = setupInterfaceRef.get(); String action = intent.getAction(); - if (action == null || !action.equalsIgnoreCase(Constants.BROADCAST_PROVIDER_API_EVENT)) { + if (action == null || !action.equalsIgnoreCase(Constants.BROADCAST_PROVIDER_API_EVENT) || setupInterface == null) { return; } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java index a7d0f916..4f555f94 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderListBaseActivity.java @@ -134,18 +134,6 @@ public abstract class ProviderListBaseActivity extends ProviderSetupBaseActivity this.provider = handledProvider; showProviderDetails(); } - // ----------------------------------------- - - //TODO: only keep empty method for testing purposes - @Override - public void onReceiveResult(int resultCode, Bundle resultData) { - super.onReceiveResult(resultCode, resultData); - if (resultCode == AboutFragment.VIEWED) { - // Do nothing, right now - // I need this for CW to wait for the About activity to end before going back to Dashboard. - //FIXME: WEEEIRD! - } - } @OnItemClick(R.id.provider_list) void onItemSelected(int position) { diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderSetupBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/ProviderSetupBaseActivity.java index 396b8b26..3bcc6feb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderSetupBaseActivity.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderSetupBaseActivity.java @@ -19,12 +19,12 @@ package se.leap.bitmaskclient; import android.content.Intent; import android.content.IntentFilter; import android.os.Bundle; -import android.os.Handler; +import android.util.Log; + import androidx.annotation.Nullable; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.FragmentTransaction; import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import android.util.Log; import org.jetbrains.annotations.NotNull; import org.json.JSONException; @@ -35,9 +35,9 @@ import static se.leap.bitmaskclient.Constants.PROVIDER_KEY; import static se.leap.bitmaskclient.Constants.REQUEST_CODE_CONFIGURE_LEAP; import static se.leap.bitmaskclient.ProviderAPI.DOWNLOAD_VPN_CERTIFICATE; import static se.leap.bitmaskclient.ProviderAPI.ERRORS; -import static se.leap.bitmaskclient.ProviderAPI.PROVIDER_SET_UP; import static se.leap.bitmaskclient.ProviderAPI.UPDATE_PROVIDER_DETAILS; import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.PENDING_SHOW_FAILED_DIALOG; +import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.PENDING_SHOW_PROVIDER_DETAILS; import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.PROVIDER_NOT_SET; import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER; import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.SHOWING_PROVIDER_DETAILS; @@ -47,7 +47,7 @@ import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.S * Created by cyberta on 19.08.18. */ -public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity implements ProviderAPIResultReceiver.Receiver, ProviderSetupInterface, ProviderSetupFailedDialog.DownloadFailedDialogInterface { +public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity implements ProviderSetupInterface, ProviderSetupFailedDialog.DownloadFailedDialogInterface { final public static String TAG = "PoviderSetupActivity"; final private static String ACTIVITY_STATE = "ACTIVITY STATE"; final private static String REASON_TO_FAIL = "REASON TO FAIL"; @@ -60,23 +60,21 @@ public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity protected boolean testNewURL; private ProviderApiSetupBroadcastReceiver providerAPIBroadcastReceiver; - private ProviderAPIResultReceiver providerAPIResultReceiver; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); fragmentManager = new FragmentManagerEnhanced(getSupportFragmentManager()); providerManager = ProviderManager.getInstance(getAssets(), getExternalFilesDir(null)); + setUpProviderAPIResultReceiver(); } @Override protected void onResume() { super.onResume(); Log.d(TAG, "resuming with ConfigState: " + providerConfigState.toString()); - setUpProviderAPIResultReceiver(); if (SETTING_UP_PROVIDER == providerConfigState) { showProgressBar(); - checkProviderSetUp(); } else if (PENDING_SHOW_FAILED_DIALOG == providerConfigState) { showProgressBar(); showDownloadFailedDialog(); @@ -84,20 +82,18 @@ public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity showProgressBar(); } else if (SHOWING_PROVIDER_DETAILS == providerConfigState) { cancelSettingUpProvider(); + } else if (PENDING_SHOW_PROVIDER_DETAILS == providerConfigState) { + showProviderDetails(); } } @Override - protected void onPause() { - super.onPause(); - if (providerAPIBroadcastReceiver != null) - LocalBroadcastManager.getInstance(this).unregisterReceiver(providerAPIBroadcastReceiver); - } - - @Override protected void onDestroy() { super.onDestroy(); - providerAPIResultReceiver = null; + if (providerAPIBroadcastReceiver != null) { + LocalBroadcastManager.getInstance(this).unregisterReceiver(providerAPIBroadcastReceiver); + } + providerAPIBroadcastReceiver = null; } @@ -163,15 +159,6 @@ public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity ProviderAPICommand.execute(this, UPDATE_PROVIDER_DETAILS, provider); } - // -------- ProviderAPIResultReceiver.Receiver ---v - @Override - public void onReceiveResult(int resultCode, Bundle resultData) { - if (resultCode == ProviderAPI.PROVIDER_OK) { - Provider provider = resultData.getParcelable(PROVIDER_KEY); - handleProviderSetUp(provider); - } - } - protected void restoreState(Bundle savedInstanceState) { super.restoreState(savedInstanceState); if (savedInstanceState == null) { @@ -184,7 +171,6 @@ public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity } private void setUpProviderAPIResultReceiver() { - providerAPIResultReceiver = new ProviderAPIResultReceiver(new Handler(), this); providerAPIBroadcastReceiver = new ProviderApiSetupBroadcastReceiver(this); IntentFilter updateIntentFilter = new IntentFilter(BROADCAST_PROVIDER_API_EVENT); @@ -199,13 +185,6 @@ public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity ProviderAPICommand.execute(this, DOWNLOAD_VPN_CERTIFICATE, provider); } - /* - * - */ - public void checkProviderSetUp() { - ProviderAPICommand.execute(this, PROVIDER_SET_UP, provider, providerAPIResultReceiver); - } - /** * Once selected a provider, this fragment offers the user to log in, * use it anonymously (if possible) @@ -220,6 +199,8 @@ public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); intent.putExtra(PROVIDER_KEY, provider); startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP); + } else { + providerConfigState = PENDING_SHOW_PROVIDER_DETAILS; } } diff --git a/app/src/main/java/se/leap/bitmaskclient/ProviderSetupInterface.java b/app/src/main/java/se/leap/bitmaskclient/ProviderSetupInterface.java index 2b921ef0..9cf4dc33 100644 --- a/app/src/main/java/se/leap/bitmaskclient/ProviderSetupInterface.java +++ b/app/src/main/java/se/leap/bitmaskclient/ProviderSetupInterface.java @@ -27,6 +27,7 @@ public interface ProviderSetupInterface { PROVIDER_NOT_SET, SETTING_UP_PROVIDER, SHOWING_PROVIDER_DETAILS, + PENDING_SHOW_PROVIDER_DETAILS, PENDING_SHOW_FAILED_DIALOG, SHOW_FAILED_DIALOG, } |