|
|
@ -60,8 +60,9 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
|
|
|
|
|
|
|
|
override fun onClick() { |
|
|
|
override fun onClick() { |
|
|
|
getActivity()?.let { |
|
|
|
getActivity()?.let { |
|
|
|
IconDialog().apply { |
|
|
|
val dialog = IconDialog().apply { |
|
|
|
val args = Bundle() |
|
|
|
val args = Bundle() |
|
|
|
|
|
|
|
args.putString("value", value) |
|
|
|
args.putCharSequenceArray("entries", entries) |
|
|
|
args.putCharSequenceArray("entries", entries) |
|
|
|
args.putCharSequenceArray("entryValues", entryValues) |
|
|
|
args.putCharSequenceArray("entryValues", entryValues) |
|
|
|
args.putCharSequenceArray("iconNames", iconNames) |
|
|
|
args.putCharSequenceArray("iconNames", iconNames) |
|
|
@ -69,7 +70,11 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
onChanged = { value -> |
|
|
|
onChanged = { value -> |
|
|
|
this@IconListPreference.value = value |
|
|
|
this@IconListPreference.value = value |
|
|
|
} |
|
|
|
} |
|
|
|
}.show(it.supportFragmentManager, "iconDialog") |
|
|
|
} |
|
|
|
|
|
|
|
it.supportFragmentManager |
|
|
|
|
|
|
|
.beginTransaction() |
|
|
|
|
|
|
|
.add(dialog, getFragmentTag()) |
|
|
|
|
|
|
|
.commitAllowingStateLoss() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -86,10 +91,14 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun getFragmentTag(): String { |
|
|
|
|
|
|
|
return "icon_$key" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class IconDialog : DialogFragment() { |
|
|
|
class IconDialog : DialogFragment() { |
|
|
|
|
|
|
|
|
|
|
|
var onChanged: ((value: String) -> Unit)? = null |
|
|
|
var onChanged: ((value: String) -> Unit)? = null |
|
|
|
|
|
|
|
var dialogValue: String? = null |
|
|
|
var dialogEntries: Array<CharSequence>? = null |
|
|
|
var dialogEntries: Array<CharSequence>? = null |
|
|
|
var dialogEntryValues: Array<CharSequence>? = null |
|
|
|
var dialogEntryValues: Array<CharSequence>? = null |
|
|
|
var dialogIconNames: Array<CharSequence>? = null |
|
|
|
var dialogIconNames: Array<CharSequence>? = null |
|
|
@ -119,6 +128,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
val adapter = Adapter(requireContext()) |
|
|
|
val adapter = Adapter(requireContext()) |
|
|
|
recycler_view.adapter = adapter |
|
|
|
recycler_view.adapter = adapter |
|
|
|
arguments?.let { |
|
|
|
arguments?.let { |
|
|
|
|
|
|
|
dialogValue = it.getString("value") |
|
|
|
dialogEntries = it.getCharSequenceArray("entries") |
|
|
|
dialogEntries = it.getCharSequenceArray("entries") |
|
|
|
dialogEntryValues = it.getCharSequenceArray("entryValues") |
|
|
|
dialogEntryValues = it.getCharSequenceArray("entryValues") |
|
|
|
dialogIconNames = it.getCharSequenceArray("iconNames") |
|
|
|
dialogIconNames = it.getCharSequenceArray("iconNames") |
|
|
@ -148,6 +158,7 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
val d = context.getCompatDrawable(resId) |
|
|
|
val d = context.getCompatDrawable(resId) |
|
|
|
icon.setImageDrawable(d) |
|
|
|
icon.setImageDrawable(d) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
label.isChecked = item.toString() == dialogValue |
|
|
|
onClick { |
|
|
|
onClick { |
|
|
|
onChanged?.invoke(item.toString()) |
|
|
|
onChanged?.invoke(item.toString()) |
|
|
|
this@IconDialog.dismiss() |
|
|
|
this@IconDialog.dismiss() |
|
|
|