From a5098e5b5b3fdae129fd1a7beb2c867d6ae8cca7 Mon Sep 17 00:00:00 2001 From: mpm11011 Date: Sat, 5 Sep 2020 14:28:41 -0400 Subject: [PATCH] Code review cleanup and refactoring. --- .../ui/setting/SettingsController.kt | 16 ++-- .../ui/setting/SettingsMainController.kt | 10 +-- .../SettingsSearchController.kt | 12 +-- .../settingssearch/SettingsSearchPresenter.kt | 4 - .../settings_search_controller_card.xml | 79 +++++++++---------- app/src/main/res/values/dimens.xml | 4 - 6 files changed, 51 insertions(+), 74 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index a6a3e11ff2..ff42364c6f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -82,14 +82,14 @@ abstract class SettingsController : PreferenceController() { } private fun animatePreferenceHighlight(view: View) { - val duration = 500L - val repeat = 2 - - val colorAnimation = ValueAnimator.ofObject(ArgbEvaluator(), Color.TRANSPARENT, Color.WHITE) - colorAnimation.duration = duration - colorAnimation.repeatCount = repeat - colorAnimation.addUpdateListener { animator -> view.setBackgroundColor(animator.animatedValue as Int) } - colorAnimation.reverse() + ValueAnimator + .ofObject(ArgbEvaluator(), Color.TRANSPARENT, R.attr.rippleColor) + .apply { + duration = 500L + repeatCount = 2 + addUpdateListener { animator -> view.setBackgroundColor(animator.animatedValue as Int) } + reverse() + } } open fun getTitle(): String? { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt index 4aebe5a922..f4ad880e28 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsMainController.kt @@ -108,14 +108,10 @@ class SettingsMainController : SettingsController() { searchView.queryTextEvents() .filterIsInstance() .onEach { - performSettingsSearch(it.queryText.toString()) + router.pushController( + SettingsSearchController().withFadeTransaction() + ) } .launchIn(scope) } - - private fun performSettingsSearch(query: String) { - router.pushController( - SettingsSearchController().withFadeTransaction() - ) - } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt index 9ce6098531..3aeb4a54a3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchController.kt @@ -137,16 +137,12 @@ class SettingsSearchController : * returns a list of `SettingsSearchItem` to be shown as search results */ fun getResultSet(query: String? = null): List { - val list = mutableListOf() - - if (!query.isNullOrBlank()) { - SettingsSearchHelper.getFilteredResults(query) - .forEach { - list.add(SettingsSearchItem(it, null)) - } + if (!query.isNullOrBlank() && query.length >= 3) { + return SettingsSearchHelper.getFilteredResults(query) + .map { SettingsSearchItem(it, null) } } - return list + return mutableListOf() } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchPresenter.kt index e3946eed9d..90e59ba001 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchPresenter.kt @@ -1,9 +1,7 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch import android.os.Bundle -import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.source.SourceManager import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -20,8 +18,6 @@ open class SettingsSearchPresenter : BasePresenter() { var query = "" private set - val sourceManager: SourceManager = Injekt.get() - val db: DatabaseHelper = Injekt.get() val preferences: PreferencesHelper = Injekt.get() override fun onCreate(savedState: Bundle?) { diff --git a/app/src/main/res/layout/settings_search_controller_card.xml b/app/src/main/res/layout/settings_search_controller_card.xml index fe2dfda8ac..ada7639e7a 100644 --- a/app/src/main/res/layout/settings_search_controller_card.xml +++ b/app/src/main/res/layout/settings_search_controller_card.xml @@ -1,52 +1,45 @@ - + android:layout_marginStart="48dp" + android:layout_marginTop="16dp" + android:layout_marginBottom="16dp" + android:background="?attr/selectableItemBackground"> - + - + - + + - - - - - - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 8b59b5c6cb..fd1c4105e1 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -23,8 +23,4 @@ 14sp 0dp - - 50dp - 20dp - 20dp