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 2cb5623dec..db25cc7633 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 @@ -138,7 +138,7 @@ class Anilist(id: Long) : BaseTracker(id, "AniList"), DeletableTracker { else -> "😊" } - else -> track.toAnilistScore() + else -> track.toApiScore() } } 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 08057400af..302466f46d 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 @@ -55,7 +55,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { putJsonObject("variables") { put("mangaId", track.remote_id) put("progress", track.last_chapter_read.toInt()) - put("status", track.toAnilistStatus()) + put("status", track.toApiStatus()) } } with(json) { @@ -98,7 +98,7 @@ class AnilistApi(val client: OkHttpClient, interceptor: AnilistInterceptor) { putJsonObject("variables") { put("listId", track.library_id) put("progress", track.last_chapter_read.toInt()) - put("status", track.toAnilistStatus()) + put("status", track.toApiStatus()) put("score", track.score.toInt()) put("startedAt", createDate(track.started_reading_date)) put("completedAt", createDate(track.finished_reading_date)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistUtils.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistUtils.kt index 6f69565115..5dab651132 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistUtils.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/anilist/AnilistUtils.kt @@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.data.database.models.Track import uy.kohesive.injekt.injectLazy import tachiyomi.domain.track.model.Track as DomainTrack -fun Track.toAnilistStatus() = when (status) { +fun Track.toApiStatus() = when (status) { Anilist.READING -> "CURRENT" Anilist.COMPLETED -> "COMPLETED" Anilist.ON_HOLD -> "PAUSED" @@ -18,7 +18,7 @@ fun Track.toAnilistStatus() = when (status) { private val preferences: TrackPreferences by injectLazy() @Suppress("MagicNumber", "CyclomaticComplexMethod") -fun DomainTrack.toAnilistScore(): String = when (preferences.anilistScoreType().get()) { +fun DomainTrack.toApiScore(): String = when (preferences.anilistScoreType().get()) { // 10 point "POINT_10" -> (score.toInt() / 10).toString() // 100 point 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 472b5a6c9a..91aed7ee23 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 @@ -5,7 +5,7 @@ import dev.icerock.moko.resources.StringResource import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Track import eu.kanade.tachiyomi.data.track.BaseTracker -import eu.kanade.tachiyomi.data.track.bangumi.dto.BangumiOAuth +import eu.kanade.tachiyomi.data.track.bangumi.dto.BGMOAuth import eu.kanade.tachiyomi.data.track.model.TrackSearch import kotlinx.collections.immutable.ImmutableList import kotlinx.collections.immutable.toImmutableList @@ -119,13 +119,13 @@ class Bangumi(id: Long) : BaseTracker(id, "Bangumi") { } } - fun saveToken(oauth: BangumiOAuth?) { + fun saveToken(oauth: BGMOAuth?) { trackPreferences.trackToken(this).set(json.encodeToString(oauth)) } - fun restoreToken(): BangumiOAuth? { + fun restoreToken(): BGMOAuth? { return try { - json.decodeFromString(trackPreferences.trackToken(this).get()) + json.decodeFromString(trackPreferences.trackToken(this).get()) } catch (e: Exception) { null } 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 6803f22f37..98f513e91b 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 @@ -3,10 +3,10 @@ package eu.kanade.tachiyomi.data.track.bangumi import android.net.Uri import androidx.core.net.toUri import eu.kanade.tachiyomi.data.database.models.Track -import eu.kanade.tachiyomi.data.track.bangumi.dto.BangumiCollectionResponse -import eu.kanade.tachiyomi.data.track.bangumi.dto.BangumiOAuth -import eu.kanade.tachiyomi.data.track.bangumi.dto.BangumiSearchItem -import eu.kanade.tachiyomi.data.track.bangumi.dto.BangumiSearchResult +import eu.kanade.tachiyomi.data.track.bangumi.dto.BGMCollectionResponse +import eu.kanade.tachiyomi.data.track.bangumi.dto.BGMOAuth +import eu.kanade.tachiyomi.data.track.bangumi.dto.BGMSearchItem +import eu.kanade.tachiyomi.data.track.bangumi.dto.BGMSearchResult import eu.kanade.tachiyomi.data.track.model.TrackSearch import eu.kanade.tachiyomi.network.GET import eu.kanade.tachiyomi.network.POST @@ -36,7 +36,7 @@ class BangumiApi( return withIOContext { val body = FormBody.Builder() .add("rating", track.score.toInt().toString()) - .add("status", track.toBangumiStatus()) + .add("status", track.toApiStatus()) .build() authClient.newCall(POST("$API_URL/collection/${track.remote_id}/update", body = body)) .awaitSuccess() @@ -49,7 +49,7 @@ class BangumiApi( // read status update val sbody = FormBody.Builder() .add("rating", track.score.toInt().toString()) - .add("status", track.toBangumiStatus()) + .add("status", track.toApiStatus()) .build() authClient.newCall(POST("$API_URL/collection/${track.remote_id}/update", body = sbody)) .awaitSuccess() @@ -77,7 +77,7 @@ class BangumiApi( with(json) { authClient.newCall(GET(url.toString())) .awaitSuccess() - .parseAs() + .parseAs() .let { result -> if (result.code == 404) emptyList() @@ -95,7 +95,7 @@ class BangumiApi( with(json) { authClient.newCall(GET("$API_URL/subject/${track.remote_id}")) .awaitSuccess() - .parseAs() + .parseAs() .toTrackSearch(trackId) } } @@ -115,7 +115,7 @@ class BangumiApi( with(json) { authClient.newCall(requestUserRead) .awaitSuccess() - .parseAs() + .parseAs() .let { if (it.code == 400) return@let null @@ -128,7 +128,7 @@ class BangumiApi( } } - suspend fun accessToken(code: String): BangumiOAuth { + suspend fun accessToken(code: String): BGMOAuth { return withIOContext { with(json) { client.newCall(accessTokenRequest(code)) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt index 1c23a8ec83..349ab48867 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiInterceptor.kt @@ -1,7 +1,7 @@ package eu.kanade.tachiyomi.data.track.bangumi import eu.kanade.tachiyomi.BuildConfig -import eu.kanade.tachiyomi.data.track.bangumi.dto.BangumiOAuth +import eu.kanade.tachiyomi.data.track.bangumi.dto.BGMOAuth import eu.kanade.tachiyomi.data.track.bangumi.dto.isExpired import kotlinx.serialization.json.Json import okhttp3.FormBody @@ -16,7 +16,7 @@ class BangumiInterceptor(private val bangumi: Bangumi) : Interceptor { /** * OAuth object used for authenticated requests. */ - private var oauth: BangumiOAuth? = bangumi.restoreToken() + private var oauth: BGMOAuth? = bangumi.restoreToken() override fun intercept(chain: Interceptor.Chain): Response { val originalRequest = chain.request() @@ -26,7 +26,7 @@ class BangumiInterceptor(private val bangumi: Bangumi) : Interceptor { if (currAuth.isExpired()) { val response = chain.proceed(BangumiApi.refreshTokenRequest(currAuth.refreshToken!!)) if (response.isSuccessful) { - newAuth(json.decodeFromString(response.body.string())) + newAuth(json.decodeFromString(response.body.string())) } else { response.close() } @@ -51,11 +51,11 @@ class BangumiInterceptor(private val bangumi: Bangumi) : Interceptor { .let(chain::proceed) } - fun newAuth(oauth: BangumiOAuth?) { + fun newAuth(oauth: BGMOAuth?) { this.oauth = if (oauth == null) { null } else { - BangumiOAuth( + BGMOAuth( oauth.accessToken, oauth.tokenType, System.currentTimeMillis() / 1000, diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiUtils.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiUtils.kt index a10e727538..5e38960bf0 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiUtils.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/BangumiUtils.kt @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.data.track.bangumi import eu.kanade.tachiyomi.data.database.models.Track -fun Track.toBangumiStatus() = when (status) { +fun Track.toApiStatus() = when (status) { Bangumi.READING -> "do" Bangumi.COMPLETED -> "collect" Bangumi.ON_HOLD -> "on_hold" diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiCollectionResponse.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMCollectionResponse.kt similarity index 94% rename from app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiCollectionResponse.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMCollectionResponse.kt index 8484775e00..85501934f7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiCollectionResponse.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMCollectionResponse.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class BangumiCollectionResponse( +data class BGMCollectionResponse( val code: Int?, val `private`: Int? = 0, val comment: String? = "", diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiOAuth.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMOAuth.kt similarity index 83% rename from app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiOAuth.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMOAuth.kt index 846a16dd5a..69b1a94fa7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiOAuth.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMOAuth.kt @@ -4,7 +4,7 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class BangumiOAuth( +data class BGMOAuth( @SerialName("access_token") val accessToken: String, @SerialName("token_type") @@ -22,4 +22,4 @@ data class BangumiOAuth( // Access token refresh before expired @Suppress("MagicNumber") -fun BangumiOAuth.isExpired() = (System.currentTimeMillis() / 1000) > (createdAt + expiresIn - 3600) +fun BGMOAuth.isExpired() = (System.currentTimeMillis() / 1000) > (createdAt + expiresIn - 3600) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiSearch.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMSearch.kt similarity index 68% rename from app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiSearch.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMSearch.kt index a2d7058c59..241b954306 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiSearch.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMSearch.kt @@ -5,29 +5,29 @@ import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @Serializable -data class BangumiSearchResult( - val list: List?, +data class BGMSearchResult( + val list: List?, val code: Int?, ) @Serializable -data class BangumiSearchItem( +data class BGMSearchItem( val id: Long, @SerialName("name_cn") val nameCn: String, val name: String, val type: Int, - val images: BangumiSearchItemCovers?, + val images: BGMSearchItemCovers?, @SerialName("eps_count") val epsCount: Long?, - val rating: BangumiSearchItemRating?, + val rating: BGMSearchItemRating?, val url: String, ) { fun toTrackSearch(trackId: Long): TrackSearch = TrackSearch.create(trackId).apply { - remote_id = this@BangumiSearchItem.id + remote_id = this@BGMSearchItem.id title = nameCn cover_url = images?.common ?: "" - summary = this@BangumiSearchItem.name + summary = this@BGMSearchItem.name score = rating?.score ?: -1.0 tracking_url = url total_chapters = epsCount ?: 0 @@ -35,11 +35,11 @@ data class BangumiSearchItem( } @Serializable -data class BangumiSearchItemCovers( +data class BGMSearchItemCovers( val common: String?, ) @Serializable -data class BangumiSearchItemRating( +data class BGMSearchItemRating( val score: Double?, ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiUser.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMUser.kt similarity index 100% rename from app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BangumiUser.kt rename to app/src/main/java/eu/kanade/tachiyomi/data/track/bangumi/dto/BGMUser.kt 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 a22e323888..152177253a 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 @@ -44,7 +44,7 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) putJsonObject("data") { put("type", "libraryEntries") putJsonObject("attributes") { - put("status", track.toKitsuStatus()) + put("status", track.toApiStatus()) put("progress", track.last_chapter_read.toInt()) } putJsonObject("relationships") { @@ -89,9 +89,9 @@ class KitsuApi(private val client: OkHttpClient, interceptor: KitsuInterceptor) put("type", "libraryEntries") put("id", track.remote_id) putJsonObject("attributes") { - put("status", track.toKitsuStatus()) + put("status", track.toApiStatus()) put("progress", track.last_chapter_read.toInt()) - put("ratingTwenty", track.toKitsuScore()) + put("ratingTwenty", track.toApiScore()) put("startedAt", KitsuDateHelper.convert(track.started_reading_date)) put("finishedAt", KitsuDateHelper.convert(track.finished_reading_date)) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuUtils.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuUtils.kt index 98e4e70e39..6a52ba1a41 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuUtils.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/kitsu/KitsuUtils.kt @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.track.kitsu import eu.kanade.tachiyomi.data.database.models.Track @Suppress("TooGenericExceptionThrown") -fun Track.toKitsuStatus() = when (status) { +fun Track.toApiStatus() = when (status) { Kitsu.READING -> "current" Kitsu.COMPLETED -> "completed" Kitsu.ON_HOLD -> "on_hold" @@ -12,6 +12,6 @@ fun Track.toKitsuStatus() = when (status) { else -> throw Exception("Unknown status") } -fun Track.toKitsuScore(): String? { +fun Track.toApiScore(): String? { return if (score > 0) (score * 2).toInt().toString() else null }