149 lines
5.9 KiB
Kotlin
149 lines
5.9 KiB
Kotlin
package exh.recs.components
|
|
|
|
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 androidx.compose.ui.platform.LocalContext
|
|
import eu.kanade.presentation.browse.components.BrowseSourceSimpleToolbar
|
|
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.components.BulkSelectionToolbar
|
|
import eu.kanade.presentation.util.formattedMessage
|
|
import eu.kanade.tachiyomi.ui.browse.BulkFavoriteScreenModel
|
|
import eu.kanade.tachiyomi.ui.browse.source.globalsearch.SearchItemResult
|
|
import exh.recs.RecommendationItemResult
|
|
import exh.recs.RecommendsScreenModel
|
|
import exh.recs.sources.RecommendationPagingSource
|
|
import kotlinx.collections.immutable.ImmutableMap
|
|
import nl.adaptivity.xmlutil.core.impl.multiplatform.name
|
|
import tachiyomi.domain.manga.model.Manga
|
|
import tachiyomi.i18n.sy.SYMR
|
|
import tachiyomi.presentation.core.components.material.Scaffold
|
|
import tachiyomi.presentation.core.i18n.stringResource
|
|
|
|
@Composable
|
|
fun RecommendsScreen(
|
|
manga: Manga?,
|
|
state: RecommendsScreenModel.State,
|
|
navigateUp: () -> Unit,
|
|
getManga: @Composable (Manga) -> State<Manga>,
|
|
onClickSource: (RecommendationPagingSource) -> 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) {
|
|
BulkSelectionToolbar(
|
|
selectedCount = bulkFavoriteState.selection.size,
|
|
isRunning = bulkFavoriteState.isRunning,
|
|
onClickClearSelection = bulkFavoriteScreenModel::toggleSelectionMode,
|
|
onChangeCategoryClick = bulkFavoriteScreenModel::addFavorite,
|
|
onSelectAll = {
|
|
state.filteredItems.forEach { (_, result) ->
|
|
if (result is RecommendationItemResult.Success) {
|
|
result.result.forEach { manga ->
|
|
bulkFavoriteScreenModel.select(manga)
|
|
}
|
|
}
|
|
}
|
|
},
|
|
onReverseSelection = {
|
|
bulkFavoriteScreenModel.reverseSelection(
|
|
state.filteredItems.values
|
|
.filterIsInstance<SearchItemResult.Success>()
|
|
.flatMap { it.result },
|
|
)
|
|
},
|
|
)
|
|
} else {
|
|
BrowseSourceSimpleToolbar(
|
|
displayMode = null,
|
|
onDisplayModeChange = {},
|
|
toggleSelectionMode = bulkFavoriteScreenModel::toggleSelectionMode,
|
|
isRunning = bulkFavoriteState.isRunning,
|
|
// KMK <--
|
|
title = stringResource(SYMR.strings.similar, manga?.title.orEmpty()),
|
|
scrollBehavior = scrollBehavior,
|
|
navigateUp = navigateUp,
|
|
)
|
|
}
|
|
},
|
|
) { paddingValues ->
|
|
RecommendsContent(
|
|
items = state.filteredItems,
|
|
contentPadding = paddingValues,
|
|
getManga = getManga,
|
|
onClickSource = onClickSource,
|
|
onClickItem = onClickItem,
|
|
onLongClickItem = onLongClickItem,
|
|
// KMK -->
|
|
selection = bulkFavoriteState.selection,
|
|
// KMK <--
|
|
)
|
|
}
|
|
}
|
|
|
|
@Composable
|
|
internal fun RecommendsContent(
|
|
items: ImmutableMap<RecommendationPagingSource, RecommendationItemResult>,
|
|
contentPadding: PaddingValues,
|
|
getManga: @Composable (Manga) -> State<Manga>,
|
|
onClickSource: (RecommendationPagingSource) -> Unit,
|
|
onClickItem: (Manga) -> Unit,
|
|
onLongClickItem: (Manga) -> Unit,
|
|
// KMK -->
|
|
selection: List<Manga>,
|
|
// KMK <--
|
|
) {
|
|
LazyColumn(
|
|
contentPadding = contentPadding,
|
|
) {
|
|
items.forEach { (source, recResult) ->
|
|
item(key = source::class.name) {
|
|
GlobalSearchResultItem(
|
|
title = source.name,
|
|
subtitle = stringResource(source.category),
|
|
onClick = { onClickSource(source) },
|
|
) {
|
|
when (recResult) {
|
|
RecommendationItemResult.Loading -> {
|
|
GlobalSearchLoadingResultItem()
|
|
}
|
|
is RecommendationItemResult.Success -> {
|
|
GlobalSearchCardRow(
|
|
titles = recResult.result,
|
|
getManga = getManga,
|
|
onClick = onClickItem,
|
|
onLongClick = onLongClickItem,
|
|
// KMK -->
|
|
selection = selection,
|
|
// KMK <--
|
|
)
|
|
}
|
|
is RecommendationItemResult.Error -> {
|
|
GlobalSearchErrorResultItem(
|
|
message = with(LocalContext.current) {
|
|
recResult.throwable.formattedMessage
|
|
},
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|