From dd17832428efe49cccd24cafd830e47b1ffe7a37 Mon Sep 17 00:00:00 2001 From: Secozzi Date: Mon, 28 Oct 2024 11:57:58 +0100 Subject: [PATCH] Add stable marker to Manga data class Co-authored-by: ivan <12537387+ivaniskandar@users.noreply.github.com> Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../presentation/entries/anime/AnimeScreen.kt | 12 +-- .../anime/components/AnimeCoverDialog.kt | 4 +- .../anime/components/AnimeInfoHeader.kt | 85 +++++++++---------- .../presentation/entries/manga/MangaScreen.kt | 12 +-- .../manga/components/MangaCoverDialog.kt | 4 +- .../manga/components/MangaInfoHeader.kt | 85 +++++++++---------- .../tachiyomi/ui/entries/anime/AnimeScreen.kt | 2 +- .../tachiyomi/ui/entries/manga/MangaScreen.kt | 2 +- domain/build.gradle.kts | 2 + .../domain/entries/anime/model/Anime.kt | 2 + .../domain/entries/manga/model/Manga.kt | 2 + gradle/libs.versions.toml | 1 + 12 files changed, 93 insertions(+), 120 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt b/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt index 48f6929d4..eae574b70 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/anime/AnimeScreen.kt @@ -427,13 +427,9 @@ private fun AnimeScreenSmallImpl( AnimeInfoBox( isTabletUi = false, appBarPadding = topPadding, - title = state.anime.title, - author = state.anime.author, - artist = state.anime.artist, + anime = state.anime, sourceName = remember { state.source.getNameForAnimeInfo() }, isStubSource = remember { state.source is StubAnimeSource }, - coverDataProvider = { state.anime }, - status = state.anime.status, onCoverClick = onCoverClicked, doSearch = onSearch, ) @@ -708,13 +704,9 @@ fun AnimeScreenLargeImpl( AnimeInfoBox( isTabletUi = true, appBarPadding = contentPadding.calculateTopPadding(), - title = state.anime.title, - author = state.anime.author, - artist = state.anime.artist, + anime = state.anime, sourceName = remember { state.source.getNameForAnimeInfo() }, isStubSource = remember { state.source is StubAnimeSource }, - coverDataProvider = { state.anime }, - status = state.anime.status, onCoverClick = onCoverClicked, doSearch = onSearch, ) diff --git a/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeCoverDialog.kt b/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeCoverDialog.kt index 901235c98..2130d348d 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeCoverDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeCoverDialog.kt @@ -56,7 +56,7 @@ import tachiyomi.presentation.core.util.clickableNoIndication @Composable fun AnimeCoverDialog( - coverDataProvider: () -> Anime, + anime: Anime, isCustomCover: Boolean, snackbarHostState: SnackbarHostState, onShareClick: () -> Unit, @@ -168,7 +168,7 @@ fun AnimeCoverDialog( }, update = { view -> val request = ImageRequest.Builder(view.context) - .data(coverDataProvider()) + .data(anime) .size(Size.ORIGINAL) .memoryCachePolicy(CachePolicy.DISABLED) .target { image -> diff --git a/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeInfoHeader.kt index 75847645d..95c12c9c1 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/anime/components/AnimeInfoHeader.kt @@ -75,6 +75,8 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil3.compose.AsyncImage +import coil3.request.ImageRequest +import coil3.request.crossfade import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.entries.components.DotSeparatorText import eu.kanade.presentation.entries.components.ItemCover @@ -100,13 +102,9 @@ private val whitespaceLineRegex = Regex("[\\r\\n]{2,}", setOf(RegexOption.MULTIL fun AnimeInfoBox( isTabletUi: Boolean, appBarPadding: Dp, - title: String, - author: String?, - artist: String?, + anime: Anime, sourceName: String, isStubSource: Boolean, - coverDataProvider: () -> Anime, - status: Long, onCoverClick: () -> Unit, doSearch: (query: String, global: Boolean) -> Unit, modifier: Modifier = Modifier, @@ -118,7 +116,10 @@ fun AnimeInfoBox( MaterialTheme.colorScheme.background, ) AsyncImage( - model = coverDataProvider(), + model = ImageRequest.Builder(LocalContext.current) + .data(anime) + .crossfade(true) + .build(), contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier @@ -138,28 +139,20 @@ fun AnimeInfoBox( if (!isTabletUi) { AnimeAndSourceTitlesSmall( appBarPadding = appBarPadding, - coverDataProvider = coverDataProvider, - onCoverClick = onCoverClick, - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + anime = anime, sourceName = sourceName, isStubSource = isStubSource, + onCoverClick = onCoverClick, + doSearch = doSearch, ) } else { AnimeAndSourceTitlesLarge( appBarPadding = appBarPadding, - coverDataProvider = coverDataProvider, - onCoverClick = onCoverClick, - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + anime = anime, sourceName = sourceName, isStubSource = isStubSource, + onCoverClick = onCoverClick, + doSearch = doSearch, ) } } @@ -343,15 +336,11 @@ fun ExpandableAnimeDescription( @Composable private fun AnimeAndSourceTitlesLarge( appBarPadding: Dp, - coverDataProvider: () -> Anime, - onCoverClick: () -> Unit, - title: String, - doSearch: (query: String, global: Boolean) -> Unit, - author: String?, - artist: String?, - status: Long, + anime: Anime, sourceName: String, isStubSource: Boolean, + onCoverClick: () -> Unit, + doSearch: (query: String, global: Boolean) -> Unit, ) { Column( modifier = Modifier @@ -361,19 +350,22 @@ private fun AnimeAndSourceTitlesLarge( ) { ItemCover.Book( modifier = Modifier.fillMaxWidth(0.65f), - data = coverDataProvider(), + data = ImageRequest.Builder(LocalContext.current) + .data(anime) + .crossfade(true) + .build(), contentDescription = stringResource(MR.strings.manga_cover), onClick = onCoverClick, ) Spacer(modifier = Modifier.height(16.dp)) AnimeContentInfo( - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + title = anime.title, + author = anime.author, + artist = anime.artist, + status = anime.status, sourceName = sourceName, isStubSource = isStubSource, + doSearch = doSearch, textAlign = TextAlign.Center, ) } @@ -382,15 +374,11 @@ private fun AnimeAndSourceTitlesLarge( @Composable private fun AnimeAndSourceTitlesSmall( appBarPadding: Dp, - coverDataProvider: () -> Anime, - onCoverClick: () -> Unit, - title: String, - doSearch: (query: String, global: Boolean) -> Unit, - author: String?, - artist: String?, - status: Long, + anime: Anime, sourceName: String, isStubSource: Boolean, + onCoverClick: () -> Unit, + doSearch: (query: String, global: Boolean) -> Unit, ) { Row( modifier = Modifier @@ -403,7 +391,10 @@ private fun AnimeAndSourceTitlesSmall( modifier = Modifier .sizeIn(maxWidth = 100.dp) .align(Alignment.Top), - data = coverDataProvider(), + data = ImageRequest.Builder(LocalContext.current) + .data(anime) + .crossfade(true) + .build(), contentDescription = stringResource(MR.strings.manga_cover), onClick = onCoverClick, ) @@ -411,13 +402,13 @@ private fun AnimeAndSourceTitlesSmall( verticalArrangement = Arrangement.spacedBy(2.dp), ) { AnimeContentInfo( - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + title = anime.title, + author = anime.author, + artist = anime.artist, + status = anime.status, sourceName = sourceName, isStubSource = isStubSource, + doSearch = doSearch, ) } } @@ -426,12 +417,12 @@ private fun AnimeAndSourceTitlesSmall( @Composable private fun ColumnScope.AnimeContentInfo( title: String, - doSearch: (query: String, global: Boolean) -> Unit, author: String?, artist: String?, status: Long, sourceName: String, isStubSource: Boolean, + doSearch: (query: String, global: Boolean) -> Unit, textAlign: TextAlign? = LocalTextStyle.current.textAlign, ) { val context = LocalContext.current diff --git a/app/src/main/java/eu/kanade/presentation/entries/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/presentation/entries/manga/MangaScreen.kt index 7e0787778..78e0e3343 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/manga/MangaScreen.kt @@ -397,13 +397,9 @@ private fun MangaScreenSmallImpl( MangaInfoBox( isTabletUi = false, appBarPadding = topPadding, - title = state.manga.title, - author = state.manga.author, - artist = state.manga.artist, + manga = state.manga, sourceName = remember { state.source.getNameForMangaInfo() }, isStubSource = remember { state.source is StubMangaSource }, - coverDataProvider = { state.manga }, - status = state.manga.status, onCoverClick = onCoverClicked, doSearch = onSearch, ) @@ -644,13 +640,9 @@ fun MangaScreenLargeImpl( MangaInfoBox( isTabletUi = true, appBarPadding = contentPadding.calculateTopPadding(), - title = state.manga.title, - author = state.manga.author, - artist = state.manga.artist, + manga = state.manga, sourceName = remember { state.source.getNameForMangaInfo() }, isStubSource = remember { state.source is StubMangaSource }, - coverDataProvider = { state.manga }, - status = state.manga.status, onCoverClick = onCoverClicked, doSearch = onSearch, ) diff --git a/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaCoverDialog.kt b/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaCoverDialog.kt index eabe209ce..d88de54d8 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaCoverDialog.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaCoverDialog.kt @@ -56,7 +56,7 @@ import tachiyomi.presentation.core.util.clickableNoIndication @Composable fun MangaCoverDialog( - coverDataProvider: () -> Manga, + manga: Manga, isCustomCover: Boolean, snackbarHostState: SnackbarHostState, onShareClick: () -> Unit, @@ -168,7 +168,7 @@ fun MangaCoverDialog( }, update = { view -> val request = ImageRequest.Builder(view.context) - .data(coverDataProvider()) + .data(manga) .size(Size.ORIGINAL) .memoryCachePolicy(CachePolicy.DISABLED) .target { image -> diff --git a/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaInfoHeader.kt b/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaInfoHeader.kt index c4f171853..2b8824e6c 100644 --- a/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaInfoHeader.kt +++ b/app/src/main/java/eu/kanade/presentation/entries/manga/components/MangaInfoHeader.kt @@ -75,6 +75,8 @@ import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import coil3.compose.AsyncImage +import coil3.request.ImageRequest +import coil3.request.crossfade import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.entries.components.DotSeparatorText import eu.kanade.presentation.entries.components.ItemCover @@ -100,13 +102,9 @@ private val whitespaceLineRegex = Regex("[\\r\\n]{2,}", setOf(RegexOption.MULTIL fun MangaInfoBox( isTabletUi: Boolean, appBarPadding: Dp, - title: String, - author: String?, - artist: String?, + manga: Manga, sourceName: String, isStubSource: Boolean, - coverDataProvider: () -> Manga, - status: Long, onCoverClick: () -> Unit, doSearch: (query: String, global: Boolean) -> Unit, modifier: Modifier = Modifier, @@ -118,7 +116,10 @@ fun MangaInfoBox( MaterialTheme.colorScheme.background, ) AsyncImage( - model = coverDataProvider(), + model = ImageRequest.Builder(LocalContext.current) + .data(manga) + .crossfade(true) + .build(), contentDescription = null, contentScale = ContentScale.Crop, modifier = Modifier @@ -138,28 +139,20 @@ fun MangaInfoBox( if (!isTabletUi) { MangaAndSourceTitlesSmall( appBarPadding = appBarPadding, - coverDataProvider = coverDataProvider, - onCoverClick = onCoverClick, - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + manga = manga, sourceName = sourceName, isStubSource = isStubSource, + onCoverClick = onCoverClick, + doSearch = doSearch, ) } else { MangaAndSourceTitlesLarge( appBarPadding = appBarPadding, - coverDataProvider = coverDataProvider, - onCoverClick = onCoverClick, - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + manga = manga, sourceName = sourceName, isStubSource = isStubSource, + onCoverClick = onCoverClick, + doSearch = doSearch, ) } } @@ -342,15 +335,11 @@ fun ExpandableMangaDescription( @Composable private fun MangaAndSourceTitlesLarge( appBarPadding: Dp, - coverDataProvider: () -> Manga, - onCoverClick: () -> Unit, - title: String, - doSearch: (query: String, global: Boolean) -> Unit, - author: String?, - artist: String?, - status: Long, + manga: Manga, sourceName: String, isStubSource: Boolean, + onCoverClick: () -> Unit, + doSearch: (query: String, global: Boolean) -> Unit, ) { Column( modifier = Modifier @@ -360,19 +349,22 @@ private fun MangaAndSourceTitlesLarge( ) { ItemCover.Book( modifier = Modifier.fillMaxWidth(0.65f), - data = coverDataProvider(), + data = ImageRequest.Builder(LocalContext.current) + .data(manga) + .crossfade(true) + .build(), contentDescription = stringResource(MR.strings.manga_cover), onClick = onCoverClick, ) Spacer(modifier = Modifier.height(16.dp)) MangaContentInfo( - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + title = manga.title, + author = manga.author, + artist = manga.artist, + status = manga.status, sourceName = sourceName, isStubSource = isStubSource, + doSearch = doSearch, textAlign = TextAlign.Center, ) } @@ -381,15 +373,11 @@ private fun MangaAndSourceTitlesLarge( @Composable private fun MangaAndSourceTitlesSmall( appBarPadding: Dp, - coverDataProvider: () -> Manga, - onCoverClick: () -> Unit, - title: String, - doSearch: (query: String, global: Boolean) -> Unit, - author: String?, - artist: String?, - status: Long, + manga: Manga, sourceName: String, isStubSource: Boolean, + onCoverClick: () -> Unit, + doSearch: (query: String, global: Boolean) -> Unit, ) { Row( modifier = Modifier @@ -402,7 +390,10 @@ private fun MangaAndSourceTitlesSmall( modifier = Modifier .sizeIn(maxWidth = 100.dp) .align(Alignment.Top), - data = coverDataProvider(), + data = ImageRequest.Builder(LocalContext.current) + .data(manga) + .crossfade(true) + .build(), contentDescription = stringResource(MR.strings.manga_cover), onClick = onCoverClick, ) @@ -410,13 +401,13 @@ private fun MangaAndSourceTitlesSmall( verticalArrangement = Arrangement.spacedBy(2.dp), ) { MangaContentInfo( - title = title, - doSearch = doSearch, - author = author, - artist = artist, - status = status, + title = manga.title, + author = manga.author, + artist = manga.artist, + status = manga.status, sourceName = sourceName, isStubSource = isStubSource, + doSearch = doSearch, ) } } @@ -425,12 +416,12 @@ private fun MangaAndSourceTitlesSmall( @Composable private fun ColumnScope.MangaContentInfo( title: String, - doSearch: (query: String, global: Boolean) -> Unit, author: String?, artist: String?, status: Long, sourceName: String, isStubSource: Boolean, + doSearch: (query: String, global: Boolean) -> Unit, textAlign: TextAlign? = LocalTextStyle.current.textAlign, ) { val context = LocalContext.current diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt index 4562acf45..596fdb26a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/anime/AnimeScreen.kt @@ -277,7 +277,7 @@ class AnimeScreen( sm.editCover(context, it) } AnimeCoverDialog( - coverDataProvider = { anime!! }, + anime = anime!!, snackbarHostState = sm.snackbarHostState, isCustomCover = remember(anime) { anime!!.hasCustomCover() }, onShareClick = { sm.shareCover(context) }, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt index 120d1bb40..4e17f9bbb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/entries/manga/MangaScreen.kt @@ -261,7 +261,7 @@ class MangaScreen( sm.editCover(context, it) } MangaCoverDialog( - coverDataProvider = { manga!! }, + manga = manga!!, snackbarHostState = sm.snackbarHostState, isCustomCover = remember(manga) { manga!!.hasCustomCover() }, onShareClick = { sm.shareCover(context) }, diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index 031eb4044..da4b6c942 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -25,6 +25,8 @@ dependencies { api(libs.sqldelight.android.paging) + compileOnly(libs.compose.stablemarker) + testImplementation(libs.bundles.test) testImplementation(kotlinx.coroutines.test) } diff --git a/domain/src/main/java/tachiyomi/domain/entries/anime/model/Anime.kt b/domain/src/main/java/tachiyomi/domain/entries/anime/model/Anime.kt index d8ff87aae..3f4335c15 100644 --- a/domain/src/main/java/tachiyomi/domain/entries/anime/model/Anime.kt +++ b/domain/src/main/java/tachiyomi/domain/entries/anime/model/Anime.kt @@ -1,5 +1,6 @@ package tachiyomi.domain.entries.anime.model +import androidx.compose.runtime.Immutable import eu.kanade.tachiyomi.animesource.model.AnimeUpdateStrategy import eu.kanade.tachiyomi.animesource.model.SAnime import tachiyomi.core.common.preference.TriState @@ -7,6 +8,7 @@ import java.io.Serializable import java.time.Instant import kotlin.math.pow +@Immutable data class Anime( val id: Long, val source: Long, diff --git a/domain/src/main/java/tachiyomi/domain/entries/manga/model/Manga.kt b/domain/src/main/java/tachiyomi/domain/entries/manga/model/Manga.kt index fd8d920c6..f214a33a1 100644 --- a/domain/src/main/java/tachiyomi/domain/entries/manga/model/Manga.kt +++ b/domain/src/main/java/tachiyomi/domain/entries/manga/model/Manga.kt @@ -1,11 +1,13 @@ package tachiyomi.domain.entries.manga.model +import androidx.compose.runtime.Immutable import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.UpdateStrategy import tachiyomi.core.common.preference.TriState import java.io.Serializable import java.time.Instant +@Immutable data class Manga( val id: Long, val source: Long, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6efb2b727..9d8450dc9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -63,6 +63,7 @@ insetter = "dev.chrisbanes.insetter:insetter:0.6.1" compose-materialmotion = "io.github.fornewid:material-motion-compose-core:2.0.1" compose-webview = "io.github.kevinnzou:compose-webview:0.33.6" compose-grid = "io.woong.compose.grid:grid:1.2.2" +compose-stablemarker = "com.github.skydoves:compose-stable-marker:1.0.5" swipe = "me.saket.swipe:swipe:1.3.0"