Minor cleanup

(cherry picked from commit 456db526538d67773ee939850fa435d52d785a29)
This commit is contained in:
Jobobby04 2025-01-21 18:03:00 -05:00 committed by Cuong-Tran
parent 0521cb4478
commit 24f7d133f7
No known key found for this signature in database
GPG key ID: 733AA7624B9315C2
4 changed files with 21 additions and 24 deletions

View file

@ -32,7 +32,6 @@ import mihon.presentation.core.util.collectAsLazyPagingItems
import tachiyomi.core.common.util.lang.launchIO
import tachiyomi.domain.manga.model.Manga
import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.i18n.stringResource
import tachiyomi.presentation.core.screens.LoadingScreen
class BrowseRecommendsScreen(
@ -115,11 +114,14 @@ class BrowseRecommendsScreen(
)
} else {
// KMK <--
val recSource = remember { screenModel.recommendationSource }
val title = remember {
val recSource = screenModel.recommendationSource
"${recSource.name} (${recSource.category.getString(context)})"
}
BrowseSourceSimpleToolbar(
navigateUp = navigator::pop,
title = "${recSource.name} (${stringResource(recSource.category)})",
title = title,
displayMode = screenModel.displayMode,
onDisplayModeChange = { screenModel.displayMode = it },
scrollBehavior = scrollBehavior,

View file

@ -72,7 +72,7 @@ class RecommendsScreen(val mangaId: Long, val sourceId: Long) : Screen() {
}
RecommendsScreen(
manga = screenModel.manga,
manga = state.manga,
state = state,
navigateUp = navigator::pop,
getManga = @Composable { manga: Manga -> screenModel.getManga(manga) },

View file

@ -13,8 +13,7 @@ import kotlinx.collections.immutable.mutate
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.collections.immutable.toImmutableMap
import kotlinx.collections.immutable.toPersistentMap
import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.flow.collectLatest
@ -22,7 +21,6 @@ import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import tachiyomi.domain.manga.interactor.GetManga
import tachiyomi.domain.manga.interactor.NetworkToLocalManga
@ -30,22 +28,18 @@ import tachiyomi.domain.manga.model.Manga
import tachiyomi.domain.source.service.SourceManager
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.util.concurrent.Executors
open class RecommendsScreenModel(
val mangaId: Long,
val sourceId: Long,
initialState: State = State(),
sourceManager: SourceManager = Injekt.get(),
private val getManga: GetManga = Injekt.get(),
internal val networkToLocalManga: NetworkToLocalManga = Injekt.get(),
) : StateScreenModel<RecommendsScreenModel.State>(initialState) {
) : StateScreenModel<RecommendsScreenModel.State>(State()) {
val manga = runBlocking { getManga.await(mangaId) }!!
val source = sourceManager.getOrStub(sourceId) as CatalogueSource
private val coroutineDispatcher = Executors.newFixedThreadPool(5).asCoroutineDispatcher()
private var findRecsJob: Job? = null
private val coroutineDispatcher = Dispatchers.IO.limitedParallelism(5)
private val sortComparator = { map: Map<RecommendationPagingSource, RecommendationItemResult> ->
compareBy<RecommendationPagingSource>(
@ -56,17 +50,17 @@ open class RecommendsScreenModel(
}
init {
findRecsJob?.cancel()
ioCoroutineScope.launch {
val manga = getManga.await(mangaId)!!
mutableState.update { it.copy(manga = manga) }
val recommendationSources = RecommendationPagingSource.createSources(manga, source)
val recommendationSources = RecommendationPagingSource.createSources(manga, source)
updateItems(
recommendationSources
.associateWith { RecommendationItemResult.Loading }
.toPersistentMap(),
)
updateItems(
recommendationSources
.associateWith { RecommendationItemResult.Loading }
.toPersistentMap(),
)
findRecsJob = ioCoroutineScope.launch {
recommendationSources.map { recSource ->
async {
if (state.value.items[recSource] !is RecommendationItemResult.Loading) {
@ -132,6 +126,7 @@ open class RecommendsScreenModel(
@Immutable
data class State(
val manga: Manga? = null,
val items: PersistentMap<RecommendationPagingSource, RecommendationItemResult> = persistentMapOf(),
) {
val progress: Int = items.count { it.value !is RecommendationItemResult.Loading }

View file

@ -28,7 +28,7 @@ import tachiyomi.presentation.core.i18n.stringResource
@Composable
fun RecommendsScreen(
manga: Manga,
manga: Manga?,
state: RecommendsScreenModel.State,
navigateUp: () -> Unit,
getManga: @Composable (Manga) -> State<Manga>,
@ -76,7 +76,7 @@ fun RecommendsScreen(
toggleSelectionMode = bulkFavoriteScreenModel::toggleSelectionMode,
isRunning = bulkFavoriteState.isRunning,
// KMK <--
title = stringResource(SYMR.strings.similar, manga.title),
title = stringResource(SYMR.strings.similar, manga?.title.orEmpty()),
scrollBehavior = scrollBehavior,
navigateUp = navigateUp,
)