diff options
author | cyBerta <cyberta@riseup.net> | 2021-11-25 12:23:04 +0100 |
---|---|---|
committer | cyBerta <cyberta@riseup.net> | 2021-11-25 12:23:04 +0100 |
commit | 0ccec2d3bd7c7f890f7b651110ea10a8933eab29 (patch) | |
tree | 6809b31be22162523a187ad65b2d18048b7e2e0f /app/src/main/java/se/leap/bitmaskclient/base | |
parent | dcee5f2fa1dc67e5b08223db3441da8bd38e8b20 (diff) |
implement UI, logic and test for prefer UDP preferences
Diffstat (limited to 'app/src/main/java/se/leap/bitmaskclient/base')
3 files changed, 27 insertions, 2 deletions
diff --git a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java index ed1e8b6d..87c64a89 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/fragments/SettingsFragment.java @@ -34,10 +34,12 @@ import static se.leap.bitmaskclient.base.MainActivity.ACTION_SHOW_VPN_FRAGMENT; 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.models.Constants.USE_IPv6_FIREWALL; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getPreferUDP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getShowAlwaysOnDialog; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseBridges; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.getUseSnowflake; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.hasSnowflakePrefs; +import static se.leap.bitmaskclient.base.utils.PreferenceHelper.preferUDP; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useBridges; import static se.leap.bitmaskclient.base.utils.PreferenceHelper.useSnowflake; @@ -63,10 +65,11 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh View view = inflater.inflate(R.layout.f_settings, container, false); initAlwaysOnVpnEntry(view); initExcludeAppsEntry(view); - initFirewallEntry(view); - initTetheringEntry(view); + initPreferUDPEntry(view); initUseBridgesEntry(view); initUseSnowflakeEntry(view); + initFirewallEntry(view); + initTetheringEntry(view); return view; } @@ -126,6 +129,18 @@ public class SettingsFragment extends Fragment implements SharedPreferences.OnSh } } + private void initPreferUDPEntry(View rootView) { + IconSwitchEntry useSnowflake = rootView.findViewById(R.id.prefer_udp); + useSnowflake.setVisibility(VISIBLE); + useSnowflake.setChecked(getPreferUDP(getContext())); + useSnowflake.setOnCheckedChangeListener((buttonView, isChecked) -> { + if (!buttonView.isPressed()) { + return; + } + preferUDP(getContext(), isChecked); + }); + } + private void initExcludeAppsEntry(View rootView) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { IconTextEntry excludeApps = rootView.findViewById(R.id.exclude_apps); diff --git a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java index 016a8563..468b1b01 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/models/Constants.java @@ -42,6 +42,7 @@ public interface Constants { String LAST_UPDATE_CHECK = "last_update_check"; String PREFERRED_CITY = "preferred_city"; String USE_SNOWFLAKE = "use_snowflake"; + String PREFER_UDP = "prefer_UDP"; ////////////////////////////////////////////// @@ -163,6 +164,7 @@ public interface Constants { String REMOTE = "remote"; String PORTS = "ports"; String PROTOCOLS = "protocols"; + String UDP = "udp"; String CAPABILITIES = "capabilities"; String TRANSPORT = "transport"; String TYPE = "type"; diff --git a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java index 515ec282..fe9100cb 100644 --- a/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java +++ b/app/src/main/java/se/leap/bitmaskclient/base/utils/PreferenceHelper.java @@ -29,6 +29,7 @@ import static se.leap.bitmaskclient.base.models.Constants.EXCLUDED_APPS; import static se.leap.bitmaskclient.base.models.Constants.LAST_UPDATE_CHECK; import static se.leap.bitmaskclient.base.models.Constants.LAST_USED_PROFILE; import static se.leap.bitmaskclient.base.models.Constants.PREFERRED_CITY; +import static se.leap.bitmaskclient.base.models.Constants.PREFER_UDP; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_CONFIGURED; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_EIP_DEFINITION; import static se.leap.bitmaskclient.base.models.Constants.PROVIDER_PRIVATE_KEY; @@ -145,6 +146,13 @@ public class PreferenceHelper { return getBoolean(context, RESTART_ON_UPDATE, false); } + public static boolean getPreferUDP(Context context) { + return getBoolean(context, PREFER_UDP, false); + } + + public static void preferUDP(Context context, boolean prefer) { + putBoolean(context, PREFER_UDP, prefer); + } public static boolean getUseBridges(SharedPreferences preferences) { return preferences.getBoolean(USE_BRIDGES, false); |