Fast browse for RecommendsScreen & remove bulk-selection on it

This commit is contained in:
Cuong-Tran 2025-01-24 03:34:50 +07:00
parent aba9faff57
commit 7e16b56911
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
3 changed files with 40 additions and 97 deletions

View file

@ -56,18 +56,37 @@ class RecommendsScreen(val mangaId: Long, val sourceId: Long) : Screen() {
// KMK <--
val onClickItem = { manga: Manga ->
navigator.push(
when (manga.source) {
-1L -> SourcesScreen(SourcesScreen.SmartSearchConfig(manga.ogTitle))
else -> MangaScreen(manga.id, true)
},
-1L -> navigator.push(
SourcesScreen(SourcesScreen.SmartSearchConfig(manga.ogTitle)),
)
else -> {
// KMK -->
scope.launchIO {
val localManga = screenModel.networkToLocalManga.getLocal(manga)
navigator.push(
// KMK <--
MangaScreen(localManga.id, true),
)
}
}
}
}
val onLongClickItem = { manga: Manga ->
when (manga.source) {
-1L -> WebViewActivity.newIntent(context, manga.url, title = manga.title).let(context::startActivity)
else -> onClickItem(manga)
else -> {
// KMK -->
scope.launchIO {
val localManga = screenModel.networkToLocalManga.getLocal(manga)
bulkFavoriteScreenModel.addRemoveManga(
localManga,
haptic,
)
}
// KMK <--
}
}
}
@ -87,33 +106,8 @@ class RecommendsScreen(val mangaId: Long, val sourceId: Long) : Screen() {
),
)
},
onClickItem = {
// KMK -->
scope.launchIO {
val manga = screenModel.networkToLocalManga.getLocal(it)
if (bulkFavoriteState.selectionMode) {
bulkFavoriteScreenModel.toggleSelection(manga)
} else {
// KMK <--
onClickItem(manga)
}
}
},
onLongClickItem = {
// KMK -->
scope.launchIO {
val manga = screenModel.networkToLocalManga.getLocal(it)
if (!bulkFavoriteState.selectionMode) {
bulkFavoriteScreenModel.addRemoveManga(manga, haptic)
} else {
// KMK <--
onLongClickItem(manga)
}
}
},
// KMK -->
bulkFavoriteScreenModel = bulkFavoriteScreenModel,
// KMK <--
onClickItem = { onClickItem(it) },
onLongClickItem = { onLongClickItem(it) },
)
// KMK -->

View file

@ -74,13 +74,11 @@ open class RecommendsScreenModel(
val titles = page.mangas.map {
val recSourceId = recSource.associatedSourceId
if (recSourceId != null) {
// KMK -->
// If the recommendation is associated with a source, resolve it
networkToLocalManga.await(it.toDomainManga(recSourceId))
} else {
// Otherwise, skip this step. The user will be prompted to choose a source via SmartSearch
it.toDomainManga(-1)
}
it.toDomainManga(recSourceId ?: -1)
// KMK <--
}
if (isActive) {

View file

@ -4,18 +4,13 @@ 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.components.AppBar
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
@ -35,52 +30,14 @@ fun RecommendsScreen(
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 <--
AppBar(
title = stringResource(SYMR.strings.similar, manga?.title.orEmpty()),
scrollBehavior = scrollBehavior,
navigateUp = navigateUp,
)
}
},
) { paddingValues ->
RecommendsContent(
@ -90,9 +47,6 @@ fun RecommendsScreen(
onClickSource = onClickSource,
onClickItem = onClickItem,
onLongClickItem = onLongClickItem,
// KMK -->
selection = bulkFavoriteState.selection,
// KMK <--
)
}
}
@ -105,9 +59,6 @@ internal fun RecommendsContent(
onClickSource: (RecommendationPagingSource) -> Unit,
onClickItem: (Manga) -> Unit,
onLongClickItem: (Manga) -> Unit,
// KMK -->
selection: List<Manga>,
// KMK <--
) {
LazyColumn(
contentPadding = contentPadding,
@ -130,7 +81,7 @@ internal fun RecommendsContent(
onClick = onClickItem,
onLongClick = onLongClickItem,
// KMK -->
selection = selection,
selection = emptyList(),
// KMK <--
)
}