ConfigList: Poor man's switch

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Samuel Holland 2017-11-24 23:44:18 -06:00
parent 3233855630
commit f1febcf9b6
2 changed files with 6 additions and 8 deletions

View File

@ -241,9 +241,9 @@ public class VpnService extends Service
@Override @Override
protected void onPostExecute(final Boolean result) { protected void onPostExecute(final Boolean result) {
config.setIsEnabled(!result);
if (!result) if (!result)
return; return;
config.setIsEnabled(false);
enabledConfigs.remove(config.getName()); enabledConfigs.remove(config.getName());
preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply(); preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply();
if (config.getName().equals(primaryName)) if (config.getName().equals(primaryName))
@ -267,9 +267,9 @@ public class VpnService extends Service
@Override @Override
protected void onPostExecute(final Boolean result) { protected void onPostExecute(final Boolean result) {
config.setIsEnabled(result);
if (!result) if (!result)
return; return;
config.setIsEnabled(true);
enabledConfigs.add(config.getName()); enabledConfigs.add(config.getName());
preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply(); preferences.edit().putStringSet(KEY_ENABLED_CONFIGS, enabledConfigs).apply();
if (config.getName().equals(primaryName)) if (config.getName().equals(primaryName))

View File

@ -20,6 +20,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/list_item_background_anim" android:background="@drawable/list_item_background_anim"
android:descendantFocusability="blocksDescendants"
android:padding="16dp"> android:padding="16dp">
<TextView <TextView
@ -34,16 +35,13 @@
android:text="@{key}" android:text="@{key}"
android:textStyle="@{item.primary ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT}" /> android:textStyle="@{item.primary ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT}" />
<TextView <Switch
android:id="@+id/config_switch" android:id="@+id/config_switch"
style="?android:attr/textAppearanceButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/config_name" android:layout_alignBaseline="@+id/config_name"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:gravity="center_vertical" android:checked="@{item.enabled}"
android:onClick="@{() -> item.enabled ? VpnService.instance.disable(item.name) : VpnService.instance.enable(item.name)}" android:onCheckedChanged="@{(v, checked) -> checked ? VpnService.instance.enable(item.name) : VpnService.instance.disable(item.name)}" />
android:text="@string/toggle"
android:textColor="@{item.enabled ? @android:color/holo_green_dark : @android:color/holo_red_dark}" />
</RelativeLayout> </RelativeLayout>
</layout> </layout>