From 6d74a86711ad17be4bebe054d88506303dd07504 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 24 Dec 2023 18:30:24 -0500 Subject: [PATCH] Some domain Track model migrations --- .../eu/kanade/domain/track/model/Track.kt | 4 +-- .../presentation/track/TrackInfoDialogHome.kt | 3 +- .../track/TrackerSearchPreviewProvider.kt | 2 +- .../tachiyomi/data/database/models/Track.kt | 2 +- .../data/database/models/TrackImpl.kt | 2 +- .../tachiyomi/data/track/DeletableTracker.kt | 4 +-- .../eu/kanade/tachiyomi/data/track/Tracker.kt | 5 +-- .../tachiyomi/data/track/anilist/Anilist.kt | 17 ++++----- .../data/track/anilist/AnilistApi.kt | 16 ++++----- .../data/track/anilist/AnilistModels.kt | 25 ++++++------- .../tachiyomi/data/track/bangumi/Bangumi.kt | 3 +- .../data/track/bangumi/BangumiApi.kt | 12 +++---- .../tachiyomi/data/track/kavita/Kavita.kt | 2 +- .../tachiyomi/data/track/kitsu/Kitsu.kt | 9 ++--- .../tachiyomi/data/track/kitsu/KitsuApi.kt | 35 ++++++++++--------- .../tachiyomi/data/track/kitsu/KitsuModels.kt | 8 ++--- .../tachiyomi/data/track/komga/Komga.kt | 2 +- .../data/track/mangaupdates/MangaUpdates.kt | 6 ++-- .../track/mangaupdates/MangaUpdatesApi.kt | 17 ++++----- .../data/track/mangaupdates/dto/Record.kt | 2 +- .../tachiyomi/data/track/model/TrackSearch.kt | 6 ++-- .../data/track/myanimelist/MyAnimeList.kt | 9 ++--- .../data/track/myanimelist/MyAnimeListApi.kt | 26 ++++++-------- .../data/track/shikimori/Shikimori.kt | 7 ++-- .../data/track/shikimori/ShikimoriApi.kt | 24 ++++++------- .../tachiyomi/data/track/suwayomi/Suwayomi.kt | 2 +- .../ui/manga/track/TrackInfoDialog.kt | 4 +-- .../main/java/eu/kanade/test/DummyTracker.kt | 2 +- 28 files changed, 129 insertions(+), 127 deletions(-) diff --git a/app/src/main/java/eu/kanade/domain/track/model/Track.kt b/app/src/main/java/eu/kanade/domain/track/model/Track.kt index e16846e0e3..e9e97c5c60 100644 --- a/app/src/main/java/eu/kanade/domain/track/model/Track.kt +++ b/app/src/main/java/eu/kanade/domain/track/model/Track.kt @@ -16,7 +16,7 @@ fun Track.copyPersonalFrom(other: Track): Track { fun Track.toDbTrack(): DbTrack = DbTrack.create(syncId).also { it.id = id it.manga_id = mangaId - it.media_id = remoteId + it.remote_id = remoteId it.library_id = libraryId it.title = title it.last_chapter_read = lastChapterRead.toFloat() @@ -34,7 +34,7 @@ fun DbTrack.toDomainTrack(idRequired: Boolean = true): Track? { id = trackId, mangaId = manga_id, syncId = sync_id.toLong(), - remoteId = media_id, + remoteId = remote_id, libraryId = library_id, title = title, lastChapterRead = last_chapter_read.toDouble(), diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt index 07693aa3a5..0aec41dce6 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt @@ -47,7 +47,6 @@ import androidx.compose.ui.tooling.preview.PreviewLightDark import androidx.compose.ui.tooling.preview.PreviewParameter import androidx.compose.ui.unit.dp import dev.icerock.moko.resources.StringResource -import eu.kanade.domain.track.model.toDbTrack import eu.kanade.presentation.components.DropdownMenu import eu.kanade.presentation.theme.TachiyomiTheme import eu.kanade.presentation.track.components.TrackLogoIcon @@ -101,7 +100,7 @@ fun TrackInfoDialogHome( } }, onChaptersClick = { onChapterClick(item) }, - score = item.tracker.displayScore(item.track.toDbTrack()) + score = item.tracker.displayScore(item.track) .takeIf { supportsScoring && item.track.score != 0.0 }, onScoreClick = { onScoreClick(item) } .takeIf { supportsScoring }, diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackerSearchPreviewProvider.kt b/app/src/main/java/eu/kanade/presentation/track/TrackerSearchPreviewProvider.kt index b945e2ad48..fe5578f7bb 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackerSearchPreviewProvider.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackerSearchPreviewProvider.kt @@ -63,7 +63,7 @@ internal class TrackerSearchPreviewProvider : PreviewParameterProvider<@Composab it.id = Random.nextLong() it.manga_id = Random.nextLong() it.sync_id = Random.nextInt() - it.media_id = Random.nextLong() + it.remote_id = Random.nextLong() it.library_id = Random.nextLong() it.title = lorem((1..10).random()).joinToString() it.last_chapter_read = (0..100).random().toFloat() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt index 38df114e2c..e0bc5f047b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/Track.kt @@ -10,7 +10,7 @@ interface Track : Serializable { var sync_id: Int - var media_id: Long + var remote_id: Long var library_id: Long? diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt index a83a5f7a7f..faf86f0213 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/TrackImpl.kt @@ -8,7 +8,7 @@ class TrackImpl : Track { override var sync_id: Int = 0 - override var media_id: Long = 0 + override var remote_id: Long = 0 override var library_id: Long? = null diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/DeletableTracker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/DeletableTracker.kt index c61c55e78c..9001639260 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/DeletableTracker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/DeletableTracker.kt @@ -1,11 +1,11 @@ package eu.kanade.tachiyomi.data.track -import eu.kanade.tachiyomi.data.database.models.Track +import tachiyomi.domain.track.model.Track /** * Tracker that support deleting am entry from a user's list. */ interface DeletableTracker { - suspend fun delete(track: Track): Track + suspend fun delete(track: Track) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/Tracker.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/Tracker.kt index 3b3223de9d..59cf64648e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/Tracker.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/Tracker.kt @@ -8,6 +8,7 @@ import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.model.TrackSearch import kotlinx.collections.immutable.ImmutableList import okhttp3.OkHttpClient +import tachiyomi.domain.track.model.Track as DomainTrack interface Tracker { @@ -39,11 +40,11 @@ interface Tracker { fun getScoreList(): ImmutableList // TODO: Store all scores as 10 point in the future maybe? - fun get10PointScore(track: tachiyomi.domain.track.model.Track): Double + fun get10PointScore(track: DomainTrack): Double fun indexToScore(index: Int): Float - fun displayScore(track: Track): String + fun displayScore(track: DomainTrack): String suspend fun update(track: Track, didReadChapter: Boolean = false): Track diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt index 95191bc003..93fd75a452 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/Anilist.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.track.anilist import android.graphics.Color import dev.icerock.moko.resources.StringResource +import eu.kanade.domain.track.model.toDbTrack import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.BaseTracker @@ -120,16 +121,16 @@ class Anilist(id: Long) : BaseTracker(id, "AniList"), DeletableTracker { } } - override fun displayScore(track: Track): String { + override fun displayScore(track: DomainTrack): String { val score = track.score return when (scorePreference.get()) { POINT_5 -> when (score) { - 0f -> "0 ★" + 0.0 -> "0 ★" else -> "${((score + 10) / 20).toInt()} ★" } POINT_3 -> when { - score == 0f -> "0" + score == 0.0 -> "0" score <= 35 -> "😦" score <= 60 -> "😐" else -> "😊" @@ -167,13 +168,13 @@ class Anilist(id: Long) : BaseTracker(id, "AniList"), DeletableTracker { return api.updateLibManga(track) } - override suspend fun delete(track: Track): Track { - if (track.library_id == null || track.library_id!! == 0L) { - val libManga = api.findLibManga(track, getUsername().toInt()) ?: return track - track.library_id = libManga.library_id + override suspend fun delete(track: DomainTrack) { + if (track.libraryId == null || track.libraryId == 0L) { + val libManga = api.findLibManga(track.toDbTrack(), getUsername().toInt()) ?: return + return api.deleteLibManga(track.copy(id = libManga.library_id!!)) } - return api.deleteLibManga(track) + api.deleteLibManga(track) } override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt index c385d76143..de6ef2f8ea 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistApi.kt @@ -31,6 +31,7 @@ import java.time.LocalDate import java.time.ZoneId import java.time.ZonedDateTime import kotlin.time.Duration.Companion.minutes +import tachiyomi.domain.track.model.Track as DomainTrack class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { @@ -55,7 +56,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { val payload = buildJsonObject { put("query", query) putJsonObject("variables") { - put("mangaId", track.media_id) + put("mangaId", track.remote_id) put("progress", track.last_chapter_read.toInt()) put("status", track.toAnilistStatus()) } @@ -113,8 +114,8 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { } } - suspend fun deleteLibManga(track: Track): Track { - return withIOContext { + suspend fun deleteLibManga(track: DomainTrack) { + withIOContext { val query = """ |mutation DeleteManga(${'$'}listId: Int) { |DeleteMediaListEntry(id: ${'$'}listId) { @@ -126,12 +127,11 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { val payload = buildJsonObject { put("query", query) putJsonObject("variables") { - put("listId", track.library_id) + put("listId", track.libraryId) } } authClient.newCall(POST(apiUrl, body = payload.toString().toRequestBody(jsonMime))) .awaitSuccess() - track } } suspend fun search(search: String): List { @@ -235,7 +235,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { put("query", query) putJsonObject("variables") { put("id", userid) - put("manga_id", track.media_id) + put("manga_id", track.remote_id) } } with(json) { @@ -258,8 +258,8 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { } } - suspend fun getLibManga(track: Track, userid: Int): Track { - return findLibManga(track, userid) ?: throw Exception("Could not find manga") + suspend fun getLibManga(track: Track, userId: Int): Track { + return findLibManga(track, userId) ?: throw Exception("Could not find manga") } fun createOAuth(token: String): OAuth { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt index eb2f15ab25..ed5550464d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistModels.kt @@ -9,9 +9,10 @@ import kotlinx.serialization.Serializable import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale +import tachiyomi.domain.track.model.Track as DomainTrack data class ALManga( - val media_id: Long, + val remote_id: Long, val title_user_pref: String, val image_url_lge: String, val description: String?, @@ -23,13 +24,13 @@ data class ALManga( ) { fun toTrack() = TrackSearch.create(TrackerManager.ANILIST).apply { - media_id = this@ALManga.media_id + remote_id = this@ALManga.remote_id title = title_user_pref total_chapters = this@ALManga.total_chapters cover_url = image_url_lge summary = description?.htmlDecode() ?: "" score = average_score.toFloat() - tracking_url = AnilistApi.mangaUrl(media_id) + tracking_url = AnilistApi.mangaUrl(remote_id) publishing_status = this@ALManga.publishing_status publishing_type = format if (start_date_fuzzy != 0L) { @@ -54,7 +55,7 @@ data class ALUserManga( ) { fun toTrack() = Track.create(TrackerManager.ANILIST).apply { - media_id = manga.media_id + remote_id = manga.remote_id title = manga.title_user_pref status = toTrackStatus() score = score_raw.toFloat() @@ -98,28 +99,28 @@ fun Track.toAnilistStatus() = when (status) { private val preferences: TrackPreferences by injectLazy() -fun Track.toAnilistScore(): String = when (preferences.anilistScoreType().get()) { -// 10 point +fun DomainTrack.toAnilistScore(): String = when (preferences.anilistScoreType().get()) { + // 10 point "POINT_10" -> (score.toInt() / 10).toString() -// 100 point + // 100 point "POINT_100" -> score.toInt().toString() -// 5 stars + // 5 stars "POINT_5" -> when { - score == 0f -> "0" + score == 0.0 -> "0" score < 30 -> "1" score < 50 -> "2" score < 70 -> "3" score < 90 -> "4" else -> "5" } -// Smiley + // Smiley "POINT_3" -> when { - score == 0f -> "0" + score == 0.0 -> "0" score <= 35 -> ":(" score <= 60 -> ":|" else -> ":)" } -// 10 point decimal + // 10 point decimal "POINT_10_DECIMAL" -> (score / 10).toString() else -> throw NotImplementedError("Unknown score type") } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt index bac2bba6d0..a85d5e583a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/Bangumi.kt @@ -12,6 +12,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import tachiyomi.i18n.MR import uy.kohesive.injekt.injectLazy +import tachiyomi.domain.track.model.Track as DomainTrack class Bangumi(id: Long) : BaseTracker(id, "Bangumi") { @@ -23,7 +24,7 @@ class Bangumi(id: Long) : BaseTracker(id, "Bangumi") { override fun getScoreList(): ImmutableList = SCORE_LIST - override fun displayScore(track: Track): String { + override fun displayScore(track: DomainTrack): String { return track.score.toInt().toString() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt index 29db49ec54..8dbde53242 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiApi.kt @@ -42,7 +42,7 @@ class BangumiApi( .add("rating", track.score.toInt().toString()) .add("status", track.toBangumiStatus()) .build() - authClient.newCall(POST("$apiUrl/collection/${track.media_id}/update", body = body)) + authClient.newCall(POST("$apiUrl/collection/${track.remote_id}/update", body = body)) .awaitSuccess() track } @@ -55,7 +55,7 @@ class BangumiApi( .add("rating", track.score.toInt().toString()) .add("status", track.toBangumiStatus()) .build() - authClient.newCall(POST("$apiUrl/collection/${track.media_id}/update", body = sbody)) + authClient.newCall(POST("$apiUrl/collection/${track.remote_id}/update", body = sbody)) .awaitSuccess() // chapter update @@ -64,7 +64,7 @@ class BangumiApi( .build() authClient.newCall( POST( - "$apiUrl/subject/${track.media_id}/update/watched_eps", + "$apiUrl/subject/${track.remote_id}/update/watched_eps", body = body, ), ).awaitSuccess() @@ -111,7 +111,7 @@ class BangumiApi( } val rating = obj["rating"]?.jsonObject?.get("score")?.jsonPrimitive?.floatOrNull ?: -1f return TrackSearch.create(trackId).apply { - media_id = obj["id"]!!.jsonPrimitive.long + remote_id = obj["id"]!!.jsonPrimitive.long title = obj["name_cn"]!!.jsonPrimitive.content cover_url = coverUrl summary = obj["name"]!!.jsonPrimitive.content @@ -124,7 +124,7 @@ class BangumiApi( suspend fun findLibManga(track: Track): Track? { return withIOContext { with(json) { - authClient.newCall(GET("$apiUrl/subject/${track.media_id}")) + authClient.newCall(GET("$apiUrl/subject/${track.remote_id}")) .awaitSuccess() .parseAs() .let { jsonToSearch(it) } @@ -134,7 +134,7 @@ class BangumiApi( suspend fun statusLibManga(track: Track): Track? { return withIOContext { - val urlUserRead = "$apiUrl/collection/${track.media_id}" + val urlUserRead = "$apiUrl/collection/${track.remote_id}" val requestUserRead = Request.Builder() .url(urlUserRead) .cacheControl(CacheControl.FORCE_NETWORK) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt index 0fff84efa7..bcfbb1ec5b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kavita/Kavita.kt @@ -55,7 +55,7 @@ class Kavita(id: Long) : BaseTracker(id, "Kavita"), EnhancedTracker { override fun getScoreList(): ImmutableList = persistentListOf() - override fun displayScore(track: Track): String = "" + override fun displayScore(track: DomainTrack): String = "" override suspend fun update(track: Track, didReadChapter: Boolean): Track { if (track.status != COMPLETED) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt index 86fc808adf..03bfcd1377 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/Kitsu.kt @@ -14,6 +14,7 @@ import kotlinx.serialization.json.Json import tachiyomi.i18n.MR import uy.kohesive.injekt.injectLazy import java.text.DecimalFormat +import tachiyomi.domain.track.model.Track as DomainTrack class Kitsu(id: Long) : BaseTracker(id, "Kitsu"), DeletableTracker { @@ -65,7 +66,7 @@ class Kitsu(id: Long) : BaseTracker(id, "Kitsu"), DeletableTracker { return if (index > 0) (index + 1) / 2f else 0f } - override fun displayScore(track: Track): String { + override fun displayScore(track: DomainTrack): String { val df = DecimalFormat("0.#") return df.format(track.score) } @@ -92,15 +93,15 @@ class Kitsu(id: Long) : BaseTracker(id, "Kitsu"), DeletableTracker { return api.updateLibManga(track) } - override suspend fun delete(track: Track): Track { - return api.removeLibManga(track) + override suspend fun delete(track: DomainTrack) { + api.removeLibManga(track) } override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val remoteTrack = api.findLibManga(track, getUserId()) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) - track.media_id = remoteTrack.media_id + track.remote_id = remoteTrack.remote_id if (track.status != COMPLETED) { track.status = if (hasReadChapters) READING else track.status diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt index 5406be0adf..e6c3acadf6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuApi.kt @@ -29,6 +29,7 @@ import tachiyomi.core.util.lang.withIOContext import uy.kohesive.injekt.injectLazy import java.net.URLEncoder import java.nio.charset.StandardCharsets +import tachiyomi.domain.track.model.Track as DomainTrack class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) { @@ -54,7 +55,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) } putJsonObject("media") { putJsonObject("data") { - put("id", track.media_id) + put("id", track.remote_id) put("type", "manga") } } @@ -77,7 +78,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) .awaitSuccess() .parseAs() .let { - track.media_id = it["data"]!!.jsonObject["id"]!!.jsonPrimitive.long + track.remote_id = it["data"]!!.jsonObject["id"]!!.jsonPrimitive.long track } } @@ -89,7 +90,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) val data = buildJsonObject { putJsonObject("data") { put("type", "libraryEntries") - put("id", track.media_id) + put("id", track.remote_id) putJsonObject("attributes") { put("status", track.toKitsuStatus()) put("progress", track.last_chapter_read.toInt()) @@ -103,7 +104,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) with(json) { authClient.newCall( Request.Builder() - .url("${baseUrl}library-entries/${track.media_id}") + .url("${baseUrl}library-entries/${track.remote_id}") .headers( headersOf( "Content-Type", @@ -124,19 +125,19 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) } } - suspend fun removeLibManga(track: Track): Track { - return withIOContext { - authClient.newCall( - DELETE( - "${baseUrl}library-entries/${track.media_id}", - headers = headersOf( - "Content-Type", - "application/vnd.api+json", + suspend fun removeLibManga(track: DomainTrack) { + withIOContext { + authClient + .newCall( + DELETE( + "${baseUrl}library-entries/${track.remoteId}", + headers = headersOf( + "Content-Type", + "application/vnd.api+json", + ), ), - ), - ) + ) .awaitSuccess() - track } } suspend fun search(query: String): List { @@ -187,7 +188,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) suspend fun findLibManga(track: Track, userId: String): Track? { return withIOContext { val url = "${baseUrl}library-entries".toUri().buildUpon() - .encodedQuery("filter[manga_id]=${track.media_id}&filter[user_id]=$userId") + .encodedQuery("filter[manga_id]=${track.remote_id}&filter[user_id]=$userId") .appendQueryParameter("include", "manga") .build() with(json) { @@ -210,7 +211,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) suspend fun getLibManga(track: Track): Track { return withIOContext { val url = "${baseUrl}library-entries".toUri().buildUpon() - .encodedQuery("filter[id]=${track.media_id}") + .encodedQuery("filter[id]=${track.remote_id}") .appendQueryParameter("include", "manga") .build() with(json) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt index 156f6d8f36..ba66843393 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuModels.kt @@ -37,12 +37,12 @@ class KitsuSearchManga(obj: JsonObject) { @CallSuper fun toTrack() = TrackSearch.create(TrackerManager.KITSU).apply { - media_id = this@KitsuSearchManga.id + remote_id = this@KitsuSearchManga.id title = canonicalTitle total_chapters = chapterCount ?: 0 cover_url = original ?: "" summary = synopsis ?: "" - tracking_url = KitsuApi.mangaUrl(media_id) + tracking_url = KitsuApi.mangaUrl(remote_id) score = rating ?: -1f publishing_status = if (endDate == null) { "Publishing" @@ -70,12 +70,12 @@ class KitsuLibManga(obj: JsonObject, manga: JsonObject) { val progress = obj["attributes"]!!.jsonObject["progress"]!!.jsonPrimitive.int fun toTrack() = TrackSearch.create(TrackerManager.KITSU).apply { - media_id = libraryId + remote_id = libraryId title = canonicalTitle total_chapters = chapterCount ?: 0 cover_url = original summary = synopsis - tracking_url = KitsuApi.mangaUrl(media_id) + tracking_url = KitsuApi.mangaUrl(remote_id) publishing_status = this@KitsuLibManga.status publishing_type = type start_date = startDate diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt index 76eabfda96..6e69bf7646 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/komga/Komga.kt @@ -52,7 +52,7 @@ class Komga(id: Long) : BaseTracker(id, "Komga"), EnhancedTracker { override fun getScoreList(): ImmutableList = persistentListOf() - override fun displayScore(track: Track): String = "" + override fun displayScore(track: DomainTrack): String = "" override suspend fun update(track: Track, didReadChapter: Boolean): Track { if (track.status != COMPLETED) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt index 698ad123ce..f5c33cf8d3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdates.kt @@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.data.track.model.TrackSearch import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList import tachiyomi.i18n.MR +import tachiyomi.domain.track.model.Track as DomainTrack class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker { @@ -60,7 +61,7 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker override fun indexToScore(index: Int): Float = SCORE_LIST[index].toFloat() - override fun displayScore(track: Track): String = track.score.toString() + override fun displayScore(track: DomainTrack): String = track.score.toString() override suspend fun update(track: Track, didReadChapter: Boolean): Track { if (track.status != COMPLETE_LIST && didReadChapter) { @@ -70,9 +71,8 @@ class MangaUpdates(id: Long) : BaseTracker(id, "MangaUpdates"), DeletableTracker return track } - override suspend fun delete(track: Track): Track { + override suspend fun delete(track: DomainTrack) { api.deleteSeriesFromList(track) - return track } override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt index ab6b8a3091..794ad11ef3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/MangaUpdatesApi.kt @@ -30,6 +30,7 @@ import okhttp3.OkHttpClient import okhttp3.RequestBody.Companion.toRequestBody import tachiyomi.core.util.system.logcat import uy.kohesive.injekt.injectLazy +import tachiyomi.domain.track.model.Track as DomainTrack class MangaUpdatesApi( interceptor: MangaUpdatesInterceptor, @@ -48,7 +49,7 @@ class MangaUpdatesApi( suspend fun getSeriesListItem(track: Track): Pair { val listItem = with(json) { - authClient.newCall(GET("$baseUrl/v1/lists/series/${track.media_id}")) + authClient.newCall(GET("$baseUrl/v1/lists/series/${track.remote_id}")) .awaitSuccess() .parseAs() } @@ -63,7 +64,7 @@ class MangaUpdatesApi( val body = buildJsonArray { addJsonObject { putJsonObject("series") { - put("id", track.media_id) + put("id", track.remote_id) } put("list_id", status) } @@ -87,7 +88,7 @@ class MangaUpdatesApi( val body = buildJsonArray { addJsonObject { putJsonObject("series") { - put("id", track.media_id) + put("id", track.remote_id) } put("list_id", track.status) putJsonObject("status") { @@ -106,9 +107,9 @@ class MangaUpdatesApi( updateSeriesRating(track) } - suspend fun deleteSeriesFromList(track: Track) { + suspend fun deleteSeriesFromList(track: DomainTrack) { val body = buildJsonArray { - add(track.media_id) + add(track.remoteId) } authClient.newCall( POST( @@ -122,7 +123,7 @@ class MangaUpdatesApi( private suspend fun getSeriesRating(track: Track): Rating? { return try { with(json) { - authClient.newCall(GET("$baseUrl/v1/series/${track.media_id}/rating")) + authClient.newCall(GET("$baseUrl/v1/series/${track.remote_id}/rating")) .awaitSuccess() .parseAs() } @@ -138,7 +139,7 @@ class MangaUpdatesApi( } authClient.newCall( PUT( - url = "$baseUrl/v1/series/${track.media_id}/rating", + url = "$baseUrl/v1/series/${track.remote_id}/rating", body = body.toString().toRequestBody(contentType), ), ) @@ -146,7 +147,7 @@ class MangaUpdatesApi( } else { authClient.newCall( DELETE( - url = "$baseUrl/v1/series/${track.media_id}/rating", + url = "$baseUrl/v1/series/${track.remote_id}/rating", ), ) .awaitSuccess() diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt index fb959a89b3..4b66273e83 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/mangaupdates/dto/Record.kt @@ -25,7 +25,7 @@ data class Record( fun Record.toTrackSearch(id: Long): TrackSearch { return TrackSearch.create(id).apply { - media_id = this@toTrackSearch.seriesId ?: 0L + remote_id = this@toTrackSearch.seriesId ?: 0L title = this@toTrackSearch.title?.htmlDecode() ?: "" total_chapters = 0 cover_url = this@toTrackSearch.image?.url?.original ?: "" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt index 7151aab621..b43d8009ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/model/TrackSearch.kt @@ -10,7 +10,7 @@ class TrackSearch : Track { override var sync_id: Int = 0 - override var media_id: Long = 0 + override var remote_id: Long = 0 override var library_id: Long? = null @@ -48,7 +48,7 @@ class TrackSearch : Track { if (manga_id != other.manga_id) return false if (sync_id != other.sync_id) return false - if (media_id != other.media_id) return false + if (remote_id != other.remote_id) return false return true } @@ -56,7 +56,7 @@ class TrackSearch : Track { override fun hashCode(): Int { var result = manga_id.hashCode() result = 31 * result + sync_id - result = 31 * result + media_id.hashCode() + result = 31 * result + remote_id.hashCode() return result } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt index 5ab94265c4..5d66b73d46 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeList.kt @@ -13,6 +13,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import tachiyomi.i18n.MR import uy.kohesive.injekt.injectLazy +import tachiyomi.domain.track.model.Track as DomainTrack class MyAnimeList(id: Long) : BaseTracker(id, "MyAnimeList"), DeletableTracker { @@ -65,7 +66,7 @@ class MyAnimeList(id: Long) : BaseTracker(id, "MyAnimeList"), DeletableTracker { override fun getScoreList(): ImmutableList = SCORE_LIST - override fun displayScore(track: Track): String { + override fun displayScore(track: DomainTrack): String { return track.score.toInt().toString() } @@ -91,15 +92,15 @@ class MyAnimeList(id: Long) : BaseTracker(id, "MyAnimeList"), DeletableTracker { return api.updateItem(track) } - override suspend fun delete(track: Track): Track { - return api.deleteItem(track) + override suspend fun delete(track: DomainTrack) { + api.deleteItem(track) } override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { val remoteTrack = api.findListItem(track) return if (remoteTrack != null) { track.copyPersonalFrom(remoteTrack) - track.media_id = remoteTrack.media_id + track.remote_id = remoteTrack.remote_id if (track.status != COMPLETED) { val isRereading = track.status == REREADING diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt index 444c5512ff..c67cc2a2a5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/myanimelist/MyAnimeListApi.kt @@ -4,6 +4,7 @@ import android.net.Uri import androidx.core.net.toUri import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.model.TrackSearch +import eu.kanade.tachiyomi.network.DELETE import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST import eu.kanade.tachiyomi.network.awaitSuccess @@ -31,6 +32,7 @@ import tachiyomi.core.util.lang.withIOContext import uy.kohesive.injekt.injectLazy import java.text.SimpleDateFormat import java.util.Locale +import tachiyomi.domain.track.model.Track as DomainTrack class MyAnimeListApi( private val trackId: Long, @@ -114,7 +116,7 @@ class MyAnimeListApi( .let { val obj = it.jsonObject TrackSearch.create(trackId).apply { - media_id = obj["id"]!!.jsonPrimitive.long + remote_id = obj["id"]!!.jsonPrimitive.long title = obj["title"]!!.jsonPrimitive.content summary = obj["synopsis"]?.jsonPrimitive?.content ?: "" total_chapters = obj["num_chapters"]!!.jsonPrimitive.int @@ -122,7 +124,7 @@ class MyAnimeListApi( cover_url = obj["main_picture"]?.jsonObject?.get("large")?.jsonPrimitive?.content ?: "" - tracking_url = "https://myanimelist.net/manga/$media_id" + tracking_url = "https://myanimelist.net/manga/$remote_id" publishing_status = obj["status"]!!.jsonPrimitive.content.replace("_", " ") publishing_type = @@ -154,7 +156,7 @@ class MyAnimeListApi( } val request = Request.Builder() - .url(mangaUrl(track.media_id).toString()) + .url(mangaUrl(track.remote_id).toString()) .put(formBodyBuilder.build()) .build() with(json) { @@ -166,24 +168,18 @@ class MyAnimeListApi( } } - suspend fun deleteItem(track: Track): Track { - return withIOContext { - val request = Request.Builder() - .url(mangaUrl(track.media_id).toString()) - .delete() - .build() - with(json) { - authClient.newCall(request) - .awaitSuccess() - track - } + suspend fun deleteItem(track: DomainTrack) { + withIOContext { + authClient + .newCall(DELETE(mangaUrl(track.remoteId).toString())) + .awaitSuccess() } } suspend fun findListItem(track: Track): Track? { return withIOContext { val uri = "$baseApiUrl/manga".toUri().buildUpon() - .appendPath(track.media_id.toString()) + .appendPath(track.remote_id.toString()) .appendQueryParameter("fields", "num_chapters,my_list_status{start_date,finish_date}") .build() with(json) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt index d8e2bdd97b..8f70e03dd2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/Shikimori.kt @@ -13,6 +13,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import tachiyomi.i18n.MR import uy.kohesive.injekt.injectLazy +import tachiyomi.domain.track.model.Track as DomainTrack class Shikimori(id: Long) : BaseTracker(id, "Shikimori"), DeletableTracker { @@ -37,7 +38,7 @@ class Shikimori(id: Long) : BaseTracker(id, "Shikimori"), DeletableTracker { override fun getScoreList(): ImmutableList = SCORE_LIST - override fun displayScore(track: Track): String { + override fun displayScore(track: DomainTrack): String { return track.score.toInt().toString() } @@ -59,8 +60,8 @@ class Shikimori(id: Long) : BaseTracker(id, "Shikimori"), DeletableTracker { return api.updateLibManga(track, getUsername()) } - override suspend fun delete(track: Track): Track { - return api.deleteLibManga(track) + override suspend fun delete(track: DomainTrack) { + api.deleteLibManga(track) } override suspend fun bind(track: Track, hasReadChapters: Boolean): Track { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt index 0a5bba7728..dca1c290d7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/shikimori/ShikimoriApi.kt @@ -27,6 +27,7 @@ import okhttp3.OkHttpClient import okhttp3.RequestBody.Companion.toRequestBody import tachiyomi.core.util.lang.withIOContext import uy.kohesive.injekt.injectLazy +import tachiyomi.domain.track.model.Track as DomainTrack class ShikimoriApi( private val trackId: Long, @@ -44,7 +45,7 @@ class ShikimoriApi( val payload = buildJsonObject { putJsonObject("user_rate") { put("user_id", userId) - put("target_id", track.media_id) + put("target_id", track.remote_id) put("target_type", "Manga") put("chapters", track.last_chapter_read.toInt()) put("score", track.score.toInt()) @@ -69,14 +70,11 @@ class ShikimoriApi( suspend fun updateLibManga(track: Track, userId: String): Track = addLibManga(track, userId) - suspend fun deleteLibManga(track: Track): Track { - return withIOContext { - authClient.newCall( - DELETE( - "$apiUrl/v2/user_rates/${track.library_id}", - ), - ).awaitSuccess() - track + suspend fun deleteLibManga(track: DomainTrack) { + withIOContext { + authClient + .newCall(DELETE("$apiUrl/v2/user_rates/${track.libraryId}")) + .awaitSuccess() } } @@ -102,7 +100,7 @@ class ShikimoriApi( private fun jsonToSearch(obj: JsonObject): TrackSearch { return TrackSearch.create(trackId).apply { - media_id = obj["id"]!!.jsonPrimitive.long + remote_id = obj["id"]!!.jsonPrimitive.long title = obj["name"]!!.jsonPrimitive.content total_chapters = obj["chapters"]!!.jsonPrimitive.int cover_url = baseUrl + obj["image"]!!.jsonObject["preview"]!!.jsonPrimitive.content @@ -118,7 +116,7 @@ class ShikimoriApi( private fun jsonToTrack(obj: JsonObject, mangas: JsonObject): Track { return Track.create(trackId).apply { title = mangas["name"]!!.jsonPrimitive.content - media_id = obj["id"]!!.jsonPrimitive.long + remote_id = obj["id"]!!.jsonPrimitive.long total_chapters = mangas["chapters"]!!.jsonPrimitive.int library_id = obj["id"]!!.jsonPrimitive.long last_chapter_read = obj["chapters"]!!.jsonPrimitive.float @@ -131,7 +129,7 @@ class ShikimoriApi( suspend fun findLibManga(track: Track, userId: String): Track? { return withIOContext { val urlMangas = "$apiUrl/mangas".toUri().buildUpon() - .appendPath(track.media_id.toString()) + .appendPath(track.remote_id.toString()) .build() val mangas = with(json) { authClient.newCall(GET(urlMangas.toString())) @@ -141,7 +139,7 @@ class ShikimoriApi( val url = "$apiUrl/v2/user_rates".toUri().buildUpon() .appendQueryParameter("user_id", userId) - .appendQueryParameter("target_id", track.media_id.toString()) + .appendQueryParameter("target_id", track.remote_id.toString()) .appendQueryParameter("target_type", "Manga") .build() with(json) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt index dedafe4864..d8d1ba9755 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/suwayomi/Suwayomi.kt @@ -45,7 +45,7 @@ class Suwayomi(id: Long) : BaseTracker(id, "Suwayomi"), EnhancedTracker { override fun getScoreList(): ImmutableList = persistentListOf() - override fun displayScore(track: Track): String = "" + override fun displayScore(track: DomainTrack): String = "" override suspend fun update(track: Track, didReadChapter: Boolean): Track { if (track.status != COMPLETED) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt index ce6f27686b..aab8f802a0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackInfoDialog.kt @@ -399,7 +399,7 @@ private data class TrackScoreSelectorScreen( private class Model( private val track: Track, private val tracker: Tracker, - ) : StateScreenModel(State(tracker.displayScore(track.toDbTrack()))) { + ) : StateScreenModel(State(tracker.displayScore(track))) { fun getSelections(): ImmutableList { return tracker.getScoreList() @@ -816,7 +816,7 @@ private data class TrackerRemoveScreen( fun deleteMangaFromService() { screenModelScope.launchNonCancellable { - (tracker as DeletableTracker).delete(track.toDbTrack()) + (tracker as DeletableTracker).delete(track) } } diff --git a/app/src/main/java/eu/kanade/test/DummyTracker.kt b/app/src/main/java/eu/kanade/test/DummyTracker.kt index 10d9bd9575..e8183310df 100644 --- a/app/src/main/java/eu/kanade/test/DummyTracker.kt +++ b/app/src/main/java/eu/kanade/test/DummyTracker.kt @@ -58,7 +58,7 @@ data class DummyTracker( override fun indexToScore(index: Int): Float = getScoreList()[index].toFloat() - override fun displayScore(track: eu.kanade.tachiyomi.data.database.models.Track): String = + override fun displayScore(track: Track): String = track.score.toString() override suspend fun update(