diff options
Diffstat (limited to 'app/src')
7 files changed, 58 insertions, 55 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java index 72cca644..4e7bb6ab 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/GatewaySelectionFragment.java @@ -28,6 +28,7 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatTextView; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -44,20 +45,21 @@ import se.leap.bitmaskclient.base.MainActivity; import se.leap.bitmaskclient.base.models.Location; import se.leap.bitmaskclient.base.utils.PreferenceHelper; import se.leap.bitmaskclient.base.views.SelectLocationEntry; -import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipCommand; import se.leap.bitmaskclient.eip.EipStatus; import se.leap.bitmaskclient.eip.GatewaysManager; import static android.content.Context.MODE_PRIVATE; +import static android.view.View.GONE; +import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OBFS4; import static de.blinkt.openvpn.core.connection.Connection.TransportType.OPENVPN; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_DIALOG_FRAGMENT; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.models.Constants.LOCATION; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.models.Constants.USE_BRIDGES; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.base.utils.ViewHelper.setActionBarTitle; interface LocationListSelectionListener { @@ -76,6 +78,8 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca private EipStatus eipStatus; private SharedPreferences preferences; private Connection.TransportType selectedTransport; + private AppCompatTextView bridgesHint; + private AppCompatTextView disableBridges; public GatewaySelectionFragment() { // Required empty public constructor @@ -88,7 +92,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca eipStatus = EipStatus.getInstance(); eipStatus.addObserver(this); preferences = getContext().getSharedPreferences(SHARED_PREFERENCES, MODE_PRIVATE); - selectedTransport = PreferenceHelper.getUseBridges(preferences) ? OBFS4 : OPENVPN; + selectedTransport = getUseBridges(preferences) ? OBFS4 : OPENVPN; preferences.registerOnSharedPreferenceChangeListener(this); } @@ -104,6 +108,7 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca super.onViewCreated(view, savedInstanceState); initRecyclerView(); initRecommendedLocationEntry(); + initBridgesHint(view); setActionBarTitle(this, R.string.gateway_selection_title); } @@ -136,6 +141,16 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca updateRecommendedLocation(); } + private void initBridgesHint(@NonNull View view) { + bridgesHint = view.findViewById(R.id.manual_subtitle); + bridgesHint.setVisibility(getUseBridges(getContext()) ? VISIBLE : GONE); + disableBridges = view.findViewById(R.id.disable_bridges); + disableBridges.setVisibility(getUseBridges(getContext()) ? VISIBLE : GONE); + disableBridges.setOnClickListener(v -> { + useBridges(getContext(), false); + }); + } + private void updateRecommendedLocation() { Location location = new Location(); boolean isManualSelection = PreferenceHelper.getPreferredCity(getContext()) != null; @@ -174,22 +189,9 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca String name = location.getName(); if (location.supportsTransport(selectedTransport)) { startEipService(name); - } else { - locationListAdapter.unselectAll(); - askToChangeTransport(name); } } - private void askToChangeTransport(String name) { - Intent intent = new Intent(getContext(), MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(ACTION_SHOW_DIALOG_FRAGMENT); - intent.putExtra(EIP.ERRORID, EIP.EIPErrors.TRANSPORT_NOT_SUPPORTED.toString()); - intent.putExtra(EIP.ERRORS, getString(R.string.warning_bridges_not_supported, name)); - intent.putExtra(LOCATION, name); - startActivity(intent); - } - @Override public void update(Observable o, Object arg) { if (o instanceof EipStatus) { @@ -204,9 +206,12 @@ public class GatewaySelectionFragment extends Fragment implements Observer, Loca @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(USE_BRIDGES)) { - selectedTransport = PreferenceHelper.getUseBridges(sharedPreferences) ? OBFS4 : OPENVPN; + boolean showBridges = getUseBridges(sharedPreferences); + selectedTransport = showBridges ? OBFS4 : OPENVPN; gatewaysManager.updateTransport(selectedTransport); locationListAdapter.updateTransport(selectedTransport, gatewaysManager); + bridgesHint.setVisibility(showBridges ? VISIBLE : GONE); + disableBridges.setVisibility(showBridges ? VISIBLE : GONE); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java index f7805002..f1895307 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/MainActivityErrorDialog.java @@ -18,37 +18,32 @@ package se.leap.bitmaskclient.base.fragments; import android.app.Dialog; import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; import android.os.Bundle; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.DialogFragment; import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.DialogFragment; import org.json.JSONObject; import se.leap.bitmaskclient.R; -import se.leap.bitmaskclient.base.MainActivity; -import se.leap.bitmaskclient.base.utils.PreferenceHelper; +import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.eip.EIP; import se.leap.bitmaskclient.eip.EipCommand; -import se.leap.bitmaskclient.base.models.Provider; import se.leap.bitmaskclient.providersetup.ProviderAPICommand; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_DIALOG_FRAGMENT; -import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; -import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE; import static se.leap.bitmaskclient.R.string.warning_option_try_ovpn; import static se.leap.bitmaskclient.R.string.warning_option_try_pt; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.setPreferredCity; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.eip.EIP.EIPErrors.UNKNOWN; import static se.leap.bitmaskclient.eip.EIP.EIPErrors.valueOf; -import static se.leap.bitmaskclient.eip.EIP.ERRORS; import static se.leap.bitmaskclient.eip.EIP.ERRORID; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; -import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; +import static se.leap.bitmaskclient.eip.EIP.ERRORS; +import static se.leap.bitmaskclient.providersetup.ProviderAPI.UPDATE_INVALID_VPN_CERTIFICATE; /** * Implements an error dialog for the main activity. @@ -158,21 +153,6 @@ public class MainActivityErrorDialog extends DialogFragment { case ERROR_VPN_PREPARE: builder.setPositiveButton(android.R.string.ok, (dialog, which) -> { }); break; - case TRANSPORT_NOT_SUPPORTED: - - builder.setPositiveButton(R.string.option_different_location, (dialog, which) -> { }); - builder.setNegativeButton(R.string.option_disable_bridges, (dialog, which) -> { - PreferenceHelper.useBridges(applicationContext, false); - PreferenceHelper.setPreferredCity(applicationContext, args[0]); - - EipCommand.startVPN(applicationContext, false); - // at this point the gateway selection dialog is shown, let's switch to the main view - Intent intent = new Intent(getContext(), MainActivity.class); - intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); - intent.setAction(ACTION_SHOW_VPN_FRAGMENT); - startActivity(intent); - }); - break; default: break; } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java index 2a082579..3d4f93ff 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/SelectLocationEntry.java @@ -65,14 +65,19 @@ public class SelectLocationEntry extends LinearLayout { title.setText(text); title.setVisibility(text != null ? VISIBLE : GONE); } + public void setLocation(Location location, Connection.TransportType transportType) { - boolean valid = location.hasLocationInfo(); - locationText.setVisibility(valid ? VISIBLE : GONE); - locationIndicator.setVisibility(valid ? VISIBLE : GONE); - bridgesView.setVisibility(transportType == OBFS4 && location.supportsTransport(OBFS4) ? VISIBLE : GONE); + boolean hasData = location.hasLocationInfo(); + boolean supportsSelectedTransport = location.supportsTransport(transportType); + locationText.setVisibility(hasData ? VISIBLE : GONE); + locationIndicator.setVisibility(hasData ? VISIBLE : GONE); + bridgesView.setVisibility(transportType == OBFS4 && supportsSelectedTransport ? VISIBLE : GONE); locationText.setText(location.getName()); locationIndicator.setLoad(Load.getLoadByValue(location.getAverageLoad(transportType))); selectedView.setChecked(location.selected); + locationText.setEnabled(supportsSelectedTransport); + selectedView.setEnabled(supportsSelectedTransport); + setEnabled(!hasData || supportsSelectedTransport); } public void showDivider(boolean show) { diff --git a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java index a7e08bd7..4db8f0c2 100644 --- a/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java +++ b/app/src/main/java/se/leap/bitmaskclient/eip/EIP.java @@ -128,7 +128,6 @@ public final class EIP extends JobIntentService implements Observer { NO_MORE_GATEWAYS, ERROR_VPN_PREPARE, ERROR_INVALID_PROFILE, - TRANSPORT_NOT_SUPPORTED, } /** diff --git a/app/src/main/res/layout/f_gateway_selection.xml b/app/src/main/res/layout/f_gateway_selection.xml index 643ae988..8ab2b1c3 100644 --- a/app/src/main/res/layout/f_gateway_selection.xml +++ b/app/src/main/res/layout/f_gateway_selection.xml @@ -56,6 +56,21 @@ android:text="@string/gateway_selection_manually" android:layout_gravity="bottom" /> + <androidx.appcompat.widget.AppCompatTextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:id="@+id/manual_subtitle" + android:textAppearance="@style/TextAppearance.AppCompat.Small" + android:text="@string/hint_bridges" + + /> + <androidx.appcompat.widget.AppCompatTextView + android:id="@+id/disable_bridges" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:text="@string/option_disable_bridges" + android:textColor="@color/primary" + /> </LinearLayout> <androidx.recyclerview.widget.RecyclerView diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index df37b5ba..53ba5e8f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -190,6 +190,6 @@ <string name="vpn_settings">VPN settings</string> <string name="prefer_udp">Use UDP if available</string> <string name="prefer_udp_subtitle">UDP can be faster and better for streaming, but does not work for all networks.</string> - - + <string name="hint_bridges">Only locations supporting bridges are currently selectable.</string> + <string name="option_disable_bridges">Disable bridges</string> </resources> diff --git a/app/src/main/res/values/untranslatable.xml b/app/src/main/res/values/untranslatable.xml index ec795f57..8c478b33 100644 --- a/app/src/main/res/values/untranslatable.xml +++ b/app/src/main/res/values/untranslatable.xml @@ -48,7 +48,6 @@ <string name="warning_no_more_gateways_manual_gw_selection" translatable="false">%1$s could not connect to %2$s. Do you want to try to connect automatically with best location?</string> <string name="warning_option_try_best" translatable="false">Try best location</string> <string name="warning_bridges_not_supported" translatable="false">%1$s doesn\'t support bridges to circumvent VPN filtering. Do you want to choose a different location or disable bridges?</string> - <string name="option_disable_bridges" translatable="false">Disable bridges</string> <string name="option_different_location" translatable="false">Choose different location</string> <string name="eip_state_insecure" translatable="false">Connection Insecure</string> <string name="eip_state_connected_recommended" translatable="false">You are connected to the recommended location</string> |