|
|
|
@ -85,22 +85,22 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
|
} |
|
|
|
|
return null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class IconDialog : DialogFragment() { |
|
|
|
|
|
|
|
|
|
class IconDialog : DialogFragment() { |
|
|
|
|
|
|
|
|
|
var onChanged: ((value: String) -> Unit)? = null |
|
|
|
|
var entries: Array<CharSequence>? = null |
|
|
|
|
var entryValues: Array<CharSequence>? = null |
|
|
|
|
var iconNames: Array<CharSequence>? = null |
|
|
|
|
var dialogEntries: Array<CharSequence>? = null |
|
|
|
|
var dialogEntryValues: Array<CharSequence>? = null |
|
|
|
|
var dialogIconNames: Array<CharSequence>? = null |
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
|
super.onStart() |
|
|
|
|
val dm = DisplayMetrics() |
|
|
|
|
activity?.windowManager?.defaultDisplay?.getMetrics(dm) |
|
|
|
|
dialog?.window?.setLayout( |
|
|
|
|
(dm.widthPixels * 0.9).toInt(), |
|
|
|
|
(dm.heightPixels * 0.9).toInt() |
|
|
|
|
(dm.widthPixels * 0.8).toInt(), |
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -119,10 +119,10 @@ class IconDialog : DialogFragment() { |
|
|
|
|
val adapter = Adapter(requireContext()) |
|
|
|
|
recycler_view.adapter = adapter |
|
|
|
|
arguments?.let { |
|
|
|
|
entries = it.getCharSequenceArray("entries") |
|
|
|
|
entryValues = it.getCharSequenceArray("entryValues") |
|
|
|
|
iconNames = it.getCharSequenceArray("iconNames") |
|
|
|
|
entryValues?.let { values -> |
|
|
|
|
dialogEntries = it.getCharSequenceArray("entries") |
|
|
|
|
dialogEntryValues = it.getCharSequenceArray("entryValues") |
|
|
|
|
dialogIconNames = it.getCharSequenceArray("iconNames") |
|
|
|
|
dialogEntryValues?.let { values -> |
|
|
|
|
adapter.setItems(values.toList()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -139,10 +139,10 @@ class IconDialog : DialogFragment() { |
|
|
|
|
) { |
|
|
|
|
with(holder.itemView) { |
|
|
|
|
val index = findIndexOfValue(item.toString()) |
|
|
|
|
entries?.let { |
|
|
|
|
dialogEntries?.let { |
|
|
|
|
label.text = it[index] |
|
|
|
|
} |
|
|
|
|
iconNames?.let { |
|
|
|
|
dialogIconNames?.let { |
|
|
|
|
val resId = context.resources |
|
|
|
|
.getIdentifier(it[index].toString(), "mipmap", context.packageName) |
|
|
|
|
val d = context.getCompatDrawable(resId) |
|
|
|
@ -150,12 +150,13 @@ class IconDialog : DialogFragment() { |
|
|
|
|
} |
|
|
|
|
onClick { |
|
|
|
|
onChanged?.invoke(item.toString()) |
|
|
|
|
this@IconDialog.dismiss() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun findIndexOfValue(value: String?): Int { |
|
|
|
|
entryValues?.let { values -> |
|
|
|
|
dialogEntryValues?.let { values -> |
|
|
|
|
for (i in values.indices.reversed()) { |
|
|
|
|
if (values[i] == value) { |
|
|
|
|
return i |
|
|
|
@ -165,4 +166,5 @@ class IconDialog : DialogFragment() { |
|
|
|
|
return -1 |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |