Adjust manga fields nullability

master
Koitharu 1 year ago
parent 8e1d02f356
commit 0aa78c0d7e
Signed by: Koitharu
GPG Key ID: 676DEE768C17A9D7

@ -49,7 +49,7 @@ fun Manga.toEntity() = MangaEntity(
publicUrl = publicUrl, publicUrl = publicUrl,
source = source.name, source = source.name,
largeCoverUrl = largeCoverUrl, largeCoverUrl = largeCoverUrl,
coverUrl = coverUrl, coverUrl = coverUrl.orEmpty(),
altTitle = altTitle, altTitle = altTitle,
rating = rating, rating = rating,
isNsfw = isNsfw, isNsfw = isNsfw,

@ -14,7 +14,7 @@ data class MangaEntity(
@ColumnInfo(name = "url") val url: String, @ColumnInfo(name = "url") val url: String,
@ColumnInfo(name = "public_url") val publicUrl: String, @ColumnInfo(name = "public_url") val publicUrl: String,
@ColumnInfo(name = "rating") val rating: Float, // normalized value [0..1] or -1 @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 = "cover_url") val coverUrl: String,
@ColumnInfo(name = "large_cover_url") val largeCoverUrl: String?, @ColumnInfo(name = "large_cover_url") val largeCoverUrl: String?,
@ColumnInfo(name = "state") val state: String?, @ColumnInfo(name = "state") val state: String?,

@ -82,7 +82,7 @@ class ExternalPluginContentSource(
publicUrl = details.publicUrl.ifEmpty { manga.publicUrl }, publicUrl = details.publicUrl.ifEmpty { manga.publicUrl },
rating = maxOf(details.rating, manga.rating), rating = maxOf(details.rating, manga.rating),
isNsfw = details.isNsfw, isNsfw = details.isNsfw,
coverUrl = details.coverUrl.ifEmpty { manga.coverUrl }, coverUrl = details.coverUrl.ifNullOrEmpty { manga.coverUrl },
tags = details.tags + manga.tags, tags = details.tags + manga.tags,
state = details.state ?: manga.state, state = details.state ?: manga.state,
author = details.author.ifNullOrEmpty { manga.author }, author = details.author.ifNullOrEmpty { manga.author },

@ -8,7 +8,7 @@ import org.koitharu.kotatsu.parsers.util.ellipsize
import org.koitharu.kotatsu.parsers.util.levenshteinDistance import org.koitharu.kotatsu.parsers.util.levenshteinDistance
import java.util.UUID 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 return if (this.isNullOrEmpty()) defaultValue() else this
} }

@ -274,7 +274,7 @@ class DetailsActivity :
startActivity( startActivity(
ImageActivity.newIntent( ImageActivity.newIntent(
v.context, v.context,
manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl } ?: return,
manga.source, manga.source,
), ),
scaleUpActivityOptionsOf(v), scaleUpActivityOptionsOf(v),

@ -199,7 +199,7 @@ class DownloadWorker @AssistedInject constructor(
format = task.format ?: settings.preferredDownloadFormat, format = task.format ?: settings.preferredDownloadFormat,
) )
val coverUrl = mangaDetails.largeCoverUrl.ifNullOrEmpty { mangaDetails.coverUrl } val coverUrl = mangaDetails.largeCoverUrl.ifNullOrEmpty { mangaDetails.coverUrl }
if (coverUrl.isNotEmpty()) { if (!coverUrl.isNullOrEmpty()) {
downloadFile(coverUrl, destination, repo.source).let { file -> downloadFile(coverUrl, destination, repo.source).let { file ->
output.addCover(file, MimeTypeMap.getFileExtensionFromUrl(coverUrl)) output.addCover(file, MimeTypeMap.getFileExtensionFromUrl(coverUrl))
file.deleteAwait() file.deleteAwait()

@ -3,7 +3,7 @@ package org.koitharu.kotatsu.favourites.domain.model
import org.koitharu.kotatsu.core.model.MangaSource import org.koitharu.kotatsu.core.model.MangaSource
data class Cover( data class Cover(
val url: String, val url: String?,
val source: String, val source: String,
) { ) {
val mangaSource by lazy { MangaSource(source) } val mangaSource by lazy { MangaSource(source) }

@ -7,7 +7,7 @@ data class MangaCompactListModel(
override val id: Long, override val id: Long,
override val title: String, override val title: String,
val subtitle: String, val subtitle: String,
override val coverUrl: String, override val coverUrl: String?,
override val manga: Manga, override val manga: Manga,
override val counter: Int, override val counter: Int,
override val progress: ReadingProgress?, override val progress: ReadingProgress?,

@ -8,7 +8,7 @@ data class MangaDetailedListModel(
override val id: Long, override val id: Long,
override val title: String, override val title: String,
val subtitle: String?, val subtitle: String?,
override val coverUrl: String, override val coverUrl: String?,
override val manga: Manga, override val manga: Manga,
override val counter: Int, override val counter: Int,
override val progress: ReadingProgress?, override val progress: ReadingProgress?,

@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
data class MangaGridModel( data class MangaGridModel(
override val id: Long, override val id: Long,
override val title: String, override val title: String,
override val coverUrl: String, override val coverUrl: String?,
override val manga: Manga, override val manga: Manga,
override val counter: Int, override val counter: Int,
override val progress: ReadingProgress?, override val progress: ReadingProgress?,

@ -11,7 +11,7 @@ sealed class MangaListModel : ListModel {
abstract val id: Long abstract val id: Long
abstract val manga: Manga abstract val manga: Manga
abstract val title: String abstract val title: String
abstract val coverUrl: String abstract val coverUrl: String?
abstract val counter: Int abstract val counter: Int
abstract val isFavorite: Boolean abstract val isFavorite: Boolean
abstract val progress: ReadingProgress? abstract val progress: ReadingProgress?

@ -100,7 +100,7 @@ class PreviewFragment : BaseFragment<FragmentPreviewBinding>(), View.OnClickList
R.id.imageView_cover -> startActivity( R.id.imageView_cover -> startActivity(
ImageActivity.newIntent( ImageActivity.newIntent(
v.context, v.context,
manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl }, manga.largeCoverUrl.ifNullOrEmpty { manga.coverUrl } ?: return,
manga.source, manga.source,
), ),
scaleUpActivityOptionsOf(v), scaleUpActivityOptionsOf(v),

@ -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.Manga
import org.koitharu.kotatsu.parsers.model.MangaChapter import org.koitharu.kotatsu.parsers.model.MangaChapter
import org.koitharu.kotatsu.parsers.model.MangaPage 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.runCatchingCancellable
import org.koitharu.kotatsu.parsers.util.toFileNameSafe import org.koitharu.kotatsu.parsers.util.toFileNameSafe
import java.io.File import java.io.File
@ -60,7 +59,7 @@ class LocalMangaParser(private val uri: Uri) {
val mangaInfo = index?.getMangaInfo() val mangaInfo = index?.getMangaInfo()
if (mangaInfo != null) { if (mangaInfo != null) {
val coverEntry: Path? = index.getCoverEntry()?.let { rootPath / it } ?: fileSystem.findFirstImage(rootPath) val coverEntry: Path? = index.getCoverEntry()?.let { rootPath / it } ?: fileSystem.findFirstImage(rootPath)
mangaInfo.copyInternal( mangaInfo.copy(
source = LocalMangaSource, source = LocalMangaSource,
url = rootFile.toUri().toString(), url = rootFile.toUri().toString(),
coverUrl = coverEntry?.let { uri.child(it, resolve = true).toString() }.orEmpty(), 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)) { if (path != null && !fileSystem.exists(rootPath / path)) {
null null
} else { } else {
c.copyInternal( c.copy(
url = path?.let { url = path?.let {
uri.child(it, resolve = false).toString() uri.child(it, resolve = false).toString()
} ?: uri.toString(), } ?: uri.toString(),
@ -277,44 +276,5 @@ class LocalMangaParser(private val uri: Uri) {
private fun String.fileNameToTitle() = substringBeforeLast('.') private fun String.fileNameToTitle() = substringBeforeLast('.')
.replace('_', ' ') .replace('_', ' ')
.replaceFirstChar { it.uppercase() } .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,
)
} }
} }

@ -6,7 +6,7 @@ import org.koitharu.kotatsu.parsers.model.Manga
data class FeedItem( data class FeedItem(
val id: Long, val id: Long,
val imageUrl: String, val imageUrl: String?,
val title: String, val title: String,
val manga: Manga, val manga: Manga,
val count: Int, val count: Int,

Loading…
Cancel
Save