From dc7363845b3edacc5bac7be85eb7fc63790e97af Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Fri, 24 Nov 2017 23:44:18 -0600 Subject: ConfigList: Poor man's switch --- .../main/java/com/wireguard/android/backends/VpnService.java | 4 ++-- app/src/main/res/layout/config_list_item.xml | 10 ++++------ 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'app/src/main') diff --git a/app/src/main/java/com/wireguard/android/backends/VpnService.java b/app/src/main/java/com/wireguard/android/backends/VpnService.java index 25eb4ade..275b719c 100644 --- a/app/src/main/java/com/wireguard/android/backends/VpnService.java +++ b/app/src/main/java/com/wireguard/android/backends/VpnService.java @@ -241,9 +241,9 @@ public class VpnService extends Service @Override protected void onPostExecute(final Boolean result) { + config.setIsEnabled(!result); if (!result) return; - config.setIsEnabled(false); enabledConfigs.remove(config.getName()); preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply(); if (config.getName().equals(primaryName)) @@ -267,9 +267,9 @@ public class VpnService extends Service @Override protected void onPostExecute(final Boolean result) { + config.setIsEnabled(result); if (!result) return; - config.setIsEnabled(true); enabledConfigs.add(config.getName()); preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply(); if (config.getName().equals(primaryName)) diff --git a/app/src/main/res/layout/config_list_item.xml b/app/src/main/res/layout/config_list_item.xml index 578db833..87380dee 100644 --- a/app/src/main/res/layout/config_list_item.xml +++ b/app/src/main/res/layout/config_list_item.xml @@ -20,6 +20,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/list_item_background_anim" + android:descendantFocusability="blocksDescendants" android:padding="16dp"> - + android:checked="@{item.enabled}" + android:onCheckedChanged="@{(v, checked) -> checked ? VpnService.instance.enable(item.name) : VpnService.instance.disable(item.name)}" /> -- cgit v1.2.3