chore: More domain module Manga prep

This commit is contained in:
Ahmad Ansori Palembani 2024-06-18 19:53:22 +07:00
parent f94e69cdf8
commit de48b52ec3
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6
6 changed files with 39 additions and 7 deletions

View file

@ -145,6 +145,7 @@ android {
dependencies {
implementation(projects.core)
implementation(projects.data)
implementation(projects.domain)
implementation(projects.i18n)
implementation(projects.presentation.core)
implementation(projects.sourceApi)

View file

@ -146,11 +146,6 @@ interface Manga : SManga {
).lowercase(Locale.getDefault())
}
fun getGenres(): List<String>? {
return genre?.split(",")
?.mapNotNull { tag -> tag.trim().takeUnless { it.isBlank() } }
}
fun getOriginalGenres(): List<String>? {
return (originalGenre ?: genre)?.split(",")
?.mapNotNull { tag -> tag.trim().takeUnless { it.isBlank() } }

View file

@ -0,0 +1,31 @@
package yokai.data.manga.models
import eu.kanade.tachiyomi.source.model.SManga
import yokai.domain.manga.models.Manga
fun Manga.toSManga() = SManga.create().also {
it.url = url
it.title = title
it.artist = artist
it.author = author
it.description = description
it.genre = genres.orEmpty().joinToString()
it.status = status
it.thumbnail_url = thumbnailUrl
it.initialized = initialized
}
fun Manga.copyFrom(other: SManga): Manga {
val author = other.author ?: author
val artist = other.artist ?: artist
val description = other.description ?: description
val genres = if (other.genre != null) other.getGenres() else genres
val thumbnailUrl = other.thumbnail_url ?: thumbnailUrl
return this.copy(
author = author,
artist = artist,
description = description,
genres = genres,
thumbnailUrl = thumbnailUrl,
)
}

View file

@ -9,11 +9,11 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.sourceApi)
}
}
val androidMain by getting {
dependencies {
implementation(projects.sourceApi)
}
}
}

View file

@ -10,7 +10,7 @@ data class Manga(
val artist: String?,
val author: String?,
val description: String?,
val genre: String?,
val genres: List<String>?,
val status: Int,
val thumbnailUrl: String?,
val updateStrategy: UpdateStrategy,

View file

@ -24,6 +24,11 @@ interface SManga : Serializable {
var initialized: Boolean
fun getGenres(): List<String>? {
if (genre.isNullOrBlank()) return null
return genre?.split(", ")?.map { it.trim() }?.filterNot { it.isBlank() }?.distinct()
}
fun copy() = create().also {
it.url = url
it.title = title