172 lines
6.8 KiB
Kotlin
172 lines
6.8 KiB
Kotlin
package eu.kanade.presentation.browse
|
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.State
|
|
import androidx.compose.runtime.collectAsState
|
|
import androidx.compose.runtime.getValue
|
|
import eu.kanade.domain.source.model.installedExtension
|
|
import eu.kanade.presentation.browse.components.GlobalSearchCardRow
|
|
import eu.kanade.presentation.browse.components.GlobalSearchErrorResultItem
|
|
import eu.kanade.presentation.browse.components.GlobalSearchLoadingResultItem
|
|
import eu.kanade.presentation.browse.components.GlobalSearchResultItem
|
|
import eu.kanade.presentation.browse.components.GlobalSearchToolbar
|
|
import eu.kanade.presentation.components.SelectionToolbar
|
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
|
import eu.kanade.tachiyomi.ui.browse.BulkFavoriteScreenModel
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchItemResult
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchScreenModel
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SourceFilter
|
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
|
import kotlinx.collections.immutable.ImmutableMap
|
|
import tachiyomi.domain.manga.model.Manga
|
|
import tachiyomi.presentation.core.components.material.Scaffold
|
|
import tachiyomi.domain.source.model.Source as DomainSource
|
|
|
|
@Composable
|
|
fun GlobalSearchScreen(
|
|
state: SearchScreenModel.State,
|
|
navigateUp: () -> Unit,
|
|
onChangeSearchQuery: (String?) -> Unit,
|
|
onSearch: (String) -> Unit,
|
|
onChangeSearchFilter: (SourceFilter) -> Unit,
|
|
onToggleResults: () -> Unit,
|
|
getManga: @Composable (Manga) -> State<Manga>,
|
|
onClickSource: (CatalogueSource) -> Unit,
|
|
onClickItem: (Manga) -> Unit,
|
|
onLongClickItem: (Manga) -> Unit,
|
|
// KMK -->
|
|
bulkFavoriteScreenModel: BulkFavoriteScreenModel,
|
|
// KMK <--
|
|
) {
|
|
// KMK -->
|
|
val bulkFavoriteState by bulkFavoriteScreenModel.state.collectAsState()
|
|
// KMK <--
|
|
|
|
Scaffold(
|
|
topBar = { scrollBehavior ->
|
|
// KMK -->
|
|
if (bulkFavoriteState.selectionMode) {
|
|
SelectionToolbar(
|
|
selectedCount = bulkFavoriteState.selection.size,
|
|
onClickClearSelection = bulkFavoriteScreenModel::toggleSelectionMode,
|
|
onChangeCategoryClicked = bulkFavoriteScreenModel::addFavorite,
|
|
onSelectAll = {
|
|
state.filteredItems.forEach { (_, result) ->
|
|
when (result) {
|
|
is SearchItemResult.Success -> {
|
|
result.result.forEach { manga ->
|
|
if (!bulkFavoriteState.selection.contains(manga)) {
|
|
bulkFavoriteScreenModel.select(manga)
|
|
}
|
|
}
|
|
}
|
|
else -> {}
|
|
}
|
|
}
|
|
},
|
|
)
|
|
} else {
|
|
// KMK <--
|
|
GlobalSearchToolbar(
|
|
searchQuery = state.searchQuery,
|
|
progress = state.progress,
|
|
total = state.total,
|
|
navigateUp = navigateUp,
|
|
onChangeSearchQuery = onChangeSearchQuery,
|
|
onSearch = onSearch,
|
|
sourceFilter = state.sourceFilter,
|
|
onChangeSearchFilter = onChangeSearchFilter,
|
|
onlyShowHasResults = state.onlyShowHasResults,
|
|
onToggleResults = onToggleResults,
|
|
scrollBehavior = scrollBehavior,
|
|
// KMK -->
|
|
toggleSelectionMode = bulkFavoriteScreenModel::toggleSelectionMode,
|
|
// KMK <--
|
|
)
|
|
}
|
|
},
|
|
) { paddingValues ->
|
|
GlobalSearchContent(
|
|
items = state.filteredItems,
|
|
contentPadding = paddingValues,
|
|
getManga = getManga,
|
|
onClickSource = onClickSource,
|
|
onClickItem = onClickItem,
|
|
onLongClickItem = onLongClickItem,
|
|
// KMK -->
|
|
selection = bulkFavoriteState.selection,
|
|
// KMK <--
|
|
)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
internal fun GlobalSearchContent(
|
|
items: ImmutableMap<CatalogueSource, SearchItemResult>,
|
|
contentPadding: PaddingValues,
|
|
getManga: @Composable (Manga) -> State<Manga>,
|
|
onClickSource: (CatalogueSource) -> Unit,
|
|
onClickItem: (Manga) -> Unit,
|
|
onLongClickItem: (Manga) -> Unit,
|
|
fromSourceId: Long? = null,
|
|
// KMK -->
|
|
selection: List<Manga>,
|
|
// KMK <--
|
|
) {
|
|
LazyColumn(
|
|
contentPadding = contentPadding,
|
|
) {
|
|
items.forEach { (source, result) ->
|
|
item(key = source.id) {
|
|
// KMK -->
|
|
val domainSource = DomainSource(
|
|
source.id,
|
|
"",
|
|
"",
|
|
supportsLatest = false,
|
|
isStub = false
|
|
)
|
|
// KMK <--
|
|
|
|
GlobalSearchResultItem(
|
|
title = (
|
|
fromSourceId?.let {
|
|
"▶ ${source.name}".takeIf { source.id == fromSourceId }
|
|
} ?: source.name
|
|
) +
|
|
// KMK -->
|
|
(
|
|
domainSource.installedExtension?.let { extension ->
|
|
" (${extension.name})".takeIf { extension.name != source.name }
|
|
} ?: ""
|
|
),
|
|
// KMK <--
|
|
subtitle = LocaleHelper.getLocalizedDisplayName(source.lang),
|
|
onClick = { onClickSource(source) },
|
|
) {
|
|
when (result) {
|
|
SearchItemResult.Loading -> {
|
|
GlobalSearchLoadingResultItem()
|
|
}
|
|
is SearchItemResult.Success -> {
|
|
GlobalSearchCardRow(
|
|
titles = result.result,
|
|
getManga = getManga,
|
|
onClick = onClickItem,
|
|
onLongClick = onLongClickItem,
|
|
// KMK -->
|
|
selection = selection,
|
|
// KMK <--
|
|
)
|
|
}
|
|
is SearchItemResult.Error -> {
|
|
GlobalSearchErrorResultItem(message = result.throwable.message)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|