Adjust manga fields nullability

This commit is contained in:
Koitharu
2025-01-13 19:54:10 +02:00
parent 8e1d02f356
commit 0aa78c0d7e
14 changed files with 15 additions and 55 deletions

View File

@@ -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,

View File

@@ -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?,

View File

@@ -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 },

View File

@@ -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 : CharSequence?> C?.ifNullOrEmpty(defaultValue: () -> C): C {
inline fun <C : R, R : CharSequence?> C?.ifNullOrEmpty(defaultValue: () -> R): R {
return if (this.isNullOrEmpty()) defaultValue() else this
}

View File

@@ -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),

View File

@@ -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()

View File

@@ -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) }

View File

@@ -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?,

View File

@@ -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?,

View File

@@ -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?,

View File

@@ -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?

View File

@@ -100,7 +100,7 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), 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),

View File

@@ -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<MangaChapter>? = 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,
)
}
}

View File

@@ -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,