From 8752607433db58cc770a5c4cfc1aedab8493befe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Pich?= <m.pich@outlook.com> Date: Thu, 6 Apr 2023 01:29:46 +0200 Subject: [PATCH] Use segmented toggle buttons instead of option group in grades statistics (#2164) --- .../statistics/GradeStatisticsAdapter.kt | 4 ++- .../layout/item_grade_statistics_header.xml | 26 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt index fd0ac547..3fce8d57 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/statistics/GradeStatisticsAdapter.kt @@ -116,7 +116,9 @@ class GradeStatisticsAdapter @Inject constructor() : } ) - binding.gradeStatisticsTypeSwitch.setOnCheckedChangeListener { _, checkedId -> + binding.gradeStatisticsTypeSwitch.addOnButtonCheckedListener { _, checkedId, isChecked -> + if (!isChecked) return@addOnButtonCheckedListener + currentDataType = when (checkedId) { R.id.gradeStatisticsTypePartial -> GradeStatisticsItem.DataType.PARTIAL R.id.gradeStatisticsTypeSemester -> GradeStatisticsItem.DataType.SEMESTER diff --git a/app/src/main/res/layout/item_grade_statistics_header.xml b/app/src/main/res/layout/item_grade_statistics_header.xml index 92f522ba..cc35f606 100644 --- a/app/src/main/res/layout/item_grade_statistics_header.xml +++ b/app/src/main/res/layout/item_grade_statistics_header.xml @@ -1,8 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="wrap_content" + tools:context=".ui.modules.grade.statistics.GradeStatisticsAdapter"> <HorizontalScrollView android:layout_width="wrap_content" @@ -12,36 +14,38 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> - <RadioGroup + <com.google.android.material.button.MaterialButtonToggleGroup android:id="@+id/gradeStatisticsTypeSwitch" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingStart="16dp" android:paddingTop="5dp" - android:paddingEnd="16dp"> + android:paddingEnd="16dp" + app:selectionRequired="true" + app:singleSelection="true"> - <com.google.android.material.radiobutton.MaterialRadioButton + <Button android:id="@+id/gradeStatisticsTypePartial" + style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" - android:tag="partial" android:text="@string/grade_statistics_partial" /> - <com.google.android.material.radiobutton.MaterialRadioButton + <Button android:id="@+id/gradeStatisticsTypeSemester" + style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:tag="annual" android:text="@string/grade_statistics_semester" /> - <com.google.android.material.radiobutton.MaterialRadioButton + <Button android:id="@+id/gradeStatisticsTypePoints" + style="?attr/materialButtonOutlinedStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:tag="points" android:text="@string/grade_statistics_points" /> - </RadioGroup> + </com.google.android.material.button.MaterialButtonToggleGroup> </HorizontalScrollView> -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file +</androidx.constraintlayout.widget.ConstraintLayout>