From 437a34b5dce46fb7a1bb773a3a0af1fc66d48009 Mon Sep 17 00:00:00 2001 From: lmj0011 <9396189+lmj0011@users.noreply.github.com> Date: Thu, 27 Aug 2020 00:53:50 -0500 Subject: [PATCH] - initialize SearchResultCollection once in Activity.onCreate --- .../eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt | 4 ++++ .../main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt | 2 -- .../kanade/tachiyomi/ui/setting/SettingsMainController.kt | 3 --- .../ui/setting/settingssearch/SettingsSearchHelper.kt | 6 +++++- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 0ecde8b1d..d2953c5db 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -10,6 +10,8 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate +import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchHelper +import eu.kanade.tachiyomi.util.lang.launchNow import eu.kanade.tachiyomi.util.system.LocaleHelper import uy.kohesive.injekt.injectLazy @@ -76,6 +78,8 @@ abstract class BaseActivity : AppCompatActivity() { super.onCreate(savedInstanceState) secureActivityDelegate.onCreate() + + launchNow { SettingsSearchHelper.initPreferenceSearchResultCollection(this@BaseActivity) } } override fun onResume() { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt index 55261c3af..f45b6ae7c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/MoreController.kt @@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.ui.download.DownloadController import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsMainController import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchController -import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchHelper import eu.kanade.tachiyomi.util.preference.add import eu.kanade.tachiyomi.util.preference.iconRes import eu.kanade.tachiyomi.util.preference.iconTint @@ -49,7 +48,6 @@ class MoreController : private var downloadQueueSize: Int = 0 override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { - SettingsSearchHelper.initPreferenceSearchResultCollection(context, preferenceManager) titleRes = R.string.label_more val tintColor = context.getResourceColor(R.attr.colorAccent) 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 8e85c618c..71cd5537d 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 @@ -7,7 +7,6 @@ import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchController -import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchHelper import eu.kanade.tachiyomi.util.preference.iconRes import eu.kanade.tachiyomi.util.preference.iconTint import eu.kanade.tachiyomi.util.preference.onClick @@ -23,8 +22,6 @@ import reactivecircus.flowbinding.appcompat.queryTextEvents class SettingsMainController : SettingsController() { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { - SettingsSearchHelper.initPreferenceSearchResultCollection(context, preferenceManager) - titleRes = R.string.label_settings val tintColor = context.getResourceColor(R.attr.colorAccent) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt index f57fc2ee6..a2a1ae265 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt @@ -1,5 +1,6 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch +import android.annotation.SuppressLint import android.content.Context import androidx.preference.Preference import androidx.preference.PreferenceCategory @@ -48,7 +49,10 @@ object SettingsSearchHelper { /** * Must be called to populate `prefSearchResultList` */ - fun initPreferenceSearchResultCollection(context: Context, preferenceManager: PreferenceManager) { + @SuppressLint("RestrictedApi") + fun initPreferenceSearchResultCollection(context: Context) { + val preferenceManager = PreferenceManager(context) + prefSearchResultList.clear() settingControllersList.forEach { kClass ->