# HG changeset patch # User Da Risk # Date 1669758805 14400 # Node ID 45a1084ed99ca1c676b4a5880d3427c4781a3f8a # Parent ab8851704ae740e6d89be426770ac1111af28bbc geekdroid: remove deprecated PreferenceSummaryBinder diff -r ab8851704ae7 -r 45a1084ed99c geekdroid/src/main/java/com/geekorum/geekdroid/preferences/PreferenceSummaryBinder.java --- a/geekdroid/src/main/java/com/geekorum/geekdroid/preferences/PreferenceSummaryBinder.java Tue Nov 29 17:48:50 2022 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -/* - * Geekdroid is a utility library for development on the Android - * Platform. - * - * Copyright (C) 2017-2022 by Frederic-Charles Barthelery. - * - * This file is part of Geekdroid. - * - * Geekdroid 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. - * - * Geekdroid 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 Geekdroid. If not, see . - */ -package com.geekorum.geekdroid.preferences; - -import androidx.preference.ListPreference; -import androidx.preference.Preference; -import androidx.preference.PreferenceManager; - -/** - * Helper class to set the summary of an {@link android.preference.Preference} to its actual value. - * @deprecated use androidx.preference.Preference.SummaryProvider - */ -@Deprecated -public class PreferenceSummaryBinder implements Preference.OnPreferenceChangeListener { - - /** - * A preference value change listener that updates the preference's summary - * to reflect its new value. - */ - @Override - public boolean onPreferenceChange(Preference preference, Object value) { - String stringValue = value.toString(); - - if (preference instanceof ListPreference) { - setListPreferenceSummary(preference, stringValue); - } else { - setGenericPreferenceSummary(preference, stringValue); - } - return true; - } - - private void setGenericPreferenceSummary(Preference preference, String stringValue) { - // For all other preferences, set the summary to the value's - // simple string representation. - preference.setSummary(stringValue); - } - - private void setListPreferenceSummary(Preference preference, String stringValue) { - // For list preferences, look up the correct display value in - // the preference's 'entries' list. - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); - - // Set the summary to reflect the new value. - preference.setSummary( - index >= 0 - ? listPreference.getEntries()[index] - : null); - } - - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - * - */ - public void bindPreferenceSummaryToValue(Preference preference) { - // Set the listener to watch for value changes. - preference.setOnPreferenceChangeListener(this); - - // Trigger the listener immediately with the preference's - // current value. - onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.getContext()) - .getString(preference.getKey(), "")); - } - - -} diff -r ab8851704ae7 -r 45a1084ed99c geekdroid/src/main/java/com/geekorum/geekdroid/preferences/RingtonePreferenceSummaryBinder.kt --- a/geekdroid/src/main/java/com/geekorum/geekdroid/preferences/RingtonePreferenceSummaryBinder.kt Tue Nov 29 17:48:50 2022 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -/* - * Geekdroid is a utility library for development on the Android - * Platform. - * - * Copyright (C) 2017-2022 by Frederic-Charles Barthelery. - * - * This file is part of Geekdroid. - * - * Geekdroid 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. - * - * Geekdroid 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 Geekdroid. If not, see . - */ -package com.geekorum.geekdroid.preferences - -import android.media.Ringtone -import android.media.RingtoneManager -import android.preference.Preference -import android.preference.RingtonePreference -import androidx.core.net.toUri -import androidx.preference.PreferenceManager -import com.geekorum.geekdroid.R - -/** - * Helper class to set the summary of an [android.preference.RingtonePreference] to its actual value. - * @deprecated use androidx.preference.Preference.SummaryProvider - */ -@Deprecated("Use androidx.preference.Preference.SummaryProvider") -class RingtonePreferenceSummaryBinder : Preference.OnPreferenceChangeListener { - override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { - val stringValue = newValue.toString() - - when (preference) { - is RingtonePreference -> setRingtonePreferenceSummary(preference, stringValue) - } - return true - } - - private fun setRingtonePreferenceSummary(preference: Preference, stringValue: String) { - val summary = when { - // Empty values correspond to 'silent' (no ringtone). - stringValue.isEmpty() -> preference.context.getString(R.string.geekdroid_pref_ringtone_silent) - else -> { - val ringtone: Ringtone? = RingtoneManager.getRingtone(preference.context, stringValue.toUri()) - ringtone?.getTitle(preference.context) - } - } - preference.summary = summary - } - - /** - * Binds a preference's summary to its value. More specifically, when the - * preference's value is changed, its summary (line of text below the - * preference title) is updated to reflect the value. The summary is also - * immediately updated upon calling this method. The exact display format is - * dependent on the type of preference. - * - */ - fun bindPreferenceSummaryToValue(preference: Preference) { - // Set the listener to watch for value changes. - preference.onPreferenceChangeListener = this - - // Trigger the listener immediately with the preference's - // current value. - onPreferenceChange(preference, - PreferenceManager - .getDefaultSharedPreferences(preference.context) - .getString(preference.key, "")!!) - } - -}