feat(ui): replace built-in multi-choice dialog with custom adapter

This commit is contained in:
zarazaex69
2026-05-24 16:31:09 +03:00
parent fbb6da0c42
commit a75deb1374
2 changed files with 44 additions and 3 deletions
@@ -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>