Răsfoiți Sursa

Merge pull request #2 from lmj0011/dev-settings-search

initialize SearchResultCollection once in Activity.onCreate
mpm11011 4 ani în urmă
părinte
comite
d7cfe1990c

+ 4 - 0
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<VB : ViewBinding> : AppCompatActivity() {
         super.onCreate(savedInstanceState)
 
         secureActivityDelegate.onCreate()
+
+        launchNow { SettingsSearchHelper.initPreferenceSearchResultCollection(this@BaseActivity) }
     }
 
     override fun onResume() {

+ 0 - 2
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)

+ 0 - 3
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)

+ 5 - 1
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 ->