From f1febcf9b626a97a5aa75029b3ba90c26e468b2f 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 Signed-off-by: Jason A. Donenfeld --- .../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') 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