Minor cleanup

This commit is contained in:
Jobobby04 2025-01-21 18:03:00 -05:00
parent 0a5e9dce24
commit 456db52653
5 changed files with 22 additions and 25 deletions

View File

@ -106,7 +106,7 @@ class ExtensionManager(
}
fun getAppIconForSource(sourceId: Long): Drawable? {
val pkgName = getExtensionPackage(sourceId) ?: return null
val pkgName = getExtensionPackage(sourceId)
if (pkgName != null) {
return iconMap[pkgName] ?: iconMap.getOrPut(pkgName) {

View File

@ -19,7 +19,6 @@ import exh.ui.ifSourcesLoaded
import mihon.presentation.core.util.collectAsLazyPagingItems
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(
@ -62,11 +61,14 @@ class BrowseRecommendsScreen(
Scaffold(
topBar = { scrollBehavior ->
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

@ -50,7 +50,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(),
private 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

@ -23,7 +23,7 @@ import tachiyomi.presentation.core.i18n.stringResource
@Composable
fun RecommendsScreen(
manga: Manga,
manga: Manga?,
state: RecommendsScreenModel.State,
navigateUp: () -> Unit,
getManga: @Composable (Manga) -> State<Manga>,
@ -34,7 +34,7 @@ fun RecommendsScreen(
Scaffold(
topBar = { scrollBehavior ->
AppBar(
title = stringResource(SYMR.strings.similar, manga.title),
title = stringResource(SYMR.strings.similar, manga?.title.orEmpty()),
scrollBehavior = scrollBehavior,
navigateUp = navigateUp,
)