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? { fun getAppIconForSource(sourceId: Long): Drawable? {
val pkgName = getExtensionPackage(sourceId) ?: return null val pkgName = getExtensionPackage(sourceId)
if (pkgName != null) { if (pkgName != null) {
return iconMap[pkgName] ?: iconMap.getOrPut(pkgName) { return iconMap[pkgName] ?: iconMap.getOrPut(pkgName) {

View File

@ -19,7 +19,6 @@ import exh.ui.ifSourcesLoaded
import mihon.presentation.core.util.collectAsLazyPagingItems import mihon.presentation.core.util.collectAsLazyPagingItems
import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.manga.model.Manga
import tachiyomi.presentation.core.components.material.Scaffold import tachiyomi.presentation.core.components.material.Scaffold
import tachiyomi.presentation.core.i18n.stringResource
import tachiyomi.presentation.core.screens.LoadingScreen import tachiyomi.presentation.core.screens.LoadingScreen
class BrowseRecommendsScreen( class BrowseRecommendsScreen(
@ -62,11 +61,14 @@ class BrowseRecommendsScreen(
Scaffold( Scaffold(
topBar = { scrollBehavior -> topBar = { scrollBehavior ->
val recSource = remember { screenModel.recommendationSource } val title = remember {
val recSource = screenModel.recommendationSource
"${recSource.name} (${recSource.category.getString(context)})"
}
BrowseSourceSimpleToolbar( BrowseSourceSimpleToolbar(
navigateUp = navigator::pop, navigateUp = navigator::pop,
title = "${recSource.name} (${stringResource(recSource.category)})", title = title,
displayMode = screenModel.displayMode, displayMode = screenModel.displayMode,
onDisplayModeChange = { screenModel.displayMode = it }, onDisplayModeChange = { screenModel.displayMode = it },
scrollBehavior = scrollBehavior, scrollBehavior = scrollBehavior,

View File

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

View File

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