From 00ac632d8f8a612f3b7479faabdea2c388faeb99 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Sat, 24 Jul 2021 23:14:46 +0700 Subject: [PATCH] Fix list scrolling on quad-state dialog (#5602) --- .../ui/setting/SettingsDownloadController.kt | 2 +- .../ui/setting/SettingsLibraryController.kt | 7 ++- .../MaterialAlertDialogBuilderExtensions.kt | 21 +++++++- .../dialog_stub_quadstatemultichoice.xml | 50 +++++++++++++++++-- 4 files changed, 70 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index 18e5a1e717..b8aed28bde 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -243,8 +243,8 @@ class SettingsDownloadController : SettingsController() { return MaterialAlertDialogBuilder(activity!!) .setTitle(R.string.categories) - .setMessage(R.string.pref_download_new_categories_details) .setQuadStateMultiChoiceItems( + message = R.string.pref_download_new_categories_details, items = items, initialSelected = selected ) { selections -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt index 892e440bee..25f2650fe2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsLibraryController.kt @@ -355,8 +355,11 @@ class SettingsLibraryController : SettingsController() { return MaterialAlertDialogBuilder(activity!!) .setTitle(R.string.categories) - .setMessage(R.string.pref_library_update_categories_details) - .setQuadStateMultiChoiceItems(items = items, initialSelected = selected) { selections -> + .setQuadStateMultiChoiceItems( + message = R.string.pref_library_update_categories_details, + items = items, + initialSelected = selected + ) { selections -> selected = selections } .setPositiveButton(android.R.string.ok) { _, _ -> diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt index ea2f66c7f0..7c98756d2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/materialdialogs/MaterialAlertDialogBuilderExtensions.kt @@ -3,7 +3,9 @@ package eu.kanade.tachiyomi.widget.materialdialogs import android.view.LayoutInflater import android.view.inputmethod.InputMethodManager import android.widget.TextView +import androidx.annotation.StringRes import androidx.core.content.getSystemService +import androidx.core.view.isVisible import androidx.core.widget.doAfterTextChanged import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.dialog.MaterialAlertDialogBuilder @@ -36,6 +38,7 @@ fun MaterialAlertDialogBuilder.setTextInput( * @see eu.kanade.tachiyomi.widget.materialdialogs.QuadStateTextView */ fun MaterialAlertDialogBuilder.setQuadStateMultiChoiceItems( + @StringRes message: Int? = null, items: List, initialSelected: IntArray, disabledIndices: IntArray? = null, @@ -49,6 +52,20 @@ fun MaterialAlertDialogBuilder.setQuadStateMultiChoiceItems( initialSelected = initialSelected, listener = selection ) - setView(binding.root) - return this + val updateScrollIndicators = { + binding.scrollIndicatorUp.isVisible = binding.list.canScrollVertically(-1) + binding.scrollIndicatorDown.isVisible = binding.list.canScrollVertically(1) + } + binding.list.setOnScrollChangeListener { _, _, _, _, _ -> + updateScrollIndicators() + } + binding.list.post { + updateScrollIndicators() + } + + if (message != null) { + binding.message.setText(message) + binding.message.isVisible = true + } + return setView(binding.root) } diff --git a/app/src/main/res/layout/dialog_stub_quadstatemultichoice.xml b/app/src/main/res/layout/dialog_stub_quadstatemultichoice.xml index a79a4ac8ed..15e74f7344 100644 --- a/app/src/main/res/layout/dialog_stub_quadstatemultichoice.xml +++ b/app/src/main/res/layout/dialog_stub_quadstatemultichoice.xml @@ -1,9 +1,49 @@ - + android:orientation="vertical" + android:minHeight="48dp"> + + + + + + + + + + + + + + + +