From 299dee25b134805114e8a9580716607bd338f30b Mon Sep 17 00:00:00 2001 From: cyBerta Date: Sat, 27 Mar 2021 15:44:57 +0100 Subject: disable 'turn on' button if automatic gateway selection is disabled but no location is manually selected --- .../bitmaskclient/base/fragments/GatewaySelectionFragment.java | 8 ++++++++ .../java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java | 4 ++++ 2 files changed, 12 insertions(+) (limited to 'app/src/main') 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 b7d5831c..30a167fc 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 @@ -54,6 +54,7 @@ import static android.content.Context.MODE_PRIVATE; import static android.view.View.INVISIBLE; import static android.view.View.VISIBLE; import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; +import static se.leap.bitmaskclient.base.models.Constants.PREFERRED_CITY; import static se.leap.bitmaskclient.base.models.Constants.SHARED_PREFERENCES; import static se.leap.bitmaskclient.base.models.Constants.USE_PLUGGABLE_TRANSPORTS; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferredCity; @@ -133,6 +134,7 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen PreferenceHelper.setPreferredCity(getContext(), null); locationListAdapter.resetSelection(); } + setVpnButtonState(); }); } @@ -154,12 +156,18 @@ public class GatewaySelectionFragment extends Fragment implements SharedPreferen } else { vpnButton.setText(R.string.reconnect); } + vpnButton.setEnabled( + (locationListAdapter.selectedLocation != null && locationListAdapter.selectedLocation.selected) || + autoSelectionSwitch.isChecked()); } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (USE_PLUGGABLE_TRANSPORTS.equals(key)) { locationListAdapter.updateData(gatewaysManager.getGatewayLocations()); + setVpnButtonState(); + } else if (PREFERRED_CITY.equals(key)) { + setVpnButtonState(); } } diff --git a/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java b/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java index 628b4c15..b6d72ab6 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/views/IconSwitchEntry.java @@ -131,6 +131,10 @@ public class IconSwitchEntry extends LinearLayout { switchView.setOnCheckedChangeListener(checkedChangeListener); } + public boolean isChecked() { + return switchView.isChecked(); + } + @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); -- cgit v1.2.3