summaryrefslogtreecommitdiff
path: root/app/src/main/java/se/leap
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/se/leap')
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java25
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java2
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java43
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java48
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java49
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java48
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java38
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java30
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/base/views/ProviderHeaderView.java109
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java10
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderListAdapter.java21
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java11
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRenderer.java61
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRendererBuilder.java21
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/TorLogAdapter.java1
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AbstractProviderDetailActivity.java108
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AddProviderBaseActivity.java126
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ButterKnifeActivity.java47
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java430
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java154
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/LoginActivity.java32
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderCredentialsBaseActivity.java479
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderListBaseActivity.java194
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderSetupBaseActivity.java256
-rw-r--r--app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SignupActivity.java55
25 files changed, 66 insertions, 2332 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java
index 7dd01ccb..5da238d4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/MainActivity.java
@@ -19,7 +19,6 @@ package se.leap.bitmaskclient.base;
import static androidx.appcompat.app.ActionBar.DISPLAY_SHOW_CUSTOM;
import static se.leap.bitmaskclient.R.string.downloading_vpn_certificate_failed;
-import static se.leap.bitmaskclient.R.string.vpn_certificate_user_message;
import static se.leap.bitmaskclient.base.models.Constants.ASK_TO_CANCEL_VPN;
import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_RESULT_CODE;
import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_RESULT_KEY;
@@ -42,11 +41,9 @@ import static se.leap.bitmaskclient.providersetup.ProviderAPI.INCORRECTLY_UPDATE
import static se.leap.bitmaskclient.providersetup.ProviderAPI.TOR_EXCEPTION;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.TOR_TIMEOUT;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.USER_MESSAGE;
import android.content.Context;
import android.content.Intent;
-import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
@@ -69,7 +66,6 @@ import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.fragments.EipFragment;
import se.leap.bitmaskclient.base.fragments.ExcludeAppsFragment;
-import se.leap.bitmaskclient.base.fragments.LogFragment;
import se.leap.bitmaskclient.base.fragments.MainActivityErrorDialog;
import se.leap.bitmaskclient.base.fragments.MotdFragment;
import se.leap.bitmaskclient.base.fragments.NavigationDrawerFragment;
@@ -83,8 +79,6 @@ import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipSetupListener;
import se.leap.bitmaskclient.eip.EipSetupObserver;
import se.leap.bitmaskclient.providersetup.ProviderAPI;
-import se.leap.bitmaskclient.providersetup.activities.LoginActivity;
-import se.leap.bitmaskclient.providersetup.models.LeapSRPSession;
public class MainActivity extends AppCompatActivity implements EipSetupListener, Observer {
@@ -310,10 +304,10 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
return;
}
- if (LeapSRPSession.loggedIn() || provider.allowsAnonymous()) {
+ if (provider.allowsAnonymous()) {
showMainActivityErrorDialog(error);
} else if (isInvalidCertificateForLoginOnlyProvider(error)) {
- askUserToLogIn(getString(vpn_certificate_user_message));
+ showMainActivityErrorDialog(getString(R.string.login_not_supported));
}
}
break;
@@ -341,11 +335,7 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
// TODO CATCH ME IF YOU CAN - WHAT DO WE WANT TO DO?
break;
case INCORRECTLY_UPDATED_INVALID_VPN_CERTIFICATE:
- if (LeapSRPSession.loggedIn() || provider.allowsAnonymous()) {
showMainActivityErrorDialog(getString(downloading_vpn_certificate_failed));
- } else {
- askUserToLogIn(getString(vpn_certificate_user_message));
- }
break;
case TOR_TIMEOUT:
case TOR_EXCEPTION:
@@ -429,20 +419,11 @@ public class MainActivity extends AppCompatActivity implements EipSetupListener,
try {
JSONObject errorJson = new JSONObject(errorJsonString);
return ERROR_INVALID_VPN_CERTIFICATE.toString().equals(errorJson.getString(ERRORID)) &&
- !LeapSRPSession.loggedIn() &&
+ provider.allowsRegistered() &&
!provider.allowsAnonymous();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
-
- private void askUserToLogIn(String userMessage) {
- Intent intent = new Intent(this, LoginActivity.class);
- intent.putExtra(PROVIDER_KEY, provider);
- if (userMessage != null) {
- intent.putExtra(USER_MESSAGE, userMessage);
- }
- startActivityForResult(intent, REQUEST_CODE_LOG_IN);
- }
}
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 19f03dee..21fc81e4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/StartActivity.java
@@ -24,7 +24,6 @@ import static se.leap.bitmaskclient.base.models.Constants.EXTRA_MOTD_MSG;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITION;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-import static se.leap.bitmaskclient.base.utils.ConfigHelper.isDefaultBitmask;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.storeProviderInPreferences;
import android.app.Activity;
@@ -52,7 +51,6 @@ 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.activities.CustomProviderSetupActivity;
import se.leap.bitmaskclient.providersetup.activities.SetupActivity;
/**
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java
index e92aa703..275dc1c4 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AboutFragment.java
@@ -1,5 +1,9 @@
package se.leap.bitmaskclient.base.fragments;
+import static android.view.View.VISIBLE;
+import static se.leap.bitmaskclient.R.string.about_fragment_title;
+import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle;
+
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
@@ -7,42 +11,24 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
-import androidx.appcompat.widget.AppCompatTextView;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import butterknife.Unbinder;
import se.leap.bitmaskclient.BuildConfig;
import se.leap.bitmaskclient.R;
-
-import static android.view.View.VISIBLE;
-import static se.leap.bitmaskclient.R.string.about_fragment_title;
-import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarSubtitle;
+import se.leap.bitmaskclient.databinding.FAboutBinding;
public class AboutFragment extends Fragment {
final public static String TAG = AboutFragment.class.getSimpleName();
final public static int VIEWED = 0;
- private Unbinder unbinder;
-
- @BindView(R.id.version)
- AppCompatTextView versionTextView;
-
- @BindView(R.id.terms_of_service)
- AppCompatTextView termsOfService;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View view = inflater.inflate(R.layout.f_about, container, false);
- unbinder = ButterKnife.bind(this, view);
+ FAboutBinding binding = FAboutBinding.inflate(inflater);
setActionBarSubtitle(this, about_fragment_title);
- return view;
- }
- @Override
- public void onStart() {
- super.onStart();
String version;
String name = "Bitmask";
try {
@@ -54,18 +40,13 @@ public class AboutFragment extends Fragment {
version = "error fetching version";
}
- versionTextView.setText(getString(R.string.version_info, name, version));
+ binding.version.setText(getString(R.string.version_info, name, version));
if (BuildConfig.FLAVOR_branding.equals("custom") && hasTermsOfServiceResource()) {
- termsOfService.setText(getString(getTermsOfServiceResource()));
- termsOfService.setVisibility(VISIBLE);
+ binding.termsOfService.setText(getString(getTermsOfServiceResource()));
+ binding.termsOfService.setVisibility(VISIBLE);
}
- }
-
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- unbinder.unbind();
+ return binding.getRoot();
}
private boolean hasTermsOfServiceResource() {
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java
index e68ba170..faa9950b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/AlwaysOnDialog.java
@@ -1,26 +1,20 @@
package se.leap.bitmaskclient.base.fragments;
+import static se.leap.bitmaskclient.base.utils.PreferenceHelper.saveShowAlwaysOnDialog;
+
import android.app.Dialog;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.CheckBox;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
-import androidx.appcompat.widget.AppCompatTextView;
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import butterknife.Unbinder;
import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.base.views.IconTextView;
-
-import static se.leap.bitmaskclient.base.utils.PreferenceHelper.saveShowAlwaysOnDialog;
+import se.leap.bitmaskclient.databinding.DCheckboxConfirmBinding;
/**
@@ -33,41 +27,24 @@ public class AlwaysOnDialog extends AppCompatDialogFragment {
public final static String TAG = AlwaysOnDialog.class.getName();
- @BindView(R.id.do_not_show_again)
- CheckBox doNotShowAgainCheckBox;
-
- @BindView(R.id.user_message)
- IconTextView userMessage;
-
- @BindView(R.id.block_vpn_user_message)
- AppCompatTextView blockVpnUserMessage;
-
- private Unbinder unbinder;
-
-
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+
LayoutInflater inflater = getActivity().getLayoutInflater();
- View view = inflater.inflate(R.layout.d_checkbox_confirm, null);
- unbinder = ButterKnife.bind(this, view);
+ DCheckboxConfirmBinding binding = DCheckboxConfirmBinding.inflate(inflater);
- userMessage.setIcon(R.drawable.ic_settings);
- userMessage.setText(getString(R.string.always_on_vpn_user_message));
+ binding.userMessage.setIcon(R.drawable.ic_settings);
+ binding.userMessage.setText(getString(R.string.always_on_vpn_user_message));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
- blockVpnUserMessage.setVisibility(View.VISIBLE);
+ binding.blockVpnUserMessage.setVisibility(View.VISIBLE);
}
- builder.setView(view)
+ builder.setView(binding.getRoot())
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
- if (doNotShowAgainCheckBox.isChecked()) {
+ if (binding.doNotShowAgain.isChecked()) {
saveShowAlwaysOnDialog(false);
}
Intent intent = new Intent("android.net.vpn.SETTINGS");
@@ -78,9 +55,4 @@ public class AlwaysOnDialog extends AppCompatDialogFragment {
return builder.create();
}
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- unbinder.unbind();
- }
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java
index 08346791..6a0a63c5 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/DonationReminderDialog.java
@@ -1,5 +1,10 @@
package se.leap.bitmaskclient.base.fragments;
+import static se.leap.bitmaskclient.base.models.Constants.DONATION_REMINDER_DURATION;
+import static se.leap.bitmaskclient.base.models.Constants.DONATION_URL;
+import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION;
+import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION_REMINDER;
+
import android.app.Dialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
@@ -8,59 +13,32 @@ import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.Button;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
import java.text.ParseException;
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import butterknife.Unbinder;
-import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.utils.DateHelper;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
-
-import static se.leap.bitmaskclient.base.models.Constants.DONATION_REMINDER_DURATION;
-import static se.leap.bitmaskclient.base.models.Constants.DONATION_URL;
-import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION;
-import static se.leap.bitmaskclient.base.models.Constants.ENABLE_DONATION_REMINDER;
-import static se.leap.bitmaskclient.base.models.Constants.FIRST_TIME_USER_DATE;
-import static se.leap.bitmaskclient.base.models.Constants.LAST_DONATION_REMINDER_DATE;
+import se.leap.bitmaskclient.databinding.DonationReminderDialogBinding;
public class DonationReminderDialog extends AppCompatDialogFragment {
public final static String TAG = DonationReminderDialog.class.getName();
private static boolean isShown = false;
- @BindView(R.id.btnDonate)
- Button btnDonate;
-
- @BindView(R.id.btnLater)
- Button btnLater;
-
- private Unbinder unbinder;
-
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- }
-
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
- View view = inflater.inflate(R.layout.donation_reminder_dialog, null);
- unbinder = ButterKnife.bind(this, view);
+ DonationReminderDialogBinding binding = DonationReminderDialogBinding.inflate(inflater);
isShown = true;
- builder.setView(view);
- btnDonate.setOnClickListener(v -> {
+ builder.setView(binding.getRoot());
+ binding.btnDonate.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(DONATION_URL));
try {
startActivity(browserIntent);
@@ -70,7 +48,7 @@ public class DonationReminderDialog extends AppCompatDialogFragment {
PreferenceHelper.lastDonationReminderDate(DateHelper.getCurrentDateString());
dismiss();
});
- btnLater.setOnClickListener(v -> {
+ binding.btnLater.setOnClickListener(v -> {
PreferenceHelper.lastDonationReminderDate(DateHelper.getCurrentDateString());
dismiss();
});
@@ -78,12 +56,6 @@ public class DonationReminderDialog extends AppCompatDialogFragment {
return builder.create();
}
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- unbinder.unbind();
- }
-
public static boolean isCallable(Context context) {
if (isShown) {
return false;
@@ -97,7 +69,6 @@ public class DonationReminderDialog extends AppCompatDialogFragment {
Log.e(TAG, "context is null!");
return false;
}
-
String firstTimeUserDate = PreferenceHelper.getFirstTimeUserDate();
if (firstTimeUserDate == null) {
PreferenceHelper.firstTimeUserDate(DateHelper.getCurrentDateString());
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java
index 670cdfd8..c500b55b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/EipFragment.java
@@ -16,21 +16,16 @@
*/
package se.leap.bitmaskclient.base.fragments;
-import static se.leap.bitmaskclient.R.string.vpn_certificate_user_message;
import static se.leap.bitmaskclient.base.models.Constants.ASK_TO_CANCEL_VPN;
import static se.leap.bitmaskclient.base.models.Constants.EIP_ACTION_START;
import static se.leap.bitmaskclient.base.models.Constants.EIP_EARLY_ROUTES;
import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_LOG_IN;
import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_SWITCH_PROVIDER;
-import static se.leap.bitmaskclient.base.utils.ConfigHelper.isDefaultBitmask;
import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity;
import static se.leap.bitmaskclient.eip.EipSetupObserver.reconnectingWithDifferentGateway;
import static se.leap.bitmaskclient.eip.GatewaysManager.Load.UNKNOWN;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.DOWNLOAD_GEOIP_JSON;
import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.USER_MESSAGE;
import android.app.Activity;
import android.content.Context;
@@ -46,6 +41,7 @@ import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Toast;
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
@@ -80,10 +76,7 @@ import se.leap.bitmaskclient.eip.EipCommand;
import se.leap.bitmaskclient.eip.EipStatus;
import se.leap.bitmaskclient.eip.GatewaysManager;
import se.leap.bitmaskclient.providersetup.ProviderAPICommand;
-import se.leap.bitmaskclient.providersetup.ProviderListActivity;
-import se.leap.bitmaskclient.providersetup.activities.CustomProviderSetupActivity;
-import se.leap.bitmaskclient.providersetup.activities.LoginActivity;
-import se.leap.bitmaskclient.providersetup.models.LeapSRPSession;
+import se.leap.bitmaskclient.providersetup.activities.SetupActivity;
import se.leap.bitmaskclient.tor.TorServiceCommand;
import se.leap.bitmaskclient.tor.TorStatusObservable;
@@ -136,14 +129,7 @@ public class EipFragment extends Fragment implements Observer {
}
private void handleNoProvider(Activity activity) {
- if (isDefaultBitmask()) {
- activity.startActivityForResult(new Intent(activity, ProviderListActivity.class), REQUEST_CODE_SWITCH_PROVIDER);
- } else {
- Log.e(TAG, "no provider given - try to reconfigure custom provider");
- startActivityForResult(new Intent(activity, CustomProviderSetupActivity.class), REQUEST_CODE_CONFIGURE_LEAP);
-
- }
-
+ activity.startActivityForResult(new Intent(activity, SetupActivity.class), REQUEST_CODE_SWITCH_PROVIDER);
}
@Override
@@ -283,11 +269,10 @@ public class EipFragment extends Fragment implements Observer {
if (canStartEIP()) {
startEipFromScratch();
- } else if (canLogInToStartEIP()) {
- askUserToLogIn(getString(vpn_certificate_user_message));
- } else {
- // provider has no VpnCertificate but user is logged in
+ } else if (provider.allowsAnonymous()){
updateInvalidVpnCertificate();
+ } else {
+ Toast.makeText(getContext(), R.string.config_error_found, Toast.LENGTH_LONG).show();
}
}
@@ -297,12 +282,6 @@ public class EipFragment extends Fragment implements Observer {
return (isAllowedAnon || certificateExists) && !eipStatus.isConnected() && !eipStatus.isConnecting();
}
- private boolean canLogInToStartEIP() {
- boolean isAllowedRegistered = provider.allowsRegistered();
- boolean isLoggedIn = LeapSRPSession.loggedIn();
- return isAllowedRegistered && !isLoggedIn && !eipStatus.isConnecting() && !eipStatus.isConnected();
- }
-
private void handleSwitchOff() {
if (eipStatus.isVPNRunningWithoutNetwork() || eipStatus.isConnecting() || eipStatus.isUpdatingVpnCert()) {
askPendingStartCancellation();
@@ -562,7 +541,6 @@ public class EipFragment extends Fragment implements Observer {
// eat me
}
-
stateView.setImageResource(drawableRes);
stateView.setTag(drawableRes);
if (stateView.getDrawable() instanceof Animatable) {
@@ -592,20 +570,6 @@ public class EipFragment extends Fragment implements Observer {
ProviderAPICommand.execute(getContext(), UPDATE_INVALID_VPN_CERTIFICATE, provider);
}
- private void askUserToLogIn(String userMessage) {
- Intent intent = new Intent(getContext(), LoginActivity.class);
- intent.putExtra(PROVIDER_KEY, provider);
-
- if(userMessage != null) {
- intent.putExtra(USER_MESSAGE, userMessage);
- }
-
- Activity activity = getActivity();
- if (activity != null) {
- activity.startActivityForResult(intent, REQUEST_CODE_LOG_IN);
- }
- }
-
public void showDonationReminderDialog() {
try {
FragmentTransaction fragmentTransaction = new FragmentManagerEnhanced(
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java
index eb9d149f..588daa3f 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/TetheringDialog.java
@@ -19,7 +19,6 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDialogFragment;
-import androidx.appcompat.widget.AppCompatTextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -28,13 +27,11 @@ import java.util.Observer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import butterknife.Unbinder;
import de.blinkt.openvpn.core.VpnStatus;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.utils.PreferenceHelper;
import se.leap.bitmaskclient.base.views.IconCheckboxEntry;
+import se.leap.bitmaskclient.databinding.DListSelectionBinding;
import se.leap.bitmaskclient.firewall.FirewallManager;
import se.leap.bitmaskclient.tethering.TetheringObservable;
@@ -59,17 +56,8 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer
public final static String TAG = TetheringDialog.class.getName();
- @BindView(R.id.tvTitle)
- AppCompatTextView title;
-
- @BindView(R.id.user_message)
- AppCompatTextView userMessage;
-
- @BindView(R.id.selection_list_view)
- RecyclerView selectionListView;
DialogListAdapter adapter;
private DialogListAdapter.ViewModel[] dataset;
- private Unbinder unbinder;
public static class DialogListAdapter extends RecyclerView.Adapter<DialogListAdapter.ViewHolder> {
@@ -139,21 +127,19 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
- View view = inflater.inflate(R.layout.d_list_selection, null);
- unbinder = ButterKnife.bind(this, view);
+ DListSelectionBinding binding = DListSelectionBinding.inflate(inflater);
- title.setText(R.string.tethering);
- userMessage.setMovementMethod(LinkMovementMethod.getInstance());
- userMessage.setLinkTextColor(getContext().getResources().getColor(R.color.colorPrimary));
- userMessage.setText(createUserMessage());
+ binding.tvTitle.setText(R.string.tethering);
+ binding.userMessage.setMovementMethod(LinkMovementMethod.getInstance());
+ binding.userMessage.setLinkTextColor(getContext().getResources().getColor(R.color.colorPrimary));
+ binding.userMessage.setText(createUserMessage());
initDataset();
adapter = new DialogListAdapter(dataset, this::onItemClick);
- selectionListView.setAdapter(adapter);
- selectionListView.setLayoutManager(new LinearLayoutManager(getActivity()));
-
+ binding.selectionListView.setAdapter(adapter);
+ binding.selectionListView.setLayoutManager(new LinearLayoutManager(getActivity()));
- builder.setView(view)
+ builder.setView(binding.getRoot())
.setPositiveButton(android.R.string.ok, (dialog, id) -> {
PreferenceHelper.allowWifiTethering(dataset[0].checked);
PreferenceHelper.allowUsbTethering(dataset[1].checked);
@@ -190,12 +176,6 @@ public class TetheringDialog extends AppCompatDialogFragment implements Observer
TetheringObservable.getInstance().deleteObserver(this);
}
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- unbinder.unbind();
- }
-
public void onItemClick(DialogListAdapter.ViewModel item) {
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java
index 0957712b..ee1a6903 100644
--- a/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java
+++ b/app/src/main/java/se/leap/bitmaskclient/base/views/IconCheckboxEntry.java
@@ -5,31 +5,20 @@ import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
-import android.view.View;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
-import androidx.appcompat.widget.AppCompatImageView;
-import androidx.appcompat.widget.AppCompatTextView;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
-import butterknife.BindView;
-import butterknife.ButterKnife;
import se.leap.bitmaskclient.R;
import se.leap.bitmaskclient.base.fragments.TetheringDialog;
+import se.leap.bitmaskclient.databinding.VIconSelectTextListItemBinding;
public class IconCheckboxEntry extends LinearLayout {
- @BindView(android.R.id.text1)
- AppCompatTextView textView;
-
- @BindView(R.id.material_icon)
- AppCompatImageView iconView;
-
- @BindView(R.id.checked_icon)
- AppCompatImageView checkedIcon;
+ VIconSelectTextListItemBinding binding;
public IconCheckboxEntry(Context context) {
super(context);
@@ -55,14 +44,13 @@ public class IconCheckboxEntry extends LinearLayout {
void initLayout(Context context, AttributeSet attrs) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View rootview = inflater.inflate(R.layout.v_icon_select_text_list_item, this, true);
- ButterKnife.bind(this, rootview);
+ binding = VIconSelectTextListItemBinding.inflate(inflater, this, true);
}
public void bind(TetheringDialog.DialogListAdapter.ViewModel model) {
this.setEnabled(model.enabled);
- textView.setText(model.text);
- textView.setEnabled(model.enabled);
+ binding.text1.setText(model.text);
+ binding.text1.setEnabled(model.enabled);
Drawable checkIcon = DrawableCompat.wrap(getResources().getDrawable(R.drawable.ic_check_bold)).mutate();
if (model.enabled) {
@@ -71,14 +59,14 @@ public class IconCheckboxEntry extends LinearLayout {
DrawableCompat.setTint(checkIcon, ContextCompat.getColor(getContext(), R.color.colorDisabled));
}
- iconView.setImageDrawable(model.image);
- checkedIcon.setImageDrawable(checkIcon);
+ binding.materialIcon.setImageDrawable(model.image);
+ binding.checkedIcon.setImageDrawable(checkIcon);
setChecked(model.checked);
}
public void setChecked(boolean checked) {
- checkedIcon.setVisibility(checked ? VISIBLE : GONE);
- checkedIcon.setContentDescription(checked ? "selected" : "unselected");
+ binding.checkedIcon.setVisibility(checked ? VISIBLE : GONE);
+ binding.checkedIcon.setContentDescription(checked ? "selected" : "unselected");
}
}
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/ProviderHeaderView.java b/app/src/main/java/se/leap/bitmaskclient/base/views/ProviderHeaderView.java
deleted file mode 100644
index 811a54a2..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/base/views/ProviderHeaderView.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package se.leap.bitmaskclient.base.views;
-
-import android.content.Context;
-import androidx.annotation.DrawableRes;
-import androidx.annotation.RequiresApi;
-import androidx.annotation.StringRes;
-import androidx.appcompat.widget.AppCompatImageView;
-import androidx.appcompat.widget.AppCompatTextView;
-import android.util.AttributeSet;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.RelativeLayout;
-
-import se.leap.bitmaskclient.R;
-
-import static se.leap.bitmaskclient.base.utils.ViewHelper.convertDimensionToPx;
-
-/**
- * Created by cyberta on 29.06.18.
- */
-
-public class ProviderHeaderView extends RelativeLayout {
- private int stdPadding;
- private int compactPadding;
- private int stdImageSize;
- private int compactImageSize;
-
- AppCompatImageView providerHeaderLogo;
- AppCompatTextView providerHeaderText;
-
- public ProviderHeaderView(Context context) {
- super(context);
- initLayout(context);
- }
-
- public ProviderHeaderView(Context context, AttributeSet attrs) {
- super(context, attrs);
- initLayout(context);
- }
-
- public ProviderHeaderView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- initLayout(context);
- }
-
- @RequiresApi(21)
- public ProviderHeaderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- initLayout(context);
- }
-
-
- void initLayout(Context context) {
- LayoutInflater inflater = (LayoutInflater) context
- .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- View rootview = inflater.inflate(R.layout.v_provider_header, this, true);
- providerHeaderLogo = rootview.findViewById(R.id.provider_header_logo);
- providerHeaderText = rootview.findViewById(R.id.provider_header_text);
-
- stdPadding = convertDimensionToPx(context, R.dimen.stdpadding);
- compactPadding = convertDimensionToPx(context, R.dimen.compact_padding);
- stdImageSize = convertDimensionToPx(context, R.dimen.bitmask_logo);
- compactImageSize = convertDimensionToPx(context, R.dimen.bitmask_logo_compact);
- }
-
- public void setTitle(String title) {
- providerHeaderText.setText(title);
- }
-
- public void setTitle(@StringRes int stringRes) {
- providerHeaderText.setText(stringRes);
- }
-
- public void setLogo(@DrawableRes int drawableRes) {
- providerHeaderLogo.setImageResource(drawableRes);
- }
-
- public void showCompactLayout() {
- LayoutParams logoLayoutParams = (LayoutParams) providerHeaderLogo.getLayoutParams();
- logoLayoutParams.width = compactImageSize;
- logoLayoutParams.height = compactImageSize;
- providerHeaderLogo.setLayoutParams(logoLayoutParams);
-
- LayoutParams textLayoutParams = (LayoutParams) providerHeaderText.getLayoutParams();
- textLayoutParams.addRule(RIGHT_OF, R.id.provider_header_logo);
- textLayoutParams.addRule(BELOW, 0);
- textLayoutParams.addRule(ALIGN_TOP, R.id.provider_header_logo);
- textLayoutParams.setMargins(compactPadding, compactPadding, compactPadding, compactPadding);
-
- providerHeaderText.setLayoutParams(textLayoutParams);
- providerHeaderText.setMaxLines(2);
- }
-
- public void showStandardLayout() {
- LayoutParams logoLayoutParams = (LayoutParams) providerHeaderLogo.getLayoutParams();
- logoLayoutParams.width = stdImageSize;
- logoLayoutParams.height = stdImageSize;
- providerHeaderLogo.setLayoutParams(logoLayoutParams);
-
- LayoutParams textLayoutParams = (LayoutParams) providerHeaderText.getLayoutParams();
- textLayoutParams.addRule(RIGHT_OF, 0);
- textLayoutParams.addRule(BELOW, R.id.provider_header_logo);
- textLayoutParams.addRule(ALIGN_TOP, 0);
- textLayoutParams.setMargins(stdPadding, stdPadding, stdPadding, stdPadding);
- providerHeaderText.setLayoutParams(textLayoutParams);
- providerHeaderText.setMaxLines(1);
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java
index 4b7d22fc..ee39499b 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderApiSetupBroadcastReceiver.java
@@ -16,6 +16,8 @@
*/
package se.leap.bitmaskclient.providersetup;
+import static android.app.Activity.RESULT_CANCELED;
+
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -27,7 +29,6 @@ import java.lang.ref.WeakReference;
import se.leap.bitmaskclient.base.models.Constants;
import se.leap.bitmaskclient.base.models.Provider;
import se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState;
-import se.leap.bitmaskclient.providersetup.activities.ProviderListBaseActivity;
/**
* Broadcast receiver that handles callback intents of ProviderApi during provider setup.
@@ -38,6 +39,7 @@ import se.leap.bitmaskclient.providersetup.activities.ProviderListBaseActivity;
*/
public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver {
+ private static final String TAG = ProviderApiSetupBroadcastReceiver.class.getSimpleName();
private final WeakReference<ProviderSetupInterface> setupInterfaceRef;
public ProviderApiSetupBroadcastReceiver(ProviderSetupInterface setupInterface) {
@@ -46,7 +48,7 @@ public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
- Log.d(ProviderListBaseActivity.TAG, "received Broadcast");
+ Log.d(TAG, "received Broadcast");
ProviderSetupInterface setupInterface = setupInterfaceRef.get();
String action = intent.getAction();
if (action == null || !action.equalsIgnoreCase(Constants.BROADCAST_PROVIDER_API_EVENT) || setupInterface == null) {
@@ -55,8 +57,8 @@ public class ProviderApiSetupBroadcastReceiver extends BroadcastReceiver {
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: " + resultCode);
+ int resultCode = intent.getIntExtra(Constants.BROADCAST_RESULT_CODE, RESULT_CANCELED);
+ Log.d(TAG, "Broadcast resultCode: " + resultCode);
Bundle resultData = intent.getParcelableExtra(Constants.BROADCAST_RESULT_KEY);
Provider handledProvider = resultData.getParcelable(Constants.PROVIDER_KEY);
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderListAdapter.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderListAdapter.java
deleted file mode 100644
index 76ee33f2..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderListAdapter.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package se.leap.bitmaskclient.providersetup;
-
-import android.view.LayoutInflater;
-
-import com.pedrogomez.renderers.AdapteeCollection;
-import com.pedrogomez.renderers.RendererAdapter;
-import com.pedrogomez.renderers.RendererBuilder;
-
-import se.leap.bitmaskclient.base.models.Provider;
-
-public class ProviderListAdapter extends RendererAdapter<Provider> {
- public ProviderListAdapter(LayoutInflater layoutInflater, RendererBuilder rendererBuilder,
- AdapteeCollection<Provider> collection) {
- super(layoutInflater, rendererBuilder, collection);
- }
-
- public void saveProviders() {
- ProviderManager provider_manager = (ProviderManager) getCollection();
- provider_manager.saveCustomProvidersToFile();
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java
index b46072ff..38198f89 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderManager.java
@@ -19,8 +19,6 @@ import android.content.res.AssetManager;
import androidx.annotation.VisibleForTesting;
-import com.pedrogomez.renderers.AdapteeCollection;
-
import org.json.JSONObject;
import java.io.File;
@@ -39,7 +37,7 @@ import se.leap.bitmaskclient.base.models.Provider;
/**
* Created by parmegv on 4/12/14.
*/
-public class ProviderManager implements AdapteeCollection<Provider> {
+public class ProviderManager {
private final AssetManager assetsManager;
private File externalFilesDir;
@@ -165,12 +163,10 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return allProviders;
}
- @Override
public int size() {
return providers().size();
}
- @Override
public Provider get(int index) {
Iterator<Provider> iterator = providers().iterator();
while (iterator.hasNext() && index > 0) {
@@ -180,7 +176,6 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return iterator.next();
}
- @Override
public boolean add(Provider element) {
return element != null &&
!defaultProviderURLs.contains(element.getMainUrl().toString()) &&
@@ -188,14 +183,12 @@ public class ProviderManager implements AdapteeCollection<Provider> {
customProviderURLs.add(element.getMainUrl().toString());
}
- @Override
public boolean remove(Object element) {
return element instanceof Provider &&
customProviders.remove(element) &&
customProviderURLs.remove(((Provider) element).getMainUrl().toString());
}
- @Override
public boolean addAll(Collection<? extends Provider> elements) {
Iterator iterator = elements.iterator();
boolean addedAll = true;
@@ -208,7 +201,6 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return addedAll;
}
- @Override
public boolean removeAll(Collection<?> elements) {
Iterator iterator = elements.iterator();
boolean removedAll = true;
@@ -226,7 +218,6 @@ public class ProviderManager implements AdapteeCollection<Provider> {
return removedAll;
}
- @Override
public void clear() {
defaultProviders.clear();
customProviders.clear();
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRenderer.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRenderer.java
deleted file mode 100644
index 8aba4941..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRenderer.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package se.leap.bitmaskclient.providersetup;
-
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import androidx.appcompat.widget.AppCompatTextView;
-
-import com.pedrogomez.renderers.Renderer;
-
-import butterknife.BindView;
-import butterknife.ButterKnife;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.base.models.Provider;
-
-/**
- * Created by parmegv on 4/12/14.
- */
-public class ProviderRenderer extends Renderer<Provider> {
- private final Context context;
-
- @BindView(R.id.provider_name)
- AppCompatTextView name;
- @BindView(R.id.provider_domain)
- AppCompatTextView domain;
-
- public ProviderRenderer(Context context) {
- this.context = context;
- }
-
- @Override
- protected View inflate(LayoutInflater inflater, ViewGroup parent) {
- View view = inflater.inflate(R.layout.v_provider_list_item, parent, false);
- ButterKnife.bind(this, view);
- return view;
- }
-
- @Override
- protected void setUpView(View rootView) {
- /*
- * Empty implementation substituted with the usage of ButterKnife library by Jake Wharton.
- */
- }
-
- @Override
- protected void hookListeners(View rootView) {
- //Empty
- }
-
- @Override
- public void render() {
- Provider provider = getContent();
- if (!provider.isDefault()) {
- name.setText(provider.getName());
- domain.setText(provider.getDomain());
- } else {
- domain.setText(R.string.add_provider);
- }
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRendererBuilder.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRendererBuilder.java
deleted file mode 100644
index 7d2b4742..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/ProviderRendererBuilder.java
+++ /dev/null
@@ -1,21 +0,0 @@
-package se.leap.bitmaskclient.providersetup;
-
-import com.pedrogomez.renderers.*;
-
-import java.util.*;
-
-import se.leap.bitmaskclient.base.models.Provider;
-
-/**
- * Created by parmegv on 4/12/14.
- */
-public class ProviderRendererBuilder extends RendererBuilder<Provider> {
- public ProviderRendererBuilder(Collection<Renderer<Provider>> prototypes) {
- super(prototypes);
- }
-
- @Override
- protected Class getPrototypeClass(Provider content) {
- return ProviderRenderer.class;
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/TorLogAdapter.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/TorLogAdapter.java
index 3df0fd94..816d4690 100644
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/TorLogAdapter.java
+++ b/app/src/main/java/se/leap/bitmaskclient/providersetup/TorLogAdapter.java
@@ -11,7 +11,6 @@ import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.providersetup.activities.ConfigWizardBaseActivity;
public class TorLogAdapter extends RecyclerView.Adapter<TorLogAdapter.ViewHolder> {
private List<String> values;
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AbstractProviderDetailActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AbstractProviderDetailActivity.java
deleted file mode 100644
index 66999580..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AbstractProviderDetailActivity.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package se.leap.bitmaskclient.providersetup.activities;
-
-import android.content.Intent;
-import android.os.Bundle;
-import androidx.annotation.Nullable;
-import androidx.appcompat.widget.AppCompatTextView;
-import android.util.Log;
-import android.widget.ArrayAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-import java.util.ArrayList;
-
-
-import butterknife.BindView;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.R;
-
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-
-public abstract class AbstractProviderDetailActivity extends ConfigWizardBaseActivity {
-
- final public static String TAG = "providerDetailActivity";
-
- @BindView(R.id.provider_detail_description)
- AppCompatTextView description;
-
- @BindView(R.id.provider_detail_options)
- ListView options;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- provider = getIntent().getParcelableExtra(PROVIDER_KEY);
- setContentView(R.layout.a_provider_detail);
-
- if (provider == null) {
- return;
- }
-
- setProviderHeaderText(provider.getName());
- description.setText(provider.getDescription());
-
- // Show only the options allowed by the provider
- ArrayList<String> optionsList = new ArrayList<>();
- if (provider.allowsRegistered()) {
- optionsList.add(getString(R.string.login_to_profile));
- optionsList.add(getString(R.string.create_profile));
- if (provider.allowsAnonymous()) {
- optionsList.add(getString(R.string.use_anonymously_button));
- }
- } else {
- onAnonymouslySelected();
- }
-
- options.setAdapter(new ArrayAdapter<>(
- this,
- R.layout.v_single_list_item,
- android.R.id.text1,
- optionsList.toArray(new String[optionsList.size()])
- ));
- options.setOnItemClickListener((parent, view, position, id) -> {
- String text = ((AppCompatTextView) view).getText().toString();
- Intent intent;
- if (text.equals(getString(R.string.login_to_profile))) {
- Log.d(TAG, "login selected");
- intent = new Intent(getApplicationContext(), LoginActivity.class);
- } else if (text.equals(getString(R.string.create_profile))) {
- Log.d(TAG, "signup selected");
- intent = new Intent(getApplicationContext(), SignupActivity.class);
- } else {
- onAnonymouslySelected();
- return;
- }
- intent.putExtra(PROVIDER_KEY, provider);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
- startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP);
- });
- }
-
- @Override
- protected void onNewIntent(Intent intent) {
- super.onNewIntent(intent);
- provider = intent.getParcelableExtra(PROVIDER_KEY);
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
- if (resultCode == RESULT_OK) {
- setResult(resultCode, data);
- finish();
- }
- }
- }
-
- private void onAnonymouslySelected() {
- Intent intent;
- Log.d(TAG, "use anonymously selected");
- intent = new Intent();
- intent.putExtra(Provider.KEY, provider);
- setResult(RESULT_OK, intent);
- finish();
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AddProviderBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AddProviderBaseActivity.java
deleted file mode 100644
index 193c1d59..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/AddProviderBaseActivity.java
+++ /dev/null
@@ -1,126 +0,0 @@
-package se.leap.bitmaskclient.providersetup.activities;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.View;
-import android.widget.Button;
-
-import com.google.android.material.textfield.TextInputEditText;
-import com.google.android.material.textfield.TextInputLayout;
-
-import butterknife.BindView;
-import se.leap.bitmaskclient.R;
-
-import static se.leap.bitmaskclient.providersetup.activities.ProviderListBaseActivity.EXTRAS_KEY_INVALID_URL;
-
-/**
- * Created by cyberta on 30.06.18.
- */
-
-public abstract class AddProviderBaseActivity extends ConfigWizardBaseActivity {
-
- final public static String EXTRAS_KEY_NEW_URL = "NEW_URL";
-
- @BindView(R.id.text_uri_error)
- TextInputLayout urlError;
-
- @BindView(R.id.text_uri)
- TextInputEditText editUrl;
-
- @BindView(R.id.button_cancel)
- Button cancelButton;
-
- @BindView(R.id.button_save)
- Button saveButton;
-
-
- protected void init() {
- Bundle extras = this.getIntent().getExtras();
- if (extras != null && extras.containsKey(EXTRAS_KEY_INVALID_URL)) {
- editUrl.setText(extras.getString(EXTRAS_KEY_INVALID_URL));
- saveButton.setEnabled(true);
- }
-
- setupSaveButton();
- setupCancelButton();
- setUpListeners();
- setUpInitialUI();
- }
-
- public abstract void setupSaveButton();
-
- private void setupCancelButton() {
- cancelButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- finish();
- }
- });
- }
-
- private void setUpInitialUI() {
- setProviderHeaderText(R.string.add_provider);
- hideProgressBar();
- }
-
- protected void saveProvider() {
- String entered_url = getURL();
- if (validURL(entered_url)) {
- Intent intent = this.getIntent();
- intent.putExtra(EXTRAS_KEY_NEW_URL, entered_url);
- setResult(RESULT_OK, intent);
- finish();
- } else {
- editUrl.setText("");
- urlError.setError(getString(R.string.not_valid_url_entered));
- }
- }
-
- private void setUpListeners() {
-
- editUrl.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- if (!validURL(getURL())) {
- urlError.setError(getString(R.string.not_valid_url_entered));
- saveButton.setEnabled(false);
-
- } else {
- urlError.setError(null);
- saveButton.setEnabled(true);
- }
- }
- });
- }
-
- private String getURL() {
- String entered_url = editUrl.getText().toString().trim();
- if (entered_url.contains("www.")) entered_url = entered_url.replaceFirst("www.", "");
- if (!entered_url.startsWith("https://")) {
- if (entered_url.startsWith("http://")) {
- entered_url = entered_url.substring("http://".length());
- }
- entered_url = "https://".concat(entered_url);
- }
- return entered_url;
- }
-
- /**
- * Checks if the entered url is valid or not.
- *
- * @param enteredUrl
- * @return true if it's not empty nor contains only the protocol.
- */
- boolean validURL(String enteredUrl) {
- return android.util.Patterns.WEB_URL.matcher(enteredUrl).matches();
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ButterKnifeActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ButterKnifeActivity.java
deleted file mode 100644
index c695cc46..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ButterKnifeActivity.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * Copyright (c) 2020 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.providersetup.activities;
-
-import android.view.View;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import butterknife.ButterKnife;
-
-/**
- * Automatically inject with ButterKnife after calling setContentView
- */
-
-public abstract class ButterKnifeActivity extends AppCompatActivity {
-
- @Override
- public void setContentView(View view) {
- super.setContentView(view);
- ButterKnife.bind(this);
- }
-
- @Override
- public void setContentView(int layoutResID) {
- super.setContentView(layoutResID);
- ButterKnife.bind(this);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java
deleted file mode 100644
index 1bf66d7d..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ConfigWizardBaseActivity.java
+++ /dev/null
@@ -1,430 +0,0 @@
-package se.leap.bitmaskclient.providersetup.activities;
-
-import static android.content.res.Configuration.ORIENTATION_LANDSCAPE;
-import static android.view.View.GONE;
-import static android.view.View.VISIBLE;
-import static androidx.recyclerview.widget.RecyclerView.SCROLL_STATE_IDLE;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.tor.TorStatusObservable.getBootstrapProgress;
-import static se.leap.bitmaskclient.tor.TorStatusObservable.getLastLogs;
-import static se.leap.bitmaskclient.tor.TorStatusObservable.getLastSnowflakeLog;
-import static se.leap.bitmaskclient.tor.TorStatusObservable.getLastTorLog;
-import static se.leap.bitmaskclient.tor.TorStatusObservable.getStringForCurrentStatus;
-
-import android.graphics.Rect;
-import android.os.Build;
-import android.os.Bundle;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewTreeObserver;
-import android.widget.LinearLayout;
-import android.widget.ProgressBar;
-import android.widget.RelativeLayout;
-
-import androidx.annotation.DrawableRes;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.annotation.StringRes;
-import androidx.appcompat.widget.AppCompatTextView;
-import androidx.constraintlayout.widget.ConstraintLayout;
-import androidx.constraintlayout.widget.Guideline;
-import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
-
-import java.util.List;
-import java.util.Observable;
-import java.util.Observer;
-
-import butterknife.BindView;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.base.views.ProviderHeaderView;
-import se.leap.bitmaskclient.providersetup.TorLogAdapter;
-import se.leap.bitmaskclient.tor.TorStatusObservable;
-
-/**
- * Base Activity for configuration wizard activities
- *
- * Created by fupduck on 09.01.18.
- */
-
-public abstract class ConfigWizardBaseActivity extends ButterKnifeActivity implements Observer {
-
- private static final String TAG = ConfigWizardBaseActivity.class.getName();
- public static final float GUIDE_LINE_COMPACT_DELTA = 0.1f;
-
- @BindView(R.id.header)
- ProviderHeaderView providerHeaderView;
-
- //Add provider screen has no loading screen
- @Nullable
- @BindView(R.id.loading_screen)
- protected LinearLayout loadingScreen;
-
- @Nullable
- @BindView(R.id.btn_connection_detail)
- protected AppCompatTextView connectionDetailBtn;
-
- @Nullable
- @BindView(R.id.connection_detail_header_container)
- protected RelativeLayout connectionDetailHeaderContainer;
-
- @Nullable
- @BindView(R.id.connection_details_title)
- protected AppCompatTextView connectionDetailsTitle;
-
- @Nullable
- @BindView(R.id.connection_detail_container)
- protected RelativeLayout connectionDetailContainer;
-
- @Nullable
- @BindView(R.id.log_container)
- protected RelativeLayout logsContainer;
-
- @Nullable
- @BindView(R.id.tor_state)
- protected AppCompatTextView torState;
-
- @Nullable
- @BindView(R.id.snowflake_state)
- protected AppCompatTextView snowflakeState;
-
- @Nullable
- @BindView(R.id.connection_detail_logs)
- protected RecyclerView connectionDetailLogs;
-
- private TorLogAdapter torLogAdapter;
-
- @Nullable
- @BindView(R.id.progressbar)
- protected ProgressBar progressBar;
-
- @Nullable
- @BindView(R.id.progressbar_title)
- protected AppCompatTextView progressbarTitle;
-
- @Nullable
- @BindView(R.id.progressbar_description)
- protected AppCompatTextView progressbarDescription;
-
- //Only tablet layouts have guidelines as they are based on a ConstraintLayout
- @Nullable
- @BindView(R.id.guideline_top)
- protected Guideline guideline_top;
-
- @Nullable
- @BindView(R.id.guideline_bottom)
- protected Guideline guideline_bottom;
-
- @BindView(R.id.content)
- protected LinearLayout content;
-
- protected Provider provider;
-
- protected boolean isCompactLayout = false;
- protected boolean isActivityShowing;
-
- private float defaultGuidelineTopPercentage;
- private float defaultGuidelineBottomPercentage;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- provider = getIntent().getParcelableExtra(PROVIDER_KEY);
- }
-
- @Override
- public void setContentView(View view) {
- super.setContentView(view);
- initContentView();
- }
-
- @Override
- public void setContentView(int layoutResID) {
- super.setContentView(layoutResID);
- initContentView();
- }
-
- @Override
- public void setContentView(View view, ViewGroup.LayoutParams params) {
- super.setContentView(view, params);
- initContentView();
- }
-
- private void initContentView() {
- if (provider != null) {
- setProviderHeaderText(provider.getName());
- }
- setDefaultGuidelineValues();
- setGlobalLayoutChangeListener();
- }
-
- private void setDefaultGuidelineValues() {
- if (isTabletLayout()) {
- defaultGuidelineTopPercentage = ((ConstraintLayout.LayoutParams) guideline_top.getLayoutParams()).guidePercent;
- defaultGuidelineBottomPercentage = ((ConstraintLayout.LayoutParams) guideline_bottom.getLayoutParams()).guidePercent;
- }
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- if (provider != null) {
- outState.putParcelable(PROVIDER_KEY, provider);
- }
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- isActivityShowing = false;
- TorStatusObservable.getInstance().deleteObserver(this);
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- isActivityShowing = true;
- TorStatusObservable.getInstance().addObserver(this);
- setProgressbarDescription(getStringForCurrentStatus(this));
- }
-
- protected void restoreState(Bundle savedInstanceState) {
- if (savedInstanceState != null && savedInstanceState.containsKey(PROVIDER_KEY)) {
- provider = savedInstanceState.getParcelable(PROVIDER_KEY);
- }
- }
-
- protected void setProviderHeaderLogo(@DrawableRes int providerHeaderLogo) {
- providerHeaderView.setLogo(providerHeaderLogo);
- }
-
- protected void setProviderHeaderText(String providerHeaderText) {
- providerHeaderView.setTitle(providerHeaderText);
- }
-
- protected void setProviderHeaderText(@StringRes int providerHeaderText) {
- providerHeaderView.setTitle(providerHeaderText);
- }
-
- protected void hideConnectionDetails() {
- if (loadingScreen == null) {
- return;
- }
- if (connectionDetailContainer.getVisibility() == VISIBLE) {
- connectionDetailBtn.setText(R.string.show_connection_details);
- }
- connectionDetailHeaderContainer.setVisibility(GONE);
- connectionDetailContainer.setVisibility(GONE);
- logsContainer.setVisibility(GONE);
- }
-
- protected void showConnectionDetails() {
- if (loadingScreen == null) {
- return;
- }
- LinearLayoutManager layoutManager = new LinearLayoutManager(this);
- connectionDetailLogs.setLayoutManager(layoutManager);
- torLogAdapter = new TorLogAdapter(getLastLogs());
- connectionDetailLogs.setAdapter(torLogAdapter);
-
- connectionDetailLogs.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
- super.onScrollStateChanged(recyclerView, newState);
- if (newState != SCROLL_STATE_IDLE) {
- torLogAdapter.postponeUpdate = true;
- } else if (newState == SCROLL_STATE_IDLE && getFirstVisibleItemPosion() == 0) {
- torLogAdapter.postponeUpdate = false;
- }
- }
- });
-
- snowflakeState.setText(getLastSnowflakeLog());
- torState.setText(getLastTorLog());
- connectionDetailBtn.setOnClickListener(v -> {
- if (logsContainer.getVisibility() == VISIBLE) {
- logsContainer.setVisibility(GONE);
- connectionDetailContainer.setVisibility(GONE);
- connectionDetailsTitle.setVisibility(GONE);
- connectionDetailBtn.setText(R.string.show_connection_details);
- } else {
- logsContainer.setVisibility(VISIBLE);
- connectionDetailContainer.setVisibility(VISIBLE);
- connectionDetailsTitle.setVisibility(VISIBLE);
- connectionDetailBtn.setText(R.string.hide);
- }
- });
- connectionDetailHeaderContainer.setVisibility(VISIBLE);
- }
-
- private int getFirstVisibleItemPosion() {
- return ((LinearLayoutManager)connectionDetailLogs.getLayoutManager()).findFirstVisibleItemPosition();
- }
-
- protected void hideProgressBar() {
- if (loadingScreen == null) {
- return;
- }
- hideConnectionDetails();
- loadingScreen.setVisibility(GONE);
- content.setVisibility(VISIBLE);
- }
-
- protected void showProgressBar() {
- if (loadingScreen == null) {
- return;
- }
- content.setVisibility(GONE);
- loadingScreen.setVisibility(VISIBLE);
- }
-
- protected void setProgressbarTitle(@StringRes int progressbarTitle) {
- if (loadingScreen == null) {
- return;
- }
- this.progressbarTitle.setText(progressbarTitle);
- }
-
- protected void setProgressbarDescription(String progressbarDescription) {
- if (loadingScreen == null) {
- return;
- }
- this.progressbarDescription.setText(progressbarDescription);
- }
-
- protected void setConfigProgress(int value) {
- if (loadingScreen == null) {
- return;
- }
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
- progressBar.setProgress(value);
- } else {
- progressBar.setProgress(value, true);
- }
- progressBar.setIndeterminate(value >= 100 || value < 0);
- }
-
-
- protected void showCompactLayout() {
- if (isCompactLayout) {
- return;
- }
-
- if (isTabletLayoutInLandscape() || isPhoneLayout()) {
- providerHeaderView.showCompactLayout();
- }
-
- showIncreasedTabletContentArea();
- isCompactLayout = true;
- }
-
- protected void showStandardLayout() {
- if (!isCompactLayout) {
- return;
- }
- providerHeaderView.showStandardLayout();
- showStandardTabletContentArea();
- isCompactLayout = false;
- }
-
- private boolean isTabletLayoutInLandscape() {
- // TabletLayout is based on a ConstraintLayout and uses Guidelines whereas the phone layout
- // has no such elements in it's layout xml file
- return guideline_top != null &&
- guideline_bottom != null &&
- getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE;
- }
-
- protected boolean isPhoneLayout() {
- return guideline_top == null && guideline_bottom == null;
- }
-
- protected boolean isTabletLayout() {
- return guideline_top != null && guideline_bottom != null;
- }
-
- /**
- * Increases the white content area in tablet layouts
- */
- private void showIncreasedTabletContentArea() {
- if (isPhoneLayout()) {
- return;
- }
- ConstraintLayout.LayoutParams guideLineTopParams = (ConstraintLayout.LayoutParams) guideline_top.getLayoutParams();
- float increasedTopPercentage = defaultGuidelineTopPercentage - GUIDE_LINE_COMPACT_DELTA;
- guideLineTopParams.guidePercent = increasedTopPercentage > 0f ? increasedTopPercentage : 0f;
- guideline_top.setLayoutParams(guideLineTopParams);
-
- ConstraintLayout.LayoutParams guideLineBottomParams = (ConstraintLayout.LayoutParams) guideline_bottom.getLayoutParams();
- float increasedBottomPercentage = defaultGuidelineBottomPercentage + GUIDE_LINE_COMPACT_DELTA;
- guideLineBottomParams.guidePercent = increasedBottomPercentage < 1f ? increasedBottomPercentage : 1f;
- guideline_bottom.setLayoutParams(guideLineBottomParams);
- }
-
- /**
- * Restores the default size of the white content area in tablet layouts
- */
- private void showStandardTabletContentArea() {
- if (isPhoneLayout()) {
- return;
- }
- ConstraintLayout.LayoutParams guideLineTopParams = (ConstraintLayout.LayoutParams) guideline_top.getLayoutParams();
- guideLineTopParams.guidePercent = defaultGuidelineTopPercentage;
- guideline_top.setLayoutParams(guideLineTopParams);
-
- ConstraintLayout.LayoutParams guideLineBottomParams = (ConstraintLayout.LayoutParams) guideline_bottom.getLayoutParams();
- guideLineBottomParams.guidePercent = defaultGuidelineBottomPercentage;
- guideline_bottom.setLayoutParams(guideLineBottomParams);
- }
-
- /**
- * Checks if the keyboard is shown and switches between the standard layout and the compact layout
- */
- private void setGlobalLayoutChangeListener() {
- final View rootView = content.getRootView();
- rootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- Rect r = new Rect();
- //r will be populated with the coordinates of your view that area still visible.
- rootView.getWindowVisibleDisplayFrame(r);
-
- float deltaHiddenScreen = 1f - ((float) (r.bottom - r.top) / (float) rootView.getHeight());
- if (deltaHiddenScreen > 0.25f) {
- // if more than 1/4 of the screen is hidden
- showCompactLayout();
- } else {
- showStandardLayout();
- }
- }
- });
- }
-
- @Override
- public void update(Observable o, Object arg) {
- if (o instanceof TorStatusObservable) {
- runOnUiThread(() -> {
- if (TorStatusObservable.getStatus() != TorStatusObservable.TorStatus.OFF && loadingScreen != null) {
- if (connectionDetailContainer.getVisibility() == GONE) {
- showConnectionDetails();
- } else {
- setLogs(getLastTorLog(), getLastSnowflakeLog(), getLastLogs());
- }
- }
- setProgressbarDescription(getStringForCurrentStatus(ConfigWizardBaseActivity.this));
- setConfigProgress(getBootstrapProgress());
- });
- }
- }
-
- protected void setLogs(String torLog, String snowflakeLog, List<String> lastLogs) {
- if (loadingScreen == null) {
- return;
- }
- torLogAdapter.updateData(lastLogs);
- torState.setText(torLog);
- snowflakeState.setText(snowflakeLog);
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
deleted file mode 100644
index 520395f8..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/CustomProviderSetupActivity.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/**
- * Copyright (c) 2018 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.providersetup.activities;
-
-import android.content.Intent;
-import android.content.res.AssetManager;
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-
-import java.io.IOException;
-
-import se.leap.bitmaskclient.BuildConfig;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.base.utils.ConfigHelper;
-import se.leap.bitmaskclient.providersetup.ProviderAPICommand;
-
-import static se.leap.bitmaskclient.BuildConfig.customProviderApiIp;
-import static se.leap.bitmaskclient.BuildConfig.customProviderIp;
-import static se.leap.bitmaskclient.BuildConfig.customProviderMotdUrl;
-import static se.leap.bitmaskclient.BuildConfig.customProviderUrl;
-import static se.leap.bitmaskclient.BuildConfig.geoipUrl;
-import static se.leap.bitmaskclient.base.models.Constants.EXT_JSON;
-import static se.leap.bitmaskclient.base.models.Constants.EXT_PEM;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-import static se.leap.bitmaskclient.base.utils.ConfigHelper.preferAnonymousUsage;
-import static se.leap.bitmaskclient.base.utils.InputStreamHelper.loadInputStreamAsString;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.SET_UP_PROVIDER;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER;
-
-/**
- * Created by cyberta on 17.08.18.
- */
-
-public class CustomProviderSetupActivity extends ProviderSetupBaseActivity {
-
- @Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setUpInitialUI();
- restoreState(savedInstanceState);
- setDefaultProvider();
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- if (getConfigState() == ProviderConfigState.PROVIDER_NOT_SET) {
- showProgressBar();
- setupProvider();
- }
- }
-
- private void setDefaultProvider() {
- try {
- AssetManager assetsManager = getAssets();
- Provider customProvider = new Provider(customProviderUrl, geoipUrl, customProviderMotdUrl, customProviderIp, customProviderApiIp);
- String domain = ConfigHelper.getDomainFromMainURL(customProviderUrl);
- String certificate = loadInputStreamAsString(assetsManager.open(domain + EXT_PEM));
- String providerDefinition = loadInputStreamAsString(assetsManager.open(domain + EXT_JSON));
- customProvider.setCaCert(certificate);
- customProvider.define(new JSONObject(providerDefinition));
- setProvider(customProvider);
- } catch (IOException | JSONException e) {
- e.printStackTrace();
- setProvider(new Provider(customProviderUrl, geoipUrl, customProviderMotdUrl, customProviderIp, customProviderApiIp));
- }
- }
-
- private void setUpInitialUI() {
- setContentView(R.layout.a_custom_provider_setup);
- setProviderHeaderText(R.string.setup_provider);
- hideProgressBar();
- }
-
- private void setupProvider() {
- setProviderConfigState(SETTING_UP_PROVIDER);
- ProviderAPICommand.execute(this, SET_UP_PROVIDER, getProvider());
- }
-
- // ------- ProviderSetupInterface ---v
- @Override
- public void handleProviderSetUp(Provider provider) {
- setProvider(provider);
- if (provider.allowsAnonymous()) {
- downloadVpnCertificate();
- } else {
- showProviderDetails();
- }
- }
-
- @Override
- public void handleCorrectlyDownloadedCertificate(Provider provider) {
- if (preferAnonymousUsage()) {
- finishWithSetupWithProvider(provider);
- } else {
- this.provider = provider;
- showProviderDetails();
- }
- }
-
- // ------- DownloadFailedDialogInterface ---v
- @Override
- public void retrySetUpProvider(@NonNull Provider provider) {
- setupProvider();
- showProgressBar();
- }
-
- @Override
- public void cancelSettingUpProvider() {
- super.cancelSettingUpProvider();
- finish();
- }
-
- @Override
- public void addAndSelectNewProvider(String url) {
- // ignore
- }
-
- private void finishWithSetupWithProvider(Provider provider) {
- Intent intent = new Intent();
- intent.putExtra(Provider.KEY, provider);
- setResult(RESULT_OK, intent);
- finish();
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
- setResult(resultCode, data);
- finish();
- }
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/LoginActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/LoginActivity.java
deleted file mode 100644
index 9a5f31f2..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/LoginActivity.java
+++ /dev/null
@@ -1,32 +0,0 @@
-package se.leap.bitmaskclient.providersetup.activities;
-
-import android.os.Bundle;
-import androidx.annotation.Nullable;
-
-import butterknife.OnClick;
-import se.leap.bitmaskclient.R;
-
-/**
- * Activity to login to chosen Provider
- *
- * Created by fupduck on 09.01.18.
- */
-
-public class LoginActivity extends ProviderCredentialsBaseActivity {
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setProgressbarTitle(R.string.logging_in);
- setProviderHeaderLogo(R.drawable.logo);
- setProviderHeaderText(R.string.login_to_profile);
- }
-
- @Override
- @OnClick(R.id.button)
- void handleButton() {
- super.handleButton();
- login(getUsername(), getPassword());
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderCredentialsBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderCredentialsBaseActivity.java
deleted file mode 100644
index e186ce5d..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderCredentialsBaseActivity.java
+++ /dev/null
@@ -1,479 +0,0 @@
-/**
- * Copyright (c) 2018 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.providersetup.activities;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Build;
-import android.os.Build.VERSION_CODES;
-import android.os.Bundle;
-import androidx.annotation.Nullable;
-import androidx.annotation.StringRes;
-import com.google.android.material.textfield.TextInputEditText;
-import com.google.android.material.textfield.TextInputLayout;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-import androidx.appcompat.widget.AppCompatButton;
-import androidx.appcompat.widget.AppCompatTextView;
-import android.text.Editable;
-import android.text.Html;
-import android.text.TextWatcher;
-import android.text.method.LinkMovementMethod;
-import android.text.util.Linkify;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.TextView;
-
-import org.json.JSONArray;
-import org.json.JSONException;
-
-import butterknife.BindView;
-import butterknife.OnClick;
-import se.leap.bitmaskclient.base.models.Constants.CREDENTIAL_ERRORS;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.providersetup.ProviderAPI;
-import se.leap.bitmaskclient.providersetup.ProviderAPICommand;
-import se.leap.bitmaskclient.R;
-
-import static android.text.TextUtils.isEmpty;
-import static android.view.View.GONE;
-import static android.view.View.VISIBLE;
-import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
-import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_PROVIDER_API_EVENT;
-import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_RESULT_CODE;
-import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_RESULT_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.CREDENTIALS_PASSWORD;
-import static se.leap.bitmaskclient.base.models.Constants.CREDENTIALS_USERNAME;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.DOWNLOAD_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.LOG_IN;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.SIGN_UP;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.USER_MESSAGE;
-
-/**
- * Base Activity for activities concerning a provider interaction
- *
- * Created by fupduck on 09.01.18.
- */
-
-public abstract class ProviderCredentialsBaseActivity extends ConfigWizardBaseActivity {
-
- final protected static String TAG = ProviderCredentialsBaseActivity.class.getName();
-
- final private static String ACTIVITY_STATE = "ACTIVITY STATE";
-
- final private static String SHOWING_FORM = "SHOWING_FORM";
- final private static String PERFORMING_ACTION = "PERFORMING_ACTION";
- final private static String USERNAME_ERROR = "USERNAME_ERROR";
- final private static String PASSWORD_ERROR = "PASSWORD_ERROR";
- final private static String PASSWORD_VERIFICATION_ERROR = "PASSWORD_VERIFICATION_ERROR";
-
- protected Intent mConfigState = new Intent(SHOWING_FORM);
- protected ProviderAPIBroadcastReceiver providerAPIBroadcastReceiver;
-
- @BindView(R.id.provider_credentials_user_message)
- AppCompatTextView userMessage;
-
- @BindView(R.id.provider_credentials_username)
- TextInputEditText usernameField;
-
- @BindView(R.id.provider_credentials_password)
- TextInputEditText passwordField;
-
- @BindView(R.id.provider_credentials_password_verification)
- TextInputEditText passwordVerificationField;
-
- @BindView(R.id.provider_credentials_username_error)
- TextInputLayout usernameError;
-
- @BindView(R.id.provider_credentials_password_error)
- TextInputLayout passwordError;
-
- @BindView(R.id.provider_credentials_password_verification_error)
- TextInputLayout passwordVerificationError;
-
- @BindView(R.id.button)
- AppCompatButton button;
-
- private boolean isUsernameError = false;
- private boolean isPasswordError = false;
- private boolean isVerificationError = false;
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.a_provider_credentials);
- providerAPIBroadcastReceiver = new ProviderAPIBroadcastReceiver();
-
- IntentFilter updateIntentFilter = new IntentFilter(BROADCAST_PROVIDER_API_EVENT);
- updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
- LocalBroadcastManager.getInstance(this).registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter);
-
- setUpListeners();
- restoreState(savedInstanceState);
-
- String userMessageString = getIntent().getStringExtra(USER_MESSAGE);
- if (userMessageString != null) {
- userMessage.setText(userMessageString);
- userMessage.setVisibility(VISIBLE);
- }
- }
-
- @Override
- protected void onResume() {
- super.onResume();
-
- String action = mConfigState.getAction();
- if (action == null) {
- return;
- }
-
- if(action.equalsIgnoreCase(PERFORMING_ACTION)) {
- showProgressBar();
- }
- }
-
- protected void restoreState(Bundle savedInstance) {
- super.restoreState(savedInstance);
- if (savedInstance == null) {
- return;
- }
- if (savedInstance.getString(USER_MESSAGE) != null) {
- userMessage.setText(savedInstance.getString(USER_MESSAGE));
- userMessage.setVisibility(VISIBLE);
- }
- updateUsernameError(savedInstance.getString(USERNAME_ERROR));
- updatePasswordError(savedInstance.getString(PASSWORD_ERROR));
- updateVerificationError(savedInstance.getString(PASSWORD_VERIFICATION_ERROR));
- if (savedInstance.getString(ACTIVITY_STATE) != null) {
- mConfigState.setAction(savedInstance.getString(ACTIVITY_STATE));
- }
- }
-
- private void updateUsernameError(String usernameErrorString) {
- usernameError.setError(usernameErrorString);
- isUsernameError = usernameErrorString != null;
- updateButton();
- }
-
- private void updatePasswordError(String passwordErrorString) {
- passwordError.setError(passwordErrorString);
- isPasswordError = passwordErrorString != null;
- updateButton();
- }
-
- private void updateVerificationError(String verificationErrorString) {
- passwordVerificationError.setError(verificationErrorString);
- isVerificationError = verificationErrorString != null;
- updateButton();
- }
-
- private void updateButton() {
- button.setEnabled(!isPasswordError &&
- !isUsernameError &&
- !isVerificationError &&
- !isEmpty(passwordField.getText()) &&
- !isEmpty(usernameField.getText()) &&
- !(passwordVerificationField.getVisibility() == VISIBLE &&
- getPasswordVerification().length() == 0));
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- outState.putString(ACTIVITY_STATE, mConfigState.getAction());
- if (userMessage.getText() != null && userMessage.getVisibility() == VISIBLE) {
- outState.putString(USER_MESSAGE, userMessage.getText().toString());
- }
- if (usernameError.getError() != null) {
- outState.putString(USERNAME_ERROR, usernameError.getError().toString());
- }
- if (passwordError.getError() != null) {
- outState.putString(PASSWORD_ERROR, passwordError.getError().toString());
- }
- if (passwordVerificationError.getError() != null) {
- outState.putString(PASSWORD_VERIFICATION_ERROR, passwordVerificationError.getError().toString());
- }
-
- super.onSaveInstanceState(outState);
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (providerAPIBroadcastReceiver != null)
- LocalBroadcastManager.getInstance(this).unregisterReceiver(providerAPIBroadcastReceiver);
- }
-
- @OnClick(R.id.button)
- void handleButton() {
- mConfigState.setAction(PERFORMING_ACTION);
- hideKeyboard();
- showProgressBar();
- }
-
- protected void setButtonText(@StringRes int buttonText) {
- button.setText(buttonText);
- }
-
- String getUsername() {
- String username = usernameField.getText().toString();
- String providerDomain = provider.getDomain();
- if (username.endsWith(providerDomain)) {
- try {
- return username.split("@" + providerDomain)[0];
- } catch (ArrayIndexOutOfBoundsException e) {
- return "";
- }
- }
- return username;
- }
-
- String getPassword() {
- return passwordField.getText().toString();
- }
-
- String getPasswordVerification() {
- return passwordVerificationField.getText().toString();
- }
-
- void login(String username, String password) {
-
- Bundle parameters = bundleUsernameAndPassword(username, password);
- ProviderAPICommand.execute(this, LOG_IN, parameters, provider);
- }
-
- public void signUp(String username, String password) {
-
- Bundle parameters = bundleUsernameAndPassword(username, password);
- ProviderAPICommand.execute(this, SIGN_UP, parameters, provider);
- }
-
- void downloadVpnCertificate(Provider handledProvider) {
- provider = handledProvider;
- ProviderAPICommand.execute(this, DOWNLOAD_VPN_CERTIFICATE, provider);
- }
-
- protected Bundle bundleUsernameAndPassword(String username, String password) {
- Bundle parameters = new Bundle();
- if (!username.isEmpty())
- parameters.putString(CREDENTIALS_USERNAME, username);
- if (!password.isEmpty())
- parameters.putString(CREDENTIALS_PASSWORD, password);
- return parameters;
- }
-
- private void setUpListeners() {
- usernameField.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- if (getUsername().equalsIgnoreCase("")) {
- s.clear();
- updateUsernameError(getString(R.string.username_ask));
- } else {
- updateUsernameError(null);
- String suffix = "@" + provider.getDomain();
- if (!usernameField.getText().toString().endsWith(suffix)) {
- s.append(suffix);
- usernameField.setSelection(usernameField.getText().toString().indexOf('@'));
- }
- }
- }
- });
- usernameField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == IME_ACTION_DONE
- || event != null && event.getAction() == KeyEvent.ACTION_DOWN
- && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
- passwordField.requestFocus();
- return true;
- }
- return false;
- }
- });
-
- passwordField.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- if(getPassword().length() < 8) {
- updatePasswordError(getString(R.string.error_not_valid_password_user_message));
- } else {
- updatePasswordError(null);
- }
- }
- });
- passwordField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == IME_ACTION_DONE
- || event != null && event.getAction() == KeyEvent.ACTION_DOWN
- && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
- if (passwordVerificationField.getVisibility() == VISIBLE) {
- passwordVerificationField.requestFocus();
- } else {
- button.performClick();
- }
- return true;
- }
- return false;
- }
- });
-
- passwordVerificationField.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- if(getPassword().equals(getPasswordVerification())) {
- updateVerificationError(null);
- } else {
- updateVerificationError(getString(R.string.password_mismatch));
- }
- }
- });
- passwordVerificationField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
- if (actionId == IME_ACTION_DONE
- || event != null && event.getAction() == KeyEvent.ACTION_DOWN
- && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
- button.performClick();
- return true;
- }
- return false;
- }
- });
- }
-
- private void hideKeyboard() {
- InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
- if (imm != null) {
- imm.hideSoftInputFromWindow(passwordField.getWindowToken(), 0);
- }
- }
-
- private void handleReceivedErrors(Bundle arguments) {
- if (arguments.containsKey(CREDENTIAL_ERRORS.PASSWORD_INVALID_LENGTH.toString())) {
- updatePasswordError(getString(R.string.error_not_valid_password_user_message));
- } else if (arguments.containsKey(CREDENTIAL_ERRORS.RISEUP_WARNING.toString())) {
- userMessage.setVisibility(VISIBLE);
- userMessage.setText(R.string.login_riseup_warning);
- }
- if (arguments.containsKey(CREDENTIALS_USERNAME)) {
- String username = arguments.getString(CREDENTIALS_USERNAME);
- usernameField.setText(username);
- }
- if (arguments.containsKey(CREDENTIAL_ERRORS.USERNAME_MISSING.toString())) {
- updateUsernameError(getString(R.string.username_ask));
- }
- if (arguments.containsKey(USER_MESSAGE)) {
- String userMessageString = arguments.getString(USER_MESSAGE);
- try {
- userMessageString = new JSONArray(userMessageString).getString(0);
- } catch (JSONException e) {
- e.printStackTrace();
- }
-
- if (Build.VERSION.SDK_INT >= VERSION_CODES.N) {
- userMessage.setText(Html.fromHtml(userMessageString, Html.FROM_HTML_MODE_LEGACY));
- } else {
- userMessage.setText(Html.fromHtml(userMessageString));
- }
- Linkify.addLinks(userMessage, Linkify.ALL);
- userMessage.setMovementMethod(LinkMovementMethod.getInstance());
- userMessage.setVisibility(VISIBLE);
- } else if (userMessage.getVisibility() != GONE) {
- userMessage.setVisibility(GONE);
- }
-
- if (!usernameField.getText().toString().isEmpty() && passwordField.isFocusable())
- passwordField.requestFocus();
-
- mConfigState.setAction(SHOWING_FORM);
- hideProgressBar();
- }
-
- private void successfullyFinished(Provider handledProvider) {
- provider = handledProvider;
- Intent resultData = new Intent();
- resultData.putExtra(Provider.KEY, provider);
- setResult(RESULT_OK, resultData);
- finish();
- }
-
- //TODO: replace with EipSetupObserver
- public class ProviderAPIBroadcastReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- Log.d(TAG, "received Broadcast");
-
- String action = intent.getAction();
- if (action == null || !action.equalsIgnoreCase(BROADCAST_PROVIDER_API_EVENT)) {
- return;
- }
-
- int resultCode = intent.getIntExtra(BROADCAST_RESULT_CODE, RESULT_CANCELED);
- Bundle resultData = intent.getParcelableExtra(BROADCAST_RESULT_KEY);
- Provider handledProvider = resultData.getParcelable(PROVIDER_KEY);
-
- switch (resultCode) {
- case ProviderAPI.SUCCESSFUL_SIGNUP:
- String password = resultData.getString(CREDENTIALS_PASSWORD);
- String username = resultData.getString(CREDENTIALS_USERNAME);
- login(username, password);
- break;
- case ProviderAPI.SUCCESSFUL_LOGIN:
- downloadVpnCertificate(handledProvider);
- break;
- case ProviderAPI.FAILED_LOGIN:
- case ProviderAPI.FAILED_SIGNUP:
- handleReceivedErrors((Bundle) intent.getParcelableExtra(BROADCAST_RESULT_KEY));
- break;
-
- case ProviderAPI.INCORRECTLY_DOWNLOADED_VPN_CERTIFICATE:
- // error handling takes place in MainActivity
- case ProviderAPI.CORRECTLY_DOWNLOADED_VPN_CERTIFICATE:
- successfullyFinished(handledProvider);
- break;
- }
- }
- }
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderListBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderListBaseActivity.java
deleted file mode 100644
index eb9898b8..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderListBaseActivity.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/**
- * Copyright (c) 2017 LEAP Encryption Access Project and contributors
- * <p>
- * 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.
- * <p>
- * 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.
- * <p>
- * 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.providersetup.activities;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.widget.ListView;
-
-import androidx.annotation.NonNull;
-
-import com.pedrogomez.renderers.Renderer;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.inject.Inject;
-
-import butterknife.BindView;
-import butterknife.OnItemClick;
-import se.leap.bitmaskclient.R;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.providersetup.AddProviderActivity;
-import se.leap.bitmaskclient.providersetup.ProviderListActivity;
-import se.leap.bitmaskclient.providersetup.ProviderListAdapter;
-import se.leap.bitmaskclient.providersetup.ProviderRenderer;
-import se.leap.bitmaskclient.providersetup.ProviderRendererBuilder;
-
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_ADD_PROVIDER;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SHOW_FAILED_DIALOG;
-
-/**
- * abstract base Activity that builds and shows the list of known available providers.
- * The implementation of ProviderListBaseActivity differ in that they may or may not allow to bypass
- * secure download mechanisms including certificate validation.
- * <p/>
- * It also allows the user to enter custom providers with a button.
- *
- * @author parmegv
- * @author cyberta
- */
-
-public abstract class ProviderListBaseActivity extends ProviderSetupBaseActivity {
-
- @BindView(R.id.provider_list)
- protected ListView providerListView;
- @Inject
- protected ProviderListAdapter adapter;
-
- final public static String TAG = ProviderListActivity.class.getSimpleName();
- final protected static String EXTRAS_KEY_INVALID_URL = "INVALID_URL";
-
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setUpInitialUI();
- initProviderList();
- restoreState(savedInstanceState);
- }
-
- public abstract void retrySetUpProvider(@NonNull Provider provider);
-
- protected abstract void onItemSelectedLogic();
-
- private void initProviderList() {
- List<Renderer<Provider>> prototypes = new ArrayList<>();
- prototypes.add(new ProviderRenderer(this));
- ProviderRendererBuilder providerRendererBuilder = new ProviderRendererBuilder(prototypes);
- adapter = new ProviderListAdapter(getLayoutInflater(), providerRendererBuilder, getProviderManager());
- providerListView.setAdapter(adapter);
- }
-
- private void setUpInitialUI() {
- setContentView(R.layout.a_provider_list);
- setProviderHeaderText(R.string.setup_provider);
- hideProgressBar();
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_CODE_CONFIGURE_LEAP) {
- if (resultCode == RESULT_OK) {
- setResult(resultCode, data);
- finish();
- }
- } else if (requestCode == REQUEST_CODE_ADD_PROVIDER) {
- if (resultCode == RESULT_OK) {
- testNewURL = true;
- String newUrl = data.getStringExtra(AddProviderActivity.EXTRAS_KEY_NEW_URL);
- this.provider.setMainUrl(newUrl);
- showAndSelectProvider(newUrl);
- } else {
- cancelSettingUpProvider();
- }
- }
- }
-
- public void showAndSelectProvider(String newURL) {
- provider = new Provider(newURL);
- autoSelectProvider();
- }
-
- private void autoSelectProvider() {
- onItemSelectedLogic();
- showProgressBar();
- }
-
- // ------- ProviderSetupInterface ---v
- @Override
- public void handleProviderSetUp(Provider handledProvider) {
- this.provider = handledProvider;
- adapter.add(provider);
- adapter.saveProviders();
- if (provider.allowsAnonymous()) {
- //FIXME: providerApiBroadcastReceiver.getConfigState().putExtra(SERVICES_RETRIEVED, true); DEAD CODE???
- downloadVpnCertificate();
- } else {
- showProviderDetails();
- }
- }
-
- @Override
- public void handleCorrectlyDownloadedCertificate(Provider handledProvider) {
- this.provider = handledProvider;
- showProviderDetails();
- }
-
- @OnItemClick(R.id.provider_list)
- void onItemSelected(int position) {
- if (SETTING_UP_PROVIDER == getConfigState() ||
- SHOW_FAILED_DIALOG == getConfigState()) {
- return;
- }
-
- //TODO Code 2 pane view
- provider = adapter.getItem(position);
- if (provider != null && !provider.isDefault()) {
- //TODO Code 2 pane view
- providerConfigState = SETTING_UP_PROVIDER;
- showProgressBar();
- onItemSelectedLogic();
- } else {
- addAndSelectNewProvider();
- }
- }
-
- @Override
- public void onBackPressed() {
- if (SETTING_UP_PROVIDER == providerConfigState ||
- SHOW_FAILED_DIALOG == providerConfigState) {
- cancelSettingUpProvider();
- } else {
- super.onBackPressed();
- }
- }
-
- /**
- * Open the new provider dialog
- */
- public void addAndSelectNewProvider() {
- Intent intent = new Intent(this, AddProviderActivity.class);
- startActivityForResult(intent, REQUEST_CODE_ADD_PROVIDER);
- }
-
- /**
- * Open the new provider dialog
- */
- @Override
- public void addAndSelectNewProvider(String url) {
- testNewURL = false;
- Intent intent = new Intent(this, AddProviderActivity.class);
- intent.putExtra(EXTRAS_KEY_INVALID_URL, url);
- startActivityForResult(intent, REQUEST_CODE_ADD_PROVIDER);
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderSetupBaseActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderSetupBaseActivity.java
deleted file mode 100644
index e429f776..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/ProviderSetupBaseActivity.java
+++ /dev/null
@@ -1,256 +0,0 @@
-/**
- * Copyright (c) 2018 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.providersetup.activities;
-
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-import androidx.fragment.app.DialogFragment;
-import androidx.fragment.app.FragmentTransaction;
-import androidx.localbroadcastmanager.content.LocalBroadcastManager;
-
-import org.json.JSONException;
-import org.json.JSONObject;
-import org.torproject.jni.TorService;
-
-import se.leap.bitmaskclient.base.FragmentManagerEnhanced;
-import se.leap.bitmaskclient.base.models.Provider;
-import se.leap.bitmaskclient.providersetup.ProviderAPICommand;
-import se.leap.bitmaskclient.providersetup.ProviderApiSetupBroadcastReceiver;
-import se.leap.bitmaskclient.providersetup.ProviderDetailActivity;
-import se.leap.bitmaskclient.providersetup.ProviderManager;
-import se.leap.bitmaskclient.providersetup.ProviderSetupFailedDialog;
-import se.leap.bitmaskclient.providersetup.ProviderSetupInterface;
-import se.leap.bitmaskclient.tor.TorServiceCommand;
-import se.leap.bitmaskclient.tor.TorStatusObservable;
-
-import static se.leap.bitmaskclient.base.models.Constants.BROADCAST_PROVIDER_API_EVENT;
-import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_KEY;
-import static se.leap.bitmaskclient.base.models.Constants.REQUEST_CODE_CONFIGURE_LEAP;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.DOWNLOAD_VPN_CERTIFICATE;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.ERRORS;
-import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_PROVIDER_DETAILS;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.PENDING_SHOW_FAILED_DIALOG;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.PENDING_SHOW_PROVIDER_DETAILS;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.PROVIDER_NOT_SET;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SETTING_UP_PROVIDER;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SHOWING_PROVIDER_DETAILS;
-import static se.leap.bitmaskclient.providersetup.ProviderSetupInterface.ProviderConfigState.SHOW_FAILED_DIALOG;
-import static se.leap.bitmaskclient.tor.TorStatusObservable.TorStatus.OFF;
-
-/**
- * Created by cyberta on 19.08.18.
- */
-
-public abstract class ProviderSetupBaseActivity extends ConfigWizardBaseActivity implements ProviderSetupInterface, ProviderSetupFailedDialog.DownloadFailedDialogInterface {
- final public static String TAG = "ProviderSetupActivity";
- final private static String ACTIVITY_STATE = "ACTIVITY STATE";
- final private static String REASON_TO_FAIL = "REASON TO FAIL";
-
- protected ProviderSetupInterface.ProviderConfigState providerConfigState = PROVIDER_NOT_SET;
- private ProviderManager providerManager;
- private FragmentManagerEnhanced fragmentManager;
-
- private String reasonToFail;
- protected boolean testNewURL;
-
- private ProviderApiSetupBroadcastReceiver providerAPIBroadcastReceiver;
-
- @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());
- if (SETTING_UP_PROVIDER == providerConfigState) {
- showProgressBar();
- } else if (PENDING_SHOW_FAILED_DIALOG == providerConfigState) {
- showProgressBar();
- hideConnectionDetails();
- showDownloadFailedDialog();
- } else if (SHOW_FAILED_DIALOG == providerConfigState) {
- showProgressBar();
- hideConnectionDetails();
- } else if (SHOWING_PROVIDER_DETAILS == providerConfigState) {
- cancelSettingUpProvider(false);
- } else if (PENDING_SHOW_PROVIDER_DETAILS == providerConfigState) {
- showProviderDetails();
- }
- }
-
- @Override
- protected void onDestroy() {
- super.onDestroy();
- if (providerAPIBroadcastReceiver != null) {
- LocalBroadcastManager.getInstance(this).unregisterReceiver(providerAPIBroadcastReceiver);
- }
- providerAPIBroadcastReceiver = null;
- }
-
-
- @Override
- public void onSaveInstanceState(@NonNull Bundle outState) {
- outState.putString(ACTIVITY_STATE, providerConfigState.toString());
- outState.putString(REASON_TO_FAIL, reasonToFail);
-
- super.onSaveInstanceState(outState);
- }
-
- protected FragmentManagerEnhanced getFragmentManagerEnhanced() {
- return fragmentManager;
- }
-
- protected ProviderManager getProviderManager() {
- return providerManager;
- }
-
- protected void setProviderConfigState(ProviderConfigState state) {
- this.providerConfigState = state;
- }
-
- protected void setProvider(Provider provider) {
- this.provider = provider;
- }
-
- // --------- ProviderSetupInterface ---v
- @Override
- public Provider getProvider() {
- return provider;
- }
-
- @Override
- public ProviderConfigState getConfigState() {
- return providerConfigState;
- }
-
- @Override
- public void handleError(Bundle resultData) {
- reasonToFail = resultData.getString(ERRORS);
- showDownloadFailedDialog();
- }
-
- @Override
- public void handleIncorrectlyDownloadedCertificate() {
- cancelSettingUpProvider();
- setResult(RESULT_CANCELED, new Intent(getConfigState().toString()));
- }
-
- // -------- DownloadFailedDialogInterface ---v
- @Override
- public void cancelSettingUpProvider() {
- cancelSettingUpProvider(true);
- }
-
- @Override
- public void updateProviderDetails() {
- providerConfigState = SETTING_UP_PROVIDER;
- ProviderAPICommand.execute(this, UPDATE_PROVIDER_DETAILS, provider);
- }
-
- public void cancelSettingUpProvider(boolean stopTor) {
- if (stopTor && TorStatusObservable.getStatus() != OFF) {
- Log.d(TAG, "SHUTDOWN - cancelSettingUpProvider stopTor:" + stopTor);
- TorServiceCommand.stopTorServiceAsync(this);
- }
- providerConfigState = PROVIDER_NOT_SET;
- provider = null;
- hideProgressBar();
- }
-
- protected void restoreState(Bundle savedInstanceState) {
- super.restoreState(savedInstanceState);
- if (savedInstanceState == null) {
- return;
- }
- this.providerConfigState = ProviderSetupInterface.ProviderConfigState.valueOf(savedInstanceState.getString(ACTIVITY_STATE, PROVIDER_NOT_SET.toString()));
- if (savedInstanceState.containsKey(REASON_TO_FAIL)) {
- reasonToFail = savedInstanceState.getString(REASON_TO_FAIL);
- }
- }
-
- private void setUpProviderAPIResultReceiver() {
- providerAPIBroadcastReceiver = new ProviderApiSetupBroadcastReceiver(this);
-
- IntentFilter updateIntentFilter = new IntentFilter(BROADCAST_PROVIDER_API_EVENT);
- updateIntentFilter.addCategory(Intent.CATEGORY_DEFAULT);
- LocalBroadcastManager.getInstance(this).registerReceiver(providerAPIBroadcastReceiver, updateIntentFilter);
- }
-
- /**
- * Asks ProviderApiService to download an anonymous (anon) VPN certificate.
- */
- protected void downloadVpnCertificate() {
- ProviderAPICommand.execute(this, DOWNLOAD_VPN_CERTIFICATE, provider);
- }
-
- /**
- * Once selected a provider, this fragment offers the user to log in,
- * use it anonymously (if possible)
- * or cancel their selection pressing the back button.
- */
- public void showProviderDetails() {
- // show only if current activity is shown
- if (isActivityShowing &&
- providerConfigState != SHOWING_PROVIDER_DETAILS) {
- providerConfigState = SHOWING_PROVIDER_DETAILS;
- Intent intent = new Intent(this, ProviderDetailActivity.class);
- intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
- intent.putExtra(PROVIDER_KEY, provider);
- startActivityForResult(intent, REQUEST_CODE_CONFIGURE_LEAP);
- } else {
- providerConfigState = PENDING_SHOW_PROVIDER_DETAILS;
- }
- }
-
- /**
- * Shows an error dialog, if configuring of a provider failed.
- */
- public void showDownloadFailedDialog() {
- try {
- providerConfigState = SHOW_FAILED_DIALOG;
- hideConnectionDetails();
- FragmentTransaction fragmentTransaction = fragmentManager.removePreviousFragment(ProviderSetupFailedDialog.TAG);
- DialogFragment newFragment;
- try {
- JSONObject errorJson = new JSONObject(reasonToFail);
- newFragment = ProviderSetupFailedDialog.newInstance(provider, errorJson, testNewURL);
- } catch (JSONException e) {
- e.printStackTrace();
- newFragment = ProviderSetupFailedDialog.newInstance(provider, reasonToFail);
- } catch (NullPointerException e) {
- //reasonToFail was null
- return;
- }
- newFragment.show(fragmentTransaction, ProviderSetupFailedDialog.TAG);
- } catch (IllegalStateException e) {
- e.printStackTrace();
- providerConfigState = PENDING_SHOW_FAILED_DIALOG;
- }
- }
-
-}
diff --git a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SignupActivity.java b/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SignupActivity.java
deleted file mode 100644
index 16007a70..00000000
--- a/app/src/main/java/se/leap/bitmaskclient/providersetup/activities/SignupActivity.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Copyright (c) 2018 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.providersetup.activities;
-
-import android.os.Bundle;
-import androidx.annotation.Nullable;
-
-import butterknife.OnClick;
-import se.leap.bitmaskclient.R;
-
-import static android.view.View.VISIBLE;
-
-/**
- * Create an account with a provider
- */
-
-public class SignupActivity extends ProviderCredentialsBaseActivity {
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setProviderHeaderLogo(R.drawable.logo);
- setProviderHeaderText(R.string.create_profile);
-
- setProgressbarTitle(R.string.signing_up);
- setButtonText(R.string.signup_button);
-
- passwordVerificationField.setVisibility(VISIBLE);
- passwordVerificationError.setVisibility(VISIBLE);
- }
-
- @Override
- @OnClick(R.id.button)
- void handleButton() {
- super.handleButton();
- if (getPassword().equals(getPasswordVerification())) {
- signUp(getUsername(), getPassword());
- }
- }
-}