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

initialize SearchResultCollection once in Activity.onCreate
This commit is contained in:
mpm11011 2020-08-30 12:19:04 -04:00 committed by GitHub
commit d7cfe1990c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 6 deletions

View file

@ -10,6 +10,8 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate 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 eu.kanade.tachiyomi.util.system.LocaleHelper
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
@ -76,6 +78,8 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
secureActivityDelegate.onCreate() secureActivityDelegate.onCreate()
launchNow { SettingsSearchHelper.initPreferenceSearchResultCollection(this@BaseActivity) }
} }
override fun onResume() { override fun onResume() {

View file

@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.ui.download.DownloadController
import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsController
import eu.kanade.tachiyomi.ui.setting.SettingsMainController import eu.kanade.tachiyomi.ui.setting.SettingsMainController
import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchController 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.add
import eu.kanade.tachiyomi.util.preference.iconRes import eu.kanade.tachiyomi.util.preference.iconRes
import eu.kanade.tachiyomi.util.preference.iconTint import eu.kanade.tachiyomi.util.preference.iconTint
@ -49,7 +48,6 @@ class MoreController :
private var downloadQueueSize: Int = 0 private var downloadQueueSize: Int = 0
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
SettingsSearchHelper.initPreferenceSearchResultCollection(context, preferenceManager)
titleRes = R.string.label_more titleRes = R.string.label_more
val tintColor = context.getResourceColor(R.attr.colorAccent) val tintColor = context.getResourceColor(R.attr.colorAccent)

View file

@ -7,7 +7,6 @@ import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
import eu.kanade.tachiyomi.ui.setting.settingssearch.SettingsSearchController 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.iconRes
import eu.kanade.tachiyomi.util.preference.iconTint import eu.kanade.tachiyomi.util.preference.iconTint
import eu.kanade.tachiyomi.util.preference.onClick import eu.kanade.tachiyomi.util.preference.onClick
@ -23,8 +22,6 @@ import reactivecircus.flowbinding.appcompat.queryTextEvents
class SettingsMainController : SettingsController() { class SettingsMainController : SettingsController() {
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
SettingsSearchHelper.initPreferenceSearchResultCollection(context, preferenceManager)
titleRes = R.string.label_settings titleRes = R.string.label_settings
val tintColor = context.getResourceColor(R.attr.colorAccent) val tintColor = context.getResourceColor(R.attr.colorAccent)

View file

@ -1,5 +1,6 @@
package eu.kanade.tachiyomi.ui.setting.settingssearch package eu.kanade.tachiyomi.ui.setting.settingssearch
import android.annotation.SuppressLint
import android.content.Context import android.content.Context
import androidx.preference.Preference import androidx.preference.Preference
import androidx.preference.PreferenceCategory import androidx.preference.PreferenceCategory
@ -48,7 +49,10 @@ object SettingsSearchHelper {
/** /**
* Must be called to populate `prefSearchResultList` * Must be called to populate `prefSearchResultList`
*/ */
fun initPreferenceSearchResultCollection(context: Context, preferenceManager: PreferenceManager) { @SuppressLint("RestrictedApi")
fun initPreferenceSearchResultCollection(context: Context) {
val preferenceManager = PreferenceManager(context)
prefSearchResultList.clear() prefSearchResultList.clear()
settingControllersList.forEach { kClass -> settingControllersList.forEach { kClass ->