From 04153a386980960ca5d00a604086271cd3b37c8e Mon Sep 17 00:00:00 2001 From: Taylor Kline Date: Sun, 2 Apr 2017 22:20:03 -0500 Subject: [PATCH] Grey 'LED blink pattern' when LED Color is None Add BooleanListPreference to allow pref_led_blink to depend on pref_led_color being non-None. Closes #6480 --- res/xml/preferences_notifications.xml | 4 +- .../preferences/BooleanListPreference.java | 58 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 src/org/thoughtcrime/securesms/preferences/BooleanListPreference.java diff --git a/res/xml/preferences_notifications.xml b/res/xml/preferences_notifications.xml index e71e6b7220..cf121de691 100644 --- a/res/xml/preferences_notifications.xml +++ b/res/xml/preferences_notifications.xml @@ -19,7 +19,7 @@ android:title="@string/preferences__vibrate" android:summary="@string/preferences__also_vibrate_when_notified" /> - diff --git a/src/org/thoughtcrime/securesms/preferences/BooleanListPreference.java b/src/org/thoughtcrime/securesms/preferences/BooleanListPreference.java new file mode 100644 index 0000000000..6a7ae1e81a --- /dev/null +++ b/src/org/thoughtcrime/securesms/preferences/BooleanListPreference.java @@ -0,0 +1,58 @@ +/** + * Copyright (C) 2017 Whisper Systems + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.thoughtcrime.securesms.preferences; + +import android.content.Context; +import android.preference.ListPreference; +import android.util.AttributeSet; + +import org.thoughtcrime.securesms.R; + +/** + * List preference that disables dependents when set to "none", similar to a CheckBoxPreference. + * + * @author Taylor Kline + */ + +public class BooleanListPreference extends ListPreference { + + public BooleanListPreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public BooleanListPreference(Context context) { + super(context); + } + + @Override + public void setValue(String value) { + CharSequence oldEntry = getEntry(); + super.setValue(value); + CharSequence newEntry = getEntry(); + if (oldEntry != newEntry) { + notifyDependencyChange(shouldDisableDependents()); + } + } + + @Override + public boolean shouldDisableDependents() { + CharSequence newEntry = getEntry(); + String noneEntry = getContext().getString(R.string.preferences__none); + boolean shouldDisable = newEntry.equals(noneEntry); + return shouldDisable || super.shouldDisableDependents(); + } +}