From 0aa78c0d7e8036a91d1c83a920e7ee670904f72e Mon Sep 17 00:00:00 2001 From: Koitharu Date: Mon, 13 Jan 2025 19:54:10 +0200 Subject: [PATCH] Adjust manga fields nullability --- .../kotatsu/core/db/entity/EntityMapping.kt | 2 +- .../kotatsu/core/db/entity/MangaEntity.kt | 2 +- .../external/ExternalPluginContentSource.kt | 2 +- .../koitharu/kotatsu/core/util/ext/String.kt | 2 +- .../kotatsu/details/ui/DetailsActivity.kt | 2 +- .../download/ui/worker/DownloadWorker.kt | 2 +- .../kotatsu/favourites/domain/model/Cover.kt | 2 +- .../list/ui/model/MangaCompactListModel.kt | 2 +- .../list/ui/model/MangaDetailedListModel.kt | 2 +- .../kotatsu/list/ui/model/MangaGridModel.kt | 2 +- .../kotatsu/list/ui/model/MangaListModel.kt | 2 +- .../list/ui/preview/PreviewFragment.kt | 2 +- .../local/data/input/LocalMangaParser.kt | 44 +------------------ .../kotatsu/tracker/ui/feed/model/FeedItem.kt | 2 +- 14 files changed, 15 insertions(+), 55 deletions(-) diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt index 63a5ff2f4..55a5cf020 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/EntityMapping.kt @@ -49,7 +49,7 @@ fun Manga.toEntity() = MangaEntity( publicUrl = publicUrl, source = source.name, largeCoverUrl = largeCoverUrl, - coverUrl = coverUrl, + coverUrl = coverUrl.orEmpty(), altTitle = altTitle, rating = rating, isNsfw = isNsfw, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaEntity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaEntity.kt index e2c474399..9156db7b7 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaEntity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/db/entity/MangaEntity.kt @@ -14,7 +14,7 @@ data class MangaEntity( @ColumnInfo(name = "url") val url: String, @ColumnInfo(name = "public_url") val publicUrl: String, @ColumnInfo(name = "rating") val rating: Float, // normalized value [0..1] or -1 - @ColumnInfo(name = "nsfw") val isNsfw: Boolean, + @ColumnInfo(name = "nsfw") val isNsfw: Boolean, // TODO change to contentRating @ColumnInfo(name = "cover_url") val coverUrl: String, @ColumnInfo(name = "large_cover_url") val largeCoverUrl: String?, @ColumnInfo(name = "state") val state: String?, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/external/ExternalPluginContentSource.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/external/ExternalPluginContentSource.kt index a0ca968e2..f59514e90 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/external/ExternalPluginContentSource.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/parser/external/ExternalPluginContentSource.kt @@ -82,7 +82,7 @@ class ExternalPluginContentSource( publicUrl = details.publicUrl.ifEmpty { manga.publicUrl }, rating = maxOf(details.rating, manga.rating), isNsfw = details.isNsfw, - coverUrl = details.coverUrl.ifEmpty { manga.coverUrl }, + coverUrl = details.coverUrl.ifNullOrEmpty { manga.coverUrl }, tags = details.tags + manga.tags, state = details.state ?: manga.state, author = details.author.ifNullOrEmpty { manga.author }, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/String.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/String.kt index 3294e66fb..dfc16562e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/String.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/util/ext/String.kt @@ -8,7 +8,7 @@ import org.koitharu.kotatsu.parsers.util.ellipsize import org.koitharu.kotatsu.parsers.util.levenshteinDistance import java.util.UUID -inline fun C?.ifNullOrEmpty(defaultValue: () -> C): C { +inline fun C?.ifNullOrEmpty(defaultValue: () -> R): R { return if (this.isNullOrEmpty()) defaultValue() else this } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index 720d33f28..5da9cba05 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -274,7 +274,7 @@ class DetailsActivity : startActivity( ImageActivity.newIntent( v.context, - manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }, + manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl } ?: return, manga.source, ), scaleUpActivityOptionsOf(v), diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt index 8aed8f1d4..a52c1c343 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/download/ui/worker/DownloadWorker.kt @@ -199,7 +199,7 @@ class DownloadWorker @AssistedInject constructor( format = task.format ?: settings.preferredDownloadFormat, ) val coverUrl = mangaDetails.largeCoverUrl.ifNullOrEmpty { mangaDetails.coverUrl } - if (coverUrl.isNotEmpty()) { + if (!coverUrl.isNullOrEmpty()) { downloadFile(coverUrl, destination, repo.source).let { file -> output.addCover(file, MimeTypeMap.getFileExtensionFromUrl(coverUrl)) file.deleteAwait() diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt index 32c0d4c0f..d5521d410 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/favourites/domain/model/Cover.kt @@ -3,7 +3,7 @@ package org.koitharu.kotatsu.favourites.domain.model import org.koitharu.kotatsu.core.model.MangaSource data class Cover( - val url: String, + val url: String?, val source: String, ) { val mangaSource by lazy { MangaSource(source) } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaCompactListModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaCompactListModel.kt index fae6ccfb1..d7c122492 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaCompactListModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaCompactListModel.kt @@ -7,7 +7,7 @@ data class MangaCompactListModel( override val id: Long, override val title: String, val subtitle: String, - override val coverUrl: String, + override val coverUrl: String?, override val manga: Manga, override val counter: Int, override val progress: ReadingProgress?, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaDetailedListModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaDetailedListModel.kt index 8b6633788..ee83aa9b8 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaDetailedListModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaDetailedListModel.kt @@ -8,7 +8,7 @@ data class MangaDetailedListModel( override val id: Long, override val title: String, val subtitle: String?, - override val coverUrl: String, + override val coverUrl: String?, override val manga: Manga, override val counter: Int, override val progress: ReadingProgress?, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaGridModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaGridModel.kt index 244c3f7b7..52007c3b5 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaGridModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaGridModel.kt @@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga data class MangaGridModel( override val id: Long, override val title: String, - override val coverUrl: String, + override val coverUrl: String?, override val manga: Manga, override val counter: Int, override val progress: ReadingProgress?, diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaListModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaListModel.kt index 322bf0b6a..4afb11370 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaListModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/model/MangaListModel.kt @@ -11,7 +11,7 @@ sealed class MangaListModel : ListModel { abstract val id: Long abstract val manga: Manga abstract val title: String - abstract val coverUrl: String + abstract val coverUrl: String? abstract val counter: Int abstract val isFavorite: Boolean abstract val progress: ReadingProgress? diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt index 549544996..cee84e64c 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/list/ui/preview/PreviewFragment.kt @@ -100,7 +100,7 @@ class PreviewFragment : BaseFragment(), View.OnClickList R.id.imageView_cover -> startActivity( ImageActivity.newIntent( v.context, - manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }, + manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl } ?: return, manga.source, ), scaleUpActivityOptionsOf(v), diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaParser.kt b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaParser.kt index 740e2e150..83d697a42 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaParser.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/local/data/input/LocalMangaParser.kt @@ -33,7 +33,6 @@ import org.koitharu.kotatsu.local.domain.model.LocalManga import org.koitharu.kotatsu.parsers.model.Manga import org.koitharu.kotatsu.parsers.model.MangaChapter import org.koitharu.kotatsu.parsers.model.MangaPage -import org.koitharu.kotatsu.parsers.model.MangaSource import org.koitharu.kotatsu.parsers.util.runCatchingCancellable import org.koitharu.kotatsu.parsers.util.toFileNameSafe import java.io.File @@ -60,7 +59,7 @@ class LocalMangaParser(private val uri: Uri) { val mangaInfo = index?.getMangaInfo() if (mangaInfo != null) { val coverEntry: Path? = index.getCoverEntry()?.let { rootPath / it } ?: fileSystem.findFirstImage(rootPath) - mangaInfo.copyInternal( + mangaInfo.copy( source = LocalMangaSource, url = rootFile.toUri().toString(), coverUrl = coverEntry?.let { uri.child(it, resolve = true).toString() }.orEmpty(), @@ -71,7 +70,7 @@ class LocalMangaParser(private val uri: Uri) { if (path != null && !fileSystem.exists(rootPath / path)) { null } else { - c.copyInternal( + c.copy( url = path?.let { uri.child(it, resolve = false).toString() } ?: uri.toString(), @@ -277,44 +276,5 @@ class LocalMangaParser(private val uri: Uri) { private fun String.fileNameToTitle() = substringBeforeLast('.') .replace('_', ' ') .replaceFirstChar { it.uppercase() } - - private fun Manga.copyInternal( - url: String = this.url, - coverUrl: String = this.coverUrl, - largeCoverUrl: String? = this.largeCoverUrl, - chapters: List? = this.chapters, - source: MangaSource = this.source, - ): Manga = Manga( - id = id, - title = title, - altTitle = altTitle, - url = url, - publicUrl = publicUrl, - rating = rating, - isNsfw = isNsfw, - coverUrl = coverUrl, - tags = tags, - state = state, - author = author, - largeCoverUrl = largeCoverUrl, - description = description, - chapters = chapters, - source = source, - ) - - private fun MangaChapter.copyInternal( - url: String = this.url, - source: MangaSource = this.source, - ) = MangaChapter( - id = id, - name = name, - number = number, - volume = volume, - url = url, - scanlator = scanlator, - uploadDate = uploadDate, - branch = branch, - source = source, - ) } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/model/FeedItem.kt b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/model/FeedItem.kt index bf9510a51..4aac9f87e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/model/FeedItem.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/tracker/ui/feed/model/FeedItem.kt @@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga data class FeedItem( val id: Long, - val imageUrl: String, + val imageUrl: String?, val title: String, val manga: Manga, val count: Int,