Verified Commit 52486b79 authored by cyberta's avatar cyberta

#8896 get rid of intent member variable as state holder... && extract...

#8896 get rid of intent member variable as state holder... && extract ProviderApi broadcast receiver for reuse
parent c5f69023
......@@ -27,6 +27,7 @@ import java.net.URL;
import se.leap.bitmaskclient.ProviderListContent.ProviderItem;
import static se.leap.bitmaskclient.ProviderAPI.SET_UP_PROVIDER;
import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER;
/**
* Activity that builds and shows the list of known available providers.
......@@ -56,7 +57,7 @@ public class ProviderListActivity extends ProviderListBaseActivity {
* @param danger_on tells if HTTPS client should bypass certificate errors
*/
public void setUpProvider(boolean danger_on) {
configState.setAction(SETTING_UP_PROVIDER);
providerConfigState = SETTING_UP_PROVIDER;
Bundle parameters = new Bundle();
parameters.putBoolean(ProviderItem.DANGER_ON, danger_on);
......@@ -69,7 +70,7 @@ public class ProviderListActivity extends ProviderListBaseActivity {
*/
@Override
public void retrySetUpProvider(@NonNull Provider provider) {
configState.setAction(SETTING_UP_PROVIDER);
providerConfigState = SETTING_UP_PROVIDER;
ProviderAPICommand.execute(this, SET_UP_PROVIDER, provider);
}
......
package se.leap.bitmaskclient;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState;
/**
* Broadcast receiver that handles callback intents of ProviderApi during provider setup.
* It is used by CustomProviderSetupActivity for custom branded apps and ProviderListActivity
* for 'normal' Bitmask.
*
* Created by cyberta on 17.08.18.
*/
public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver {
private final ProviderSetupInterface setupInterface;
public ProviderApiSetupBroadcastReceiver(ProviderSetupInterface setupInterface) {
this.setupInterface = setupInterface;
}
@Override
public void onReceive(Context context, Intent intent) {
Log.d(ProviderListBaseActivity.TAG, "received Broadcast");
String action = intent.getAction();
if (action == null || !action.equalsIgnoreCase(Constants.BROADCAST_PROVIDER_API_EVENT)) {
return;
}
if (setupInterface.getConfigState() != null &&
setupInterface.getConfigState() == ProviderConfigState.SETTING_UP_PROVIDER) {
int resultCode = intent.getIntExtra(Constants.BROADCAST_RESULT_CODE, ProviderListBaseActivity.RESULT_CANCELED);
Log.d(ProviderListBaseActivity.TAG, "Broadcast resultCode: " + Integer.toString(resultCode));
Bundle resultData = intent.getParcelableExtra(Constants.BROADCAST_RESULT_KEY);
Provider handledProvider = resultData.getParcelable(Constants.PROVIDER_KEY);
if (handledProvider != null && setupInterface.getProvider() != null &&
handledProvider.getDomain().equalsIgnoreCase(setupInterface.getProvider().getDomain())) {
switch (resultCode) {
case ProviderAPI.PROVIDER_OK:
setupInterface.handleProviderSetUp(handledProvider);
break;
case ProviderAPI.PROVIDER_NOK:
setupInterface.handleProviderSetupFailed(resultData);
break;
case ProviderAPI.CORRECTLY_DOWNLOADED_VPN_CERTIFICATE:
setupInterface.handleCorrectlyDownloadedCertificate(handledProvider);
break;
case ProviderAPI.INCORRECTLY_DOWNLOADED_VPN_CERTIFICATE:
setupInterface.handleIncorrectlyDownloadedCertificate();
break;
}
}
}
}
}
\ No newline at end of file
package se.leap.bitmaskclient;
import android.os.Bundle;
/**
* Created by cyberta on 17.08.18.
*/
public interface ProviderSetupInterface {
enum ProviderConfigState {
PROVIDER_NOT_SET,
SETTING_UP_PROVIDER,
SHOWING_PROVIDER_DETAILS,
PENDING_SHOW_FAILED_DIALOG,
SHOW_FAILED_DIALOG,
}
void handleProviderSetUp(Provider provider);
void handleProviderSetupFailed(Bundle resultData);
void handleCorrectlyDownloadedCertificate(Provider provider);
void handleIncorrectlyDownloadedCertificate();
Provider getProvider();
ProviderConfigState getConfigState();
}
......@@ -18,10 +18,8 @@ package se.leap.bitmaskclient;
import android.support.annotation.NonNull;
import java.net.MalformedURLException;
import java.net.URL;
import static se.leap.bitmaskclient.ProviderAPI.SET_UP_PROVIDER;
import static se.leap.bitmaskclient.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER;
/**
* Activity that builds and shows the list of known available providers.
......@@ -44,13 +42,13 @@ public class ProviderListActivity extends ProviderListBaseActivity {
*
*/
public void setUpProvider() {
configState.setAction(SETTING_UP_PROVIDER);
providerConfigState = SETTING_UP_PROVIDER;
ProviderAPICommand.execute(this, SET_UP_PROVIDER, provider);
}
@Override
public void retrySetUpProvider(@NonNull Provider provider) {
configState.setAction(SETTING_UP_PROVIDER);
providerConfigState = SETTING_UP_PROVIDER;
ProviderAPICommand.execute(this, SET_UP_PROVIDER, provider);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment