Fix option selection persistence
This commit is contained in:
parent
35bf805202
commit
0d62d35ae3
5 changed files with 28 additions and 16 deletions
|
@ -23,8 +23,9 @@ import androidx.fragment.app.DialogFragment
|
||||||
import androidx.preference.ListPreference
|
import androidx.preference.ListPreference
|
||||||
import androidx.preference.Preference
|
import androidx.preference.Preference
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import code.name.monkey.appthemehelper.ThemeStore
|
|
||||||
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
|
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
|
||||||
|
import code.name.monkey.appthemehelper.util.ATHUtil
|
||||||
|
import code.name.monkey.retromusic.R
|
||||||
import code.name.monkey.retromusic.preferences.*
|
import code.name.monkey.retromusic.preferences.*
|
||||||
import code.name.monkey.retromusic.util.NavigationUtil
|
import code.name.monkey.retromusic.util.NavigationUtil
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
setDivider(ColorDrawable(Color.TRANSPARENT))
|
setDivider(ColorDrawable(Color.TRANSPARENT))
|
||||||
listView.setBackgroundColor(ThemeStore.primaryColor(requireContext()))
|
listView.setBackgroundColor(ATHUtil.resolveColor(requireContext(), R.attr.colorPrimary))
|
||||||
listView.overScrollMode = View.OVER_SCROLL_NEVER
|
listView.overScrollMode = View.OVER_SCROLL_NEVER
|
||||||
listView.setPadding(0, 0, 0, 0)
|
listView.setPadding(0, 0, 0, 0)
|
||||||
listView.setPaddingRelative(0, 0, 0, 0)
|
listView.setPaddingRelative(0, 0, 0, 0)
|
||||||
|
@ -73,7 +74,6 @@ abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
|
||||||
is NowPlayingScreenPreference -> NowPlayingScreenPreferenceDialog.newInstance(preference.key)
|
is NowPlayingScreenPreference -> NowPlayingScreenPreferenceDialog.newInstance(preference.key)
|
||||||
is AlbumCoverStylePreference -> AlbumCoverStylePreferenceDialog.newInstance(preference.key)
|
is AlbumCoverStylePreference -> AlbumCoverStylePreferenceDialog.newInstance(preference.key)
|
||||||
is MaterialListPreference -> {
|
is MaterialListPreference -> {
|
||||||
preference.entries
|
|
||||||
MaterialListPreferenceDialog.newInstance(preference)
|
MaterialListPreferenceDialog.newInstance(preference)
|
||||||
}
|
}
|
||||||
is BlacklistPreference -> BlacklistPreferenceDialog.newInstance()
|
is BlacklistPreference -> BlacklistPreferenceDialog.newInstance()
|
||||||
|
|
|
@ -76,18 +76,25 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
|
||||||
|
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
val materialListPreference = preference as MaterialListPreference
|
val materialListPreference = preference as MaterialListPreference
|
||||||
position = materialListPreference.findIndexOfValue(materialListPreference.value)
|
|
||||||
|
|
||||||
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
|
val entries = arguments?.getStringArrayList(EXTRA_ENTRIES)
|
||||||
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
|
val entriesValues = arguments?.getStringArrayList(EXTRA_ENTRIES_VALUES)
|
||||||
|
val position: Int = arguments?.getInt(EXTRA_POSITION) ?: 0
|
||||||
materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT))
|
materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT))
|
||||||
.title(text = materialListPreference.title.toString())
|
.title(text = materialListPreference.title.toString())
|
||||||
.positiveButton(R.string.set)
|
.positiveButton(R.string.set)
|
||||||
.cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
|
.cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner)
|
||||||
.listItemsSingleChoice(items = entries, initialSelection = position, waitForPositiveButton = true) { _, index, _ ->
|
.listItemsSingleChoice(items = entries, initialSelection = position, waitForPositiveButton = true) { _, index, _ ->
|
||||||
materialListPreference.callChangeListener(entriesValues!![index])
|
entriesValues?.let {
|
||||||
materialListPreference.setCustomValue(entriesValues[index])
|
materialListPreference.callChangeListener(it[index])
|
||||||
materialListPreference.summary = entries!![index]
|
materialListPreference.setCustomValue(it[index])
|
||||||
|
}
|
||||||
|
entries?.let {
|
||||||
|
materialListPreference.summary = it[index]
|
||||||
|
val value = materialListPreference.entryValues[index].toString()
|
||||||
|
if (materialListPreference.callChangeListener(value)) {
|
||||||
|
materialListPreference.value = value
|
||||||
|
}
|
||||||
|
}
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
return materialDialog
|
return materialDialog
|
||||||
|
@ -107,18 +114,22 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var position = 0
|
|
||||||
private const val EXTRA_KEY = "key"
|
private const val EXTRA_KEY = "key"
|
||||||
private const val EXTRA_TITLE = "title"
|
private const val EXTRA_TITLE = "title"
|
||||||
|
private const val EXTRA_POSITION = "position"
|
||||||
private const val EXTRA_ENTRIES = "extra_entries"
|
private const val EXTRA_ENTRIES = "extra_entries"
|
||||||
private const val EXTRA_ENTRIES_VALUES = "extra_entries_values"
|
private const val EXTRA_ENTRIES_VALUES = "extra_entries_values"
|
||||||
|
|
||||||
fun newInstance(listPreference: ListPreference): MaterialListPreferenceDialog {
|
fun newInstance(listPreference: ListPreference): MaterialListPreferenceDialog {
|
||||||
val entries = listPreference.entries.toList() as ArrayList<String>
|
val entries = listPreference.entries.toList() as ArrayList<String>
|
||||||
val entriesValues = listPreference.entryValues.toList() as ArrayList<String>
|
val entriesValues = listPreference.entryValues.toList() as ArrayList<String>
|
||||||
|
println("List value: ${listPreference.value}")
|
||||||
|
val position = listPreference.findIndexOfValue(listPreference.value)
|
||||||
val args = Bundle()
|
val args = Bundle()
|
||||||
args.putString(EXTRA_KEY, listPreference.key)
|
args.putString(ARG_KEY, listPreference.key)
|
||||||
args.putString(EXTRA_TITLE, listPreference.title.toString())
|
args.putString(EXTRA_TITLE, listPreference.title.toString())
|
||||||
|
args.putInt(EXTRA_POSITION, position)
|
||||||
args.putStringArrayList(EXTRA_ENTRIES, entries)
|
args.putStringArrayList(EXTRA_ENTRIES, entries)
|
||||||
args.putStringArrayList(EXTRA_ENTRIES_VALUES, entriesValues)
|
args.putStringArrayList(EXTRA_ENTRIES_VALUES, entriesValues)
|
||||||
val fragment = MaterialListPreferenceDialog()
|
val fragment = MaterialListPreferenceDialog()
|
||||||
|
|
|
@ -792,7 +792,7 @@ public final class PreferenceUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
@LayoutRes
|
@LayoutRes
|
||||||
public int getHomeGridStyle(Context context) {
|
public int getHomeGridStyle(@NonNull Context context) {
|
||||||
int pos = Integer.parseInt(mPreferences.getString(HOME_ARTIST_GRID_STYLE, "0"));
|
int pos = Integer.parseInt(mPreferences.getString(HOME_ARTIST_GRID_STYLE, "0"));
|
||||||
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_home_grid_style_layout);
|
TypedArray typedArray = context.getResources().obtainTypedArray(R.array.pref_home_grid_style_layout);
|
||||||
int layoutRes = typedArray.getResourceId(pos, -1);
|
int layoutRes = typedArray.getResourceId(pos, -1);
|
||||||
|
|
|
@ -34,5 +34,6 @@ dependencies {
|
||||||
implementation 'com.afollestad.material-dialogs:core:3.1.1'
|
implementation 'com.afollestad.material-dialogs:core:3.1.1'
|
||||||
implementation 'com.afollestad.material-dialogs:input:3.1.1'
|
implementation 'com.afollestad.material-dialogs:input:3.1.1'
|
||||||
implementation 'com.afollestad.material-dialogs:color:3.1.1'
|
implementation 'com.afollestad.material-dialogs:color:3.1.1'
|
||||||
|
implementation 'com.afollestad.material-dialogs:bottomsheets:3.1.1'
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,17 +27,17 @@ import code.name.monkey.appthemehelper.common.prefs.supportv7.dialogs.ATEPrefere
|
||||||
*/
|
*/
|
||||||
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
|
abstract class ATEPreferenceFragmentCompat : PreferenceFragmentCompat() {
|
||||||
override fun onDisplayPreferenceDialog(preference: Preference) {
|
override fun onDisplayPreferenceDialog(preference: Preference) {
|
||||||
if (callbackFragment is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
|
if (callbackFragment is OnPreferenceDisplayDialogCallback) {
|
||||||
(callbackFragment as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
(callbackFragment as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activity is PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback) {
|
if (activity is OnPreferenceDisplayDialogCallback) {
|
||||||
(activity as PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
(activity as OnPreferenceDisplayDialogCallback).onPreferenceDisplayDialog(this, preference)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fragmentManager!!.findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
|
if (fragmentManager?.findFragmentByTag("android.support.v7.preference.PreferenceFragment.DIALOG") == null) {
|
||||||
val dialogFragment = onCreatePreferenceDialog(preference)
|
val dialogFragment = onCreatePreferenceDialog(preference)
|
||||||
|
|
||||||
if (dialogFragment != null) {
|
if (dialogFragment != null) {
|
||||||
|
|
Loading…
Reference in a new issue