diff --git a/app/build.gradle b/app/build.gradle index fcab50ecc..bf29d4fd8 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -202,7 +202,6 @@ dependencies { // Preferences implementation 'com.github.tfcporciuncula:flow-preferences:1.3.0' implementation 'com.github.ByteHamster:SearchPreference:v1.0.3' - implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" // Model View Presenter final nucleus_version = '3.0.0' @@ -276,6 +275,7 @@ dependencies { testImplementation "org.robolectric:shadows-play-services:$robolectric_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$BuildPluginsVersion.KOTLIN" + implementation "org.jetbrains.kotlin:kotlin-reflect:$BuildPluginsVersion.KOTLIN" final coroutines_version = '1.3.8' implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt index 31f72bc72..8a5b3abf8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionFilterController.kt @@ -13,7 +13,7 @@ import uy.kohesive.injekt.api.get class ExtensionFilterController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.label_extensions val activeLangs = preferences.enabledLanguages().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt index 1edf4969e..2b11f7550 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceFilterController.kt @@ -24,7 +24,7 @@ class SourceFilterController : SettingsController() { private val onlineSources by lazy { Injekt.get().getOnlineSources() } - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.label_sources // Get the list of active language codes. @@ -46,7 +46,7 @@ class SourceFilterController : SettingsController() { // Create a preference group and set initial state and change listener switchPreferenceCategory { - preferenceScreen.addPreference(this) + this@apply.addPreference(this) title = LocaleHelper.getSourceDisplayName(lang, context) isPersistent = false if (lang in activeLangsCodes) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt index 1abef4141..7ee57ce56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/more/AboutController.kt @@ -41,7 +41,7 @@ class AboutController : SettingsController() { private val isUpdaterEnabled = BuildConfig.INCLUDE_UPDATER - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_about preference { 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 b49007f3e..7f357e727 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 @@ -38,7 +38,7 @@ class MoreController : private var isDownloading: Boolean = false private var downloadQueueSize: Int = 0 - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.label_more val tintColor = context.getResourceColor(R.attr.colorAccent) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt index 9be61ad9d..7ac4b8532 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt @@ -41,7 +41,7 @@ class SettingsAdvancedController : SettingsController() { private val db: DatabaseHelper by injectLazy() @SuppressLint("BatteryLife") - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_advanced switchPreference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index f030d3680..c42d21dfe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -49,7 +49,7 @@ class SettingsBackupController : SettingsController() { requestPermissionsSafe(arrayOf(WRITE_EXTERNAL_STORAGE), 500) } - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.backup preference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt index ab4d0bd7b..7212095c3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBrowseController.kt @@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.util.preference.titleRes class SettingsBrowseController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.browse preferenceCategory { 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 ee9c15366..6915b17df 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 @@ -50,7 +50,7 @@ abstract class SettingsController : PreferenceController() { setupPreferenceScreen(screen) } - abstract fun setupPreferenceScreen(screen: PreferenceScreen): Any? + abstract fun setupPreferenceScreen(screen: PreferenceScreen): PreferenceScreen private fun getThemedContext(): Context { val tv = TypedValue() 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 82c055a0f..76ff9f196 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 @@ -40,7 +40,7 @@ class SettingsDownloadController : SettingsController() { private val db: DatabaseHelper by injectLazy() - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_downloads preference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index f3785bea6..e7feda39c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.flow.launchIn class SettingsGeneralController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_general intListPreference { 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 b42ed0b0a..477d880e7 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 @@ -40,7 +40,7 @@ class SettingsLibraryController : SettingsController() { private val db: DatabaseHelper = Injekt.get() - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_library val dbCategories = db.getCategories().executeAsBlocking() 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 72527ee64..c3a4f0e9c 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,6 +7,7 @@ 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 @@ -21,7 +22,9 @@ import reactivecircus.flowbinding.appcompat.queryTextEvents class SettingsMainController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { + SettingsSearchHelper.initPreferenceSearchResultCollection(context, preferenceManager) + titleRes = R.string.label_settings val tintColor = context.getResourceColor(R.attr.colorAccent) @@ -106,8 +109,10 @@ class SettingsMainController : SettingsController() { // Create query listener which opens the global search view. searchView.queryTextEvents() - .filterIsInstance() - .onEach { performSettingsSearch(it.queryText.toString()) } + .filterIsInstance() + .onEach { + performSettingsSearch(it.queryText.toString()) + } .launchIn(scope) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsParentalControlsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsParentalControlsController.kt index 016b626c5..42708094a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsParentalControlsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsParentalControlsController.kt @@ -13,7 +13,7 @@ import eu.kanade.tachiyomi.util.preference.titleRes class SettingsParentalControlsController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_parental_controls listPreference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index e35f49666..fbbcd9056 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -19,7 +19,7 @@ import kotlinx.coroutines.flow.launchIn class SettingsReaderController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_reader intListPreference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt index 6fb3a1e66..bf1bb76fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt @@ -14,7 +14,7 @@ import kotlinx.coroutines.flow.launchIn class SettingsSecurityController : SettingsController() { - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_security if (BiometricManager.from(context).canAuthenticate() == BiometricManager.BIOMETRIC_SUCCESS) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt index d61cce20a..dbe4e5ad9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsTrackingController.kt @@ -31,7 +31,7 @@ class SettingsTrackingController : private val trackManager: TrackManager by injectLazy() - override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) { + override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { titleRes = R.string.pref_category_tracking switchPreference { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt index a733df777..75cfae28c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchAdapter.kt @@ -3,9 +3,9 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch import android.os.Bundle import android.os.Parcelable import android.util.SparseArray -import androidx.preference.Preference import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter +import eu.kanade.tachiyomi.ui.setting.SettingsController /** * Adapter that holds the search cards. @@ -72,7 +72,7 @@ class SettingsSearchAdapter(val controller: SettingsSearchController) : } interface OnTitleClickListener { - fun onTitleClick(pref: Preference) + fun onTitleClick(ctrl: SettingsController) } private companion object { 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 4b9a74233..518460753 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 @@ -8,18 +8,13 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView -import androidx.preference.Preference import androidx.recyclerview.widget.LinearLayoutManager import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.SettingsSearchControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction +import eu.kanade.tachiyomi.ui.setting.SettingsController import eu.kanade.tachiyomi.ui.setting.SettingsControllerFactory -import kotlinx.coroutines.flow.filterIsInstance -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach -import reactivecircus.flowbinding.appcompat.QueryTextEvent -import reactivecircus.flowbinding.appcompat.queryTextEvents /** * This controller shows and manages the different search result in settings search. @@ -83,10 +78,13 @@ open class SettingsSearchController( val searchView = searchItem.actionView as SearchView searchView.maxWidth = Int.MAX_VALUE + searchItem.expandActionView() + setItems(getResultSet()) + searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { override fun onMenuItemActionExpand(item: MenuItem?): Boolean { searchView.onActionViewExpanded() // Required to show the query in the view - searchView.setQuery(presenter.query, false) + setItems(getResultSet()) return true } @@ -95,14 +93,19 @@ open class SettingsSearchController( } }) - searchView.queryTextEvents() - .filterIsInstance() - .onEach { - presenter.search(it.queryText.toString()) + searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { + override fun onQueryTextSubmit(query: String?): Boolean { searchItem.collapseActionView() - setTitle() // Update toolbar title + setTitle(query) // Update toolbar title + setItems(getResultSet(query)) + return false } - .launchIn(scope) + + override fun onQueryTextChange(newText: String?): Boolean { + setItems(getResultSet(newText)) + return false + } + }) } /** @@ -141,17 +144,44 @@ open class SettingsSearchController( * @param pref used to find holder containing source * @return the holder of the preference or null if it's not bound. */ - private fun getHolder(pref: Preference): SettingsSearchHolder? { - val adapter = adapter ?: return null +// private fun getHolder(pref: Preference): SettingsSearchHolder? { +// val adapter = adapter ?: return null +// +// adapter.allBoundViewHolders.forEach { holder -> +// val item = adapter.getItem(holder.bindingAdapterPosition) +// if (item != null && pref.key == item.pref.key) { +// return holder as SettingsSearchHolder +// } +// } +// +// return null +// } - adapter.allBoundViewHolders.forEach { holder -> - val item = adapter.getItem(holder.bindingAdapterPosition) - if (item != null && pref.key == item.pref.key) { - return holder as SettingsSearchHolder + /** + * returns a list of `SettingsSearchItem` to be shown as search results + */ + fun getResultSet(query: String? = null): List { + val list = mutableListOf() + + if (query.isNullOrBlank()) { + SettingsSearchHelper.prefSearchResultList.forEach { + list.add(SettingsSearchItem(it, null)) } + } else { + SettingsSearchHelper.prefSearchResultList + .filter { + val inTitle = it.title.contains(query, true) + val inSummary = it.summary.contains(query, true) + val inBreadcrumb = it.breadcrumb.contains(query, true) + + return@filter inTitle || inSummary || inBreadcrumb + } + .forEach { + list.add(SettingsSearchItem(it, null)) + } } - return null + return list } /** @@ -166,12 +196,7 @@ open class SettingsSearchController( /** * Opens a catalogue with the given search. */ - override fun onTitleClick(pref: Preference) { - // TODO - These asserts will be the death of me, fix them. - for (ctrl in this!!.controllers!!) { - if (ctrl.findPreference(pref.key) != null) { - router.pushController(ctrl.withFadeTransaction()) - } - } + override fun onTitleClick(ctrl: SettingsController) { + router.replaceTopController(ctrl.withFadeTransaction()) } } 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 new file mode 100644 index 000000000..1f8d6458c --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHelper.kt @@ -0,0 +1,106 @@ +package eu.kanade.tachiyomi.ui.setting.settingssearch + +import android.content.Context +import androidx.preference.Preference +import androidx.preference.PreferenceCategory +import androidx.preference.PreferenceGroup +import androidx.preference.PreferenceManager +import eu.kanade.tachiyomi.ui.browse.extension.ExtensionFilterController +import eu.kanade.tachiyomi.ui.browse.source.SourceFilterController +import eu.kanade.tachiyomi.ui.more.AboutController +import eu.kanade.tachiyomi.ui.more.MoreController +import eu.kanade.tachiyomi.ui.setting.SettingsAdvancedController +import eu.kanade.tachiyomi.ui.setting.SettingsBackupController +import eu.kanade.tachiyomi.ui.setting.SettingsBrowseController +import eu.kanade.tachiyomi.ui.setting.SettingsController +import eu.kanade.tachiyomi.ui.setting.SettingsDownloadController +import eu.kanade.tachiyomi.ui.setting.SettingsGeneralController +import eu.kanade.tachiyomi.ui.setting.SettingsLibraryController +import eu.kanade.tachiyomi.ui.setting.SettingsParentalControlsController +import eu.kanade.tachiyomi.ui.setting.SettingsReaderController +import eu.kanade.tachiyomi.ui.setting.SettingsSecurityController +import eu.kanade.tachiyomi.ui.setting.SettingsTrackingController +import kotlin.reflect.KClass +import kotlin.reflect.full.createInstance + +object SettingsSearchHelper { + var prefSearchResultList: MutableList = mutableListOf() + private set + + /** + * All subclasses of `SettingsController` should be listed here, in order to have their preferences searchable. + */ + private val settingControllersList: List> = listOf( + SettingsAdvancedController::class, + SettingsBackupController::class, + SettingsBrowseController::class, + SettingsDownloadController::class, + SettingsGeneralController::class, + SettingsLibraryController::class, + SettingsParentalControlsController::class, + SettingsReaderController::class, + SettingsSecurityController::class, + SettingsTrackingController::class, + ExtensionFilterController::class, + SourceFilterController::class, + AboutController::class, + MoreController::class + ) + + /** + * Must be called to populate `prefSearchResultList` + */ + fun initPreferenceSearchResultCollection(context: Context, preferenceManager: PreferenceManager) { + prefSearchResultList.clear() + + settingControllersList.forEach { kClass -> + val ctrl = kClass.createInstance() + val settingsPrefScreen = ctrl.setupPreferenceScreen(preferenceManager.createPreferenceScreen(context)) + val prefCount = settingsPrefScreen.preferenceCount + for (i in 0 until prefCount) { + val rootPref = settingsPrefScreen.getPreference(i) + if (rootPref.title == null) continue // no title, not a preference. (note: only info notes appear to not have titles) + getSettingSearchResult(ctrl, rootPref, "${settingsPrefScreen.title}") + } + } + } + + /** + * Extracts the data needed from a `Preference` to create a `SettingsSearchResult`, and then adds it to `prefSearchResultList` + */ + private fun getSettingSearchResult(ctrl: SettingsController, pref: Preference, breadcrumbs: String = "") { + when (pref) { + is PreferenceGroup -> { + val breadcrumbsStr = breadcrumbs + " > ${pref.title}" + + for (x in 0 until pref.preferenceCount) { + val subPref = pref.getPreference(x) + getSettingSearchResult(ctrl, subPref, breadcrumbsStr) // recursion + } + } + is PreferenceCategory -> { + val breadcrumbsStr = breadcrumbs + " > ${pref.title}" + + for (x in 0 until pref.preferenceCount) { + val subPref = pref.getPreference(x) + getSettingSearchResult(ctrl, subPref, breadcrumbsStr) // recursion + } + } + else -> { + // Is an actual preference + val title = pref.title.toString() + val summary = if (pref.summary != null) pref.summary.toString() else "" + val breadcrumbsStr = breadcrumbs + " > ${pref.title}" + + prefSearchResultList.add(SettingsSearchResult(title, summary, breadcrumbsStr, ctrl)) + } + } + } + + data class SettingsSearchResult( + val title: String, + val summary: String, + val breadcrumb: String, + val searchController: SettingsController + ) +} diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt index a5c91bec1..11ab80819 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchHolder.kt @@ -2,8 +2,8 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch import android.view.View import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder -import kotlinx.android.synthetic.main.settings_search_controller_card.setting -import kotlinx.android.synthetic.main.settings_search_controller_card.title_wrapper +import kotlin.reflect.full.createInstance +import kotlinx.android.synthetic.main.settings_search_controller_card.* /** * Holder that binds the [SettingsSearchItem] containing catalogue cards. @@ -14,17 +14,12 @@ import kotlinx.android.synthetic.main.settings_search_controller_card.title_wrap class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) : BaseFlexibleViewHolder(view, adapter) { - /** - * Adapter containing preference from search results. - */ - private val settingsAdapter = SettingsSearchAdapter(adapter.controller) - - private var lastBoundResults: List? = null - init { title_wrapper.setOnClickListener { adapter.getItem(bindingAdapterPosition)?.let { - adapter.titleClickListener.onTitleClick(it.pref) + val ctrl = it.settingsSearchResult.searchController + // needs to be a new instance to avoid this error https://github.com/bluelinelabs/Conductor/issues/446 + adapter.titleClickListener.onTitleClick(ctrl::class.createInstance()) } } } @@ -35,17 +30,8 @@ class SettingsSearchHolder(view: View, val adapter: SettingsSearchAdapter) : * @param item item of card. */ fun bind(item: SettingsSearchItem) { - val preference = item.pref - val results = item.results - - val titlePrefix = if (item.highlighted) "▶ " else "" - - // Set Title with country code if available. - setting.text = titlePrefix + preference.key - - if (results !== lastBoundResults) { - settingsAdapter.updateDataSet(results) - lastBoundResults = results - } + search_result_pref_title.text = item.settingsSearchResult.title + search_result_pref_summary.text = item.settingsSearchResult.summary + search_result_pref_breadcrumb.text = item.settingsSearchResult.breadcrumb } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt index 60fb219a2..f555abf9f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/settingssearch/SettingsSearchItem.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.ui.setting.settingssearch import android.view.View -import androidx.preference.Preference import androidx.recyclerview.widget.RecyclerView import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.AbstractFlexibleItem @@ -13,9 +12,8 @@ import eu.kanade.tachiyomi.R * * @param pref the source for the search results. * @param results the search results. - * @param highlighted whether this search item should be highlighted/marked in the catalogue search view. */ -class SettingsSearchItem(val pref: Preference, val results: List?, val highlighted: Boolean = false) : +class SettingsSearchItem(val settingsSearchResult: SettingsSearchHelper.SettingsSearchResult, val results: List?) : AbstractFlexibleItem() { /** @@ -55,7 +53,7 @@ class SettingsSearchItem(val pref: Preference, val results: List + + - - + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/search_result_pref_summary" + tools:text="Location" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index fd1c4105e..8b59b5c6c 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -23,4 +23,8 @@ 14sp 0dp + + 50dp + 20dp + 20dp