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" /> - <ListPreference + <org.thoughtcrime.securesms.preferences.BooleanListPreference android:key="pref_led_color" android:defaultValue="blue" android:title="@string/preferences__led_color" @@ -31,7 +31,7 @@ android:key="pref_led_blink" android:defaultValue="500,2000" android:title="@string/preferences__pref_led_blink_title" - android:dependency="pref_key_enable_notifications" + android:dependency="pref_led_color" android:entries="@array/pref_led_blink_pattern_entries" android:entryValues="@array/pref_led_blink_pattern_values" /> 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 <http://www.gnu.org/licenses/>. + */ +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(); + } +}