multiple choice filter: add "all" and "none" buttons

This commit is contained in:
Johan von Forstner
2020-05-15 18:56:20 +02:00
parent 02d24a3b3f
commit c82e12bb47
4 changed files with 36 additions and 1 deletions

View File

@@ -184,6 +184,7 @@ class FiltersAdapter : DataBindingAdapter<FilterWithValue<FilterValue>>() {
if (it !in filter.choices.keys) value.values.remove(it)
}
val chips = mutableMapOf<String, Chip>()
binding.chipGroup.removeAllViews()
filter.choices.entries.sortedByDescending {
it.key in value.values
@@ -208,8 +209,19 @@ class FiltersAdapter : DataBindingAdapter<FilterWithValue<FilterValue>>() {
}
binding.chipGroup.addView(chip)
chips.put(choice.key, chip)
}
binding.btnAll.setOnClickListener {
value.all = true
value.values.addAll(filter.choices.keys)
chips.values.forEach { it.isChecked = true }
}
binding.btnNone.setOnClickListener {
value.all = true
value.values.addAll(filter.choices.keys)
chips.values.forEach { it.isChecked = false }
}
}
private fun setupSlider(

View File

@@ -45,7 +45,26 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView17" />
app:layout_constraintTop_toBottomOf="@+id/btnAll" />
<Button
android:id="@+id/btnAll"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all"
app:layout_constraintBaseline_toBaselineOf="@+id/textView17"
app:layout_constraintEnd_toStartOf="@+id/btnNone" />
<Button
android:id="@+id/btnNone"
style="@style/Widget.MaterialComponents.Button.TextButton.Dialog.Flush"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:text="@string/none"
app:layout_constraintBaseline_toBaselineOf="@+id/textView17"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@@ -58,4 +58,6 @@
<string name="plug_supercharger">Tesla Supercharger</string>
<string name="plug_cee_blau">CEE Blau</string>
<string name="plug_cee_rot">CEE Rot</string>
<string name="all">alle</string>
<string name="none">keine</string>
</resources>

View File

@@ -57,4 +57,6 @@
<string name="plug_supercharger">Tesla Supercharger</string>
<string name="plug_cee_blau">CEE Blue</string>
<string name="plug_cee_rot">CEE Red</string>
<string name="all">all</string>
<string name="none">none</string>
</resources>