2022-11-27 20:56:21 +01:00
|
|
|
package eu.kanade.presentation.browse
|
|
|
|
|
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.Text
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.State
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.res.stringResource
|
|
|
|
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.LazyColumn
|
|
|
|
import eu.kanade.presentation.components.Scaffold
|
|
|
|
import eu.kanade.presentation.util.padding
|
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
|
import eu.kanade.tachiyomi.source.CatalogueSource
|
|
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.GlobalSearchState
|
2022-12-14 23:20:51 -05:00
|
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchItemResult
|
2022-11-27 20:56:21 +01:00
|
|
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
2023-01-22 10:54:28 -05:00
|
|
|
import tachiyomi.domain.manga.model.Manga
|
2022-11-27 20:56:21 +01:00
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun GlobalSearchScreen(
|
|
|
|
state: GlobalSearchState,
|
|
|
|
navigateUp: () -> Unit,
|
|
|
|
onChangeSearchQuery: (String?) -> Unit,
|
|
|
|
onSearch: (String) -> Unit,
|
|
|
|
getManga: @Composable (CatalogueSource, Manga) -> State<Manga>,
|
|
|
|
onClickSource: (CatalogueSource) -> Unit,
|
|
|
|
onClickItem: (Manga) -> Unit,
|
|
|
|
onLongClickItem: (Manga) -> Unit,
|
|
|
|
) {
|
|
|
|
Scaffold(
|
2022-11-27 15:16:08 -05:00
|
|
|
topBar = { scrollBehavior ->
|
2022-11-27 20:56:21 +01:00
|
|
|
GlobalSearchToolbar(
|
|
|
|
searchQuery = state.searchQuery,
|
|
|
|
progress = state.progress,
|
|
|
|
total = state.total,
|
|
|
|
navigateUp = navigateUp,
|
|
|
|
onChangeSearchQuery = onChangeSearchQuery,
|
|
|
|
onSearch = onSearch,
|
2022-11-27 15:16:08 -05:00
|
|
|
scrollBehavior = scrollBehavior,
|
2022-11-27 20:56:21 +01:00
|
|
|
)
|
|
|
|
},
|
|
|
|
) { paddingValues ->
|
|
|
|
GlobalSearchContent(
|
|
|
|
items = state.items,
|
|
|
|
contentPadding = paddingValues,
|
|
|
|
getManga = getManga,
|
|
|
|
onClickSource = onClickSource,
|
|
|
|
onClickItem = onClickItem,
|
|
|
|
onLongClickItem = onLongClickItem,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Composable
|
|
|
|
fun GlobalSearchContent(
|
2022-12-14 23:20:51 -05:00
|
|
|
items: Map<CatalogueSource, SearchItemResult>,
|
2022-11-27 20:56:21 +01:00
|
|
|
contentPadding: PaddingValues,
|
|
|
|
getManga: @Composable (CatalogueSource, Manga) -> State<Manga>,
|
|
|
|
onClickSource: (CatalogueSource) -> Unit,
|
|
|
|
onClickItem: (Manga) -> Unit,
|
|
|
|
onLongClickItem: (Manga) -> Unit,
|
|
|
|
) {
|
|
|
|
LazyColumn(
|
|
|
|
contentPadding = contentPadding,
|
|
|
|
) {
|
|
|
|
items.forEach { (source, result) ->
|
2023-01-15 10:14:28 -05:00
|
|
|
item(key = source.id) {
|
2022-11-27 20:56:21 +01:00
|
|
|
GlobalSearchResultItem(
|
|
|
|
title = source.name,
|
|
|
|
subtitle = LocaleHelper.getDisplayName(source.lang),
|
|
|
|
onClick = { onClickSource(source) },
|
|
|
|
) {
|
|
|
|
when (result) {
|
2022-12-14 23:20:51 -05:00
|
|
|
SearchItemResult.Loading -> {
|
2022-11-27 20:56:21 +01:00
|
|
|
GlobalSearchLoadingResultItem()
|
|
|
|
}
|
2022-12-14 23:20:51 -05:00
|
|
|
is SearchItemResult.Success -> {
|
2022-11-27 20:56:21 +01:00
|
|
|
if (result.isEmpty) {
|
|
|
|
Text(
|
2022-11-27 15:16:08 -05:00
|
|
|
text = stringResource(R.string.no_results_found),
|
2022-11-27 20:56:21 +01:00
|
|
|
modifier = Modifier
|
|
|
|
.padding(
|
|
|
|
horizontal = MaterialTheme.padding.medium,
|
|
|
|
vertical = MaterialTheme.padding.small,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
return@GlobalSearchResultItem
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalSearchCardRow(
|
|
|
|
titles = result.result,
|
|
|
|
getManga = { getManga(source, it) },
|
|
|
|
onClick = onClickItem,
|
|
|
|
onLongClick = onLongClickItem,
|
|
|
|
)
|
|
|
|
}
|
2023-01-15 10:14:28 -05:00
|
|
|
is SearchItemResult.Error -> {
|
|
|
|
GlobalSearchErrorResultItem(message = result.throwable.message)
|
|
|
|
}
|
2022-11-27 20:56:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|