Reimplement extensions search

Not sure if I should abstract this out to per-tab though. Maybe when we need it...
This commit is contained in:
arkon 2022-09-03 10:47:48 -04:00
parent 38950f7bc8
commit 21804bfc45
4 changed files with 41 additions and 16 deletions

View File

@ -21,6 +21,8 @@ fun TabbedScreen(
@StringRes titleRes: Int,
tabs: List<TabContent>,
startIndex: Int? = null,
searchQuery: String? = null,
onChangeSearchQuery: (String?) -> Unit = {},
incognitoMode: Boolean,
downloadedOnlyMode: Boolean,
) {
@ -35,12 +37,27 @@ fun TabbedScreen(
Scaffold(
topBar = {
AppBar(
title = stringResource(titleRes),
actions = {
AppBarActions(tabs[state.currentPage].actions)
},
)
if (searchQuery == null) {
AppBar(
title = stringResource(titleRes),
actions = {
AppBarActions(tabs[state.currentPage].actions)
},
)
} else {
SearchToolbar(
searchQuery = searchQuery,
onChangeSearchQuery = {
onChangeSearchQuery(it)
},
onClickCloseSearch = {
onChangeSearchQuery(null)
},
onClickResetSearch = {
onChangeSearchQuery("")
},
)
}
},
) { paddingValues ->
Column(modifier = Modifier.padding(paddingValues)) {

View File

@ -5,6 +5,8 @@ import android.os.Bundle
import android.view.View
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.core.os.bundleOf
import eu.kanade.presentation.components.TabbedScreen
import eu.kanade.tachiyomi.R
@ -31,6 +33,8 @@ class BrowseController : FullComposeController<BrowsePresenter>, RootController
@Composable
override fun ComposeContent() {
val query by presenter.extensionsPresenter.query.collectAsState()
TabbedScreen(
titleRes = R.string.browse,
tabs = listOf(
@ -39,6 +43,8 @@ class BrowseController : FullComposeController<BrowsePresenter>, RootController
migrateSourcesTab(router, presenter.migrationSourcesPresenter),
),
startIndex = 1.takeIf { toExtensions },
searchQuery = query,
onChangeSearchQuery = { presenter.extensionsPresenter.search(it) },
incognitoMode = presenter.isIncognitoMode,
downloadedOnlyMode = presenter.isDownloadOnly,
)

View File

@ -16,6 +16,8 @@ import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.system.LocaleHelper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.launchIn
@ -33,7 +35,8 @@ class ExtensionsPresenter(
private val getExtensions: GetExtensionsByType = Injekt.get(),
) : ExtensionsState by state {
private val _query: MutableStateFlow<String> = MutableStateFlow("")
private val _query: MutableStateFlow<String?> = MutableStateFlow(null)
val query: StateFlow<String?> = _query.asStateFlow()
private var _currentDownloads = MutableStateFlow<Map<String, InstallStep>>(hashMapOf())
@ -77,8 +80,10 @@ class ExtensionsPresenter(
getExtensions.subscribe(),
_currentDownloads,
) { query, (_updates, _installed, _available, _untrusted), downloads ->
val searchQuery = query ?: ""
val languagesWithExtensions = _available
.filter(queryFilter(query))
.filter(queryFilter(searchQuery))
.groupBy { LocaleHelper.getSourceDisplayName(it.lang, context) }
.toSortedMap()
.flatMap { (key, value) ->
@ -90,14 +95,14 @@ class ExtensionsPresenter(
val items = mutableListOf<ExtensionUiModel>()
val updates = _updates.filter(queryFilter(query)).map(extensionMapper(downloads))
val updates = _updates.filter(queryFilter(searchQuery)).map(extensionMapper(downloads))
if (updates.isNotEmpty()) {
items.add(ExtensionUiModel.Header.Resource(R.string.ext_updates_pending))
items.addAll(updates)
}
val installed = _installed.filter(queryFilter(query)).map(extensionMapper(downloads))
val untrusted = _untrusted.filter(queryFilter(query)).map(extensionMapper(downloads))
val installed = _installed.filter(queryFilter(searchQuery)).map(extensionMapper(downloads))
val untrusted = _untrusted.filter(queryFilter(searchQuery)).map(extensionMapper(downloads))
if (installed.isNotEmpty() || untrusted.isNotEmpty()) {
items.add(ExtensionUiModel.Header.Resource(R.string.ext_installed))
items.addAll(installed)
@ -122,7 +127,7 @@ class ExtensionsPresenter(
.launchIn(presenterScope)
}
fun search(query: String) {
fun search(query: String?) {
presenterScope.launchIO {
_query.emit(query)
}

View File

@ -25,10 +25,7 @@ fun extensionsTab(
AppBar.Action(
title = stringResource(R.string.action_search),
icon = Icons.Outlined.Search,
onClick = {
// TODO: extensions search
// presenter.search(query)
},
onClick = { presenter.search("") },
),
AppBar.Action(