|
|
@ -85,84 +85,86 @@ class IconListPreference(context: Context, attrs: AttributeSet) : ListPreference |
|
|
|
} |
|
|
|
} |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class IconDialog : DialogFragment() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var onChanged: ((value: String) -> Unit)? = null |
|
|
|
|
|
|
|
var entries: Array<CharSequence>? = null |
|
|
|
|
|
|
|
var entryValues: Array<CharSequence>? = null |
|
|
|
|
|
|
|
var iconNames: 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() |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateView( |
|
|
|
class IconDialog : DialogFragment() { |
|
|
|
inflater: LayoutInflater, |
|
|
|
|
|
|
|
container: ViewGroup?, |
|
|
|
var onChanged: ((value: String) -> Unit)? = null |
|
|
|
savedInstanceState: Bundle? |
|
|
|
var dialogEntries: Array<CharSequence>? = null |
|
|
|
): View? { |
|
|
|
var dialogEntryValues: Array<CharSequence>? = null |
|
|
|
return inflater.inflate(R.layout.dialog_recycler_view, container) |
|
|
|
var dialogIconNames: Array<CharSequence>? = null |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
|
|
|
|
super.onStart() |
|
|
|
|
|
|
|
val dm = DisplayMetrics() |
|
|
|
|
|
|
|
activity?.windowManager?.defaultDisplay?.getMetrics(dm) |
|
|
|
|
|
|
|
dialog?.window?.setLayout( |
|
|
|
|
|
|
|
(dm.widthPixels * 0.8).toInt(), |
|
|
|
|
|
|
|
ViewGroup.LayoutParams.WRAP_CONTENT |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateView( |
|
|
|
|
|
|
|
inflater: LayoutInflater, |
|
|
|
|
|
|
|
container: ViewGroup?, |
|
|
|
|
|
|
|
savedInstanceState: Bundle? |
|
|
|
|
|
|
|
): View? { |
|
|
|
|
|
|
|
return inflater.inflate(R.layout.dialog_recycler_view, container) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
tool_bar.setTitle(R.string.change_icon) |
|
|
|
tool_bar.setTitle(R.string.change_icon) |
|
|
|
recycler_view.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
recycler_view.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
val adapter = Adapter(requireContext()) |
|
|
|
val adapter = Adapter(requireContext()) |
|
|
|
recycler_view.adapter = adapter |
|
|
|
recycler_view.adapter = adapter |
|
|
|
arguments?.let { |
|
|
|
arguments?.let { |
|
|
|
entries = it.getCharSequenceArray("entries") |
|
|
|
dialogEntries = it.getCharSequenceArray("entries") |
|
|
|
entryValues = it.getCharSequenceArray("entryValues") |
|
|
|
dialogEntryValues = it.getCharSequenceArray("entryValues") |
|
|
|
iconNames = it.getCharSequenceArray("iconNames") |
|
|
|
dialogIconNames = it.getCharSequenceArray("iconNames") |
|
|
|
entryValues?.let { values -> |
|
|
|
dialogEntryValues?.let { values -> |
|
|
|
adapter.setItems(values.toList()) |
|
|
|
adapter.setItems(values.toList()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inner class Adapter(context: Context) : |
|
|
|
inner class Adapter(context: Context) : |
|
|
|
SimpleRecyclerAdapter<CharSequence>(context, R.layout.item_icon_preference) { |
|
|
|
SimpleRecyclerAdapter<CharSequence>(context, R.layout.item_icon_preference) { |
|
|
|
|
|
|
|
|
|
|
|
override fun convert( |
|
|
|
override fun convert( |
|
|
|
holder: ItemViewHolder, |
|
|
|
holder: ItemViewHolder, |
|
|
|
item: CharSequence, |
|
|
|
item: CharSequence, |
|
|
|
payloads: MutableList<Any> |
|
|
|
payloads: MutableList<Any> |
|
|
|
) { |
|
|
|
) { |
|
|
|
with(holder.itemView) { |
|
|
|
with(holder.itemView) { |
|
|
|
val index = findIndexOfValue(item.toString()) |
|
|
|
val index = findIndexOfValue(item.toString()) |
|
|
|
entries?.let { |
|
|
|
dialogEntries?.let { |
|
|
|
label.text = it[index] |
|
|
|
label.text = it[index] |
|
|
|
} |
|
|
|
} |
|
|
|
iconNames?.let { |
|
|
|
dialogIconNames?.let { |
|
|
|
val resId = context.resources |
|
|
|
val resId = context.resources |
|
|
|
.getIdentifier(it[index].toString(), "mipmap", context.packageName) |
|
|
|
.getIdentifier(it[index].toString(), "mipmap", context.packageName) |
|
|
|
val d = context.getCompatDrawable(resId) |
|
|
|
val d = context.getCompatDrawable(resId) |
|
|
|
icon.setImageDrawable(d) |
|
|
|
icon.setImageDrawable(d) |
|
|
|
} |
|
|
|
} |
|
|
|
onClick { |
|
|
|
onClick { |
|
|
|
onChanged?.invoke(item.toString()) |
|
|
|
onChanged?.invoke(item.toString()) |
|
|
|
|
|
|
|
this@IconDialog.dismiss() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun findIndexOfValue(value: String?): Int { |
|
|
|
private fun findIndexOfValue(value: String?): Int { |
|
|
|
entryValues?.let { values -> |
|
|
|
dialogEntryValues?.let { values -> |
|
|
|
for (i in values.indices.reversed()) { |
|
|
|
for (i in values.indices.reversed()) { |
|
|
|
if (values[i] == value) { |
|
|
|
if (values[i] == value) { |
|
|
|
return i |
|
|
|
return i |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return -1 |
|
|
|
} |
|
|
|
} |
|
|
|
return -1 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |