mirror of
https://github.com/openlibrecommunity/olcng.git
synced 2026-07-03 14:05:17 +02:00
feat(ui): replace built-in multi-choice dialog with custom adapter
This commit is contained in:
@@ -1093,11 +1093,26 @@ class MainActivity : HelperBaseActivity(), NavigationView.OnNavigationItemSelect
|
||||
// currentFilter stores excluded set (empty = show all)
|
||||
val checked = BooleanArray(codes.size) { codes[it] in currentFilter }
|
||||
|
||||
val adapter = object : android.widget.BaseAdapter() {
|
||||
override fun getCount() = labels.size
|
||||
override fun getItem(pos: Int) = labels[pos]
|
||||
override fun getItemId(pos: Int) = pos.toLong()
|
||||
override fun getView(pos: Int, convertView: android.view.View?, parent: android.view.ViewGroup): android.view.View {
|
||||
val view = convertView ?: layoutInflater.inflate(R.layout.item_dialog_country, parent, false)
|
||||
view.findViewById<android.widget.TextView>(R.id.text).text = labels[pos]
|
||||
val cb = view.findViewById<com.google.android.material.checkbox.MaterialCheckBox>(R.id.check_box)
|
||||
cb.isChecked = checked[pos]
|
||||
view.setOnClickListener {
|
||||
checked[pos] = !checked[pos]
|
||||
cb.isChecked = checked[pos]
|
||||
}
|
||||
return view
|
||||
}
|
||||
}
|
||||
|
||||
val dialog = MaterialAlertDialogBuilder(this@MainActivity)
|
||||
.setTitle("Исключить страны")
|
||||
.setMultiChoiceItems(labels, checked) { _, which, isChecked ->
|
||||
checked[which] = isChecked
|
||||
}
|
||||
.setAdapter(adapter, null)
|
||||
.setPositiveButton("Применить") { _, _ ->
|
||||
val excluded = codes.filterIndexed { i, _ -> checked[i] }.toSet()
|
||||
mainViewModel.applyCountryFilter(excluded)
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingHorizontal="24dp"
|
||||
android:paddingVertical="12dp">
|
||||
|
||||
<com.google.android.material.checkbox.MaterialCheckBox
|
||||
android:id="@+id/check_box"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:button="@drawable/checkbox_round_selector"
|
||||
android:clickable="false"
|
||||
android:focusable="false" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginStart="16dp"
|
||||
android:textAppearance="?attr/textAppearanceBodyLarge" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user