From 47a2d066821d0f65680255f5ce6442fd0af55382 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 10 Mar 2023 23:01:10 -0500 Subject: [PATCH] Refactor tracker status string mappings Should fix #9195 --- .../presentation/track/TrackInfoDialogHome.kt | 5 +++-- .../track/TrackInfoDialogSelector.kt | 4 ++-- .../tachiyomi/data/track/TrackManager.kt | 14 ++++++------ .../tachiyomi/data/track/TrackService.kt | 3 ++- .../tachiyomi/data/track/anilist/Anilist.kt | 22 +++++++++---------- .../tachiyomi/data/track/bangumi/Bangumi.kt | 20 ++++++++--------- .../tachiyomi/data/track/kavita/Kavita.kt | 13 +++++------ .../tachiyomi/data/track/kitsu/Kitsu.kt | 20 ++++++++--------- .../tachiyomi/data/track/komga/Komga.kt | 13 +++++------ .../data/track/mangaupdates/MangaUpdates.kt | 20 ++++++++--------- .../data/track/myanimelist/MyAnimeList.kt | 22 +++++++++---------- .../data/track/shikimori/Shikimori.kt | 22 +++++++++---------- .../tachiyomi/data/track/suwayomi/Suwayomi.kt | 17 +++++++------- .../ui/manga/track/TrackInfoDialog.kt | 2 +- 14 files changed, 92 insertions(+), 105 deletions(-) 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 3662b0bc07..c64d1ef122 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogHome.kt @@ -1,5 +1,6 @@ package eu.kanade.presentation.track +import androidx.annotation.StringRes import androidx.compose.animation.animateContentSize import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -125,7 +126,7 @@ fun TrackInfoDialogHome( private fun TrackInfoItem( title: String, service: TrackService, - status: String, + @StringRes status: Int?, onStatusClick: () -> Unit, chapters: String, onChaptersClick: () -> Unit, @@ -187,7 +188,7 @@ private fun TrackInfoItem( Row(modifier = Modifier.height(IntrinsicSize.Min)) { TrackDetailsItem( modifier = Modifier.weight(1f), - text = status, + text = status?.let { stringResource(it) } ?: "", onClick = onStatusClick, ) VerticalDivider() diff --git a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt index 0f0d9593aa..bffff72e9f 100644 --- a/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt +++ b/app/src/main/java/eu/kanade/presentation/track/TrackInfoDialogSelector.kt @@ -41,7 +41,7 @@ import tachiyomi.presentation.core.util.isScrolledToStart fun TrackStatusSelector( selection: Int, onSelectionChange: (Int) -> Unit, - selections: Map, + selections: Map, onConfirm: () -> Unit, onDismissRequest: () -> Unit, ) { @@ -69,7 +69,7 @@ fun TrackStatusSelector( onClick = null, ) Text( - text = value, + text = value?.let { stringResource(it) } ?: "", style = MaterialTheme.typography.bodyLarge.merge(), modifier = Modifier.padding(start = 24.dp), ) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt index 10b396f447..e1abbec832 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackManager.kt @@ -25,15 +25,15 @@ class TrackManager(context: Context) { const val SUWAYOMI = 9L } - val myAnimeList = MyAnimeList(context, MYANIMELIST) - val aniList = Anilist(context, ANILIST) - val kitsu = Kitsu(context, KITSU) - val shikimori = Shikimori(context, SHIKIMORI) - val bangumi = Bangumi(context, BANGUMI) + val myAnimeList = MyAnimeList(MYANIMELIST) + val aniList = Anilist(ANILIST) + val kitsu = Kitsu(KITSU) + val shikimori = Shikimori(SHIKIMORI) + val bangumi = Bangumi(BANGUMI) val komga = Komga(context, KOMGA) - val mangaUpdates = MangaUpdates(context, MANGA_UPDATES) + val mangaUpdates = MangaUpdates(MANGA_UPDATES) val kavita = Kavita(context, KAVITA) - val suwayomi = Suwayomi(context, SUWAYOMI) + val suwayomi = Suwayomi(SUWAYOMI) val services = listOf(myAnimeList, aniList, kitsu, shikimori, bangumi, komga, mangaUpdates, kavita, suwayomi) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt index b36a468b74..9bd87708f8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/track/TrackService.kt @@ -50,7 +50,8 @@ abstract class TrackService(val id: Long) { abstract fun getStatusList(): List - abstract fun getStatus(status: Int): String + @StringRes + abstract fun getStatus(status: Int): Int? abstract fun getReadingStatus(): Int 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 1faae7b3a0..e93d83817a 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.anilist -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -13,7 +12,7 @@ import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy import tachiyomi.domain.track.model.Track as DomainTrack -class Anilist(private val context: Context, id: Long) : TrackService(id) { +class Anilist(id: Long) : TrackService(id) { companion object { const val READING = 1 @@ -61,16 +60,15 @@ class Anilist(private val context: Context, id: Long) : TrackService(id) { return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ, REREADING) } - override fun getStatus(status: Int): String = with(context) { - when (status) { - READING -> getString(R.string.reading) - PLAN_TO_READ -> getString(R.string.plan_to_read) - COMPLETED -> getString(R.string.completed) - ON_HOLD -> getString(R.string.on_hold) - DROPPED -> getString(R.string.dropped) - REREADING -> getString(R.string.repeating) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + READING -> R.string.reading + PLAN_TO_READ -> R.string.plan_to_read + COMPLETED -> R.string.completed + ON_HOLD -> R.string.on_hold + DROPPED -> R.string.dropped + REREADING -> R.string.repeating + else -> null } override fun getReadingStatus(): Int = READING 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 b43cea74c1..e131c33a11 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.bangumi -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -12,7 +11,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class Bangumi(private val context: Context, id: Long) : TrackService(id) { +class Bangumi(id: Long) : TrackService(id) { private val json: Json by injectLazy() @@ -94,15 +93,14 @@ class Bangumi(private val context: Context, id: Long) : TrackService(id) { return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ) } - override fun getStatus(status: Int): String = with(context) { - when (status) { - READING -> getString(R.string.reading) - PLAN_TO_READ -> getString(R.string.plan_to_read) - COMPLETED -> getString(R.string.completed) - ON_HOLD -> getString(R.string.on_hold) - DROPPED -> getString(R.string.dropped) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + READING -> R.string.reading + PLAN_TO_READ -> R.string.plan_to_read + COMPLETED -> R.string.completed + ON_HOLD -> R.string.on_hold + DROPPED -> R.string.dropped + else -> null } override fun getReadingStatus(): Int = READING 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 e242f0da3c..205228ba2f 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 @@ -36,13 +36,12 @@ class Kavita(private val context: Context, id: Long) : TrackService(id), Enhance override fun getStatusList() = listOf(UNREAD, READING, COMPLETED) - override fun getStatus(status: Int): String = with(context) { - when (status) { - UNREAD -> getString(R.string.unread) - READING -> getString(R.string.reading) - COMPLETED -> getString(R.string.completed) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + UNREAD -> R.string.unread + READING -> R.string.reading + COMPLETED -> R.string.completed + else -> null } override fun getReadingStatus(): Int = READING 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 0799229e5e..7a0c8eef69 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.kitsu -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -13,7 +12,7 @@ import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy import java.text.DecimalFormat -class Kitsu(private val context: Context, id: Long) : TrackService(id) { +class Kitsu(id: Long) : TrackService(id) { companion object { const val READING = 1 @@ -42,15 +41,14 @@ class Kitsu(private val context: Context, id: Long) : TrackService(id) { return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ) } - override fun getStatus(status: Int): String = with(context) { - when (status) { - READING -> getString(R.string.reading) - PLAN_TO_READ -> getString(R.string.plan_to_read) - COMPLETED -> getString(R.string.completed) - ON_HOLD -> getString(R.string.on_hold) - DROPPED -> getString(R.string.dropped) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + READING -> R.string.reading + PLAN_TO_READ -> R.string.plan_to_read + COMPLETED -> R.string.completed + ON_HOLD -> R.string.on_hold + DROPPED -> R.string.dropped + else -> null } override fun getReadingStatus(): Int = READING 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 5a7671ee4a..5dbc6ca09e 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 @@ -38,13 +38,12 @@ class Komga(private val context: Context, id: Long) : TrackService(id), Enhanced override fun getStatusList() = listOf(UNREAD, READING, COMPLETED) - override fun getStatus(status: Int): String = with(context) { - when (status) { - UNREAD -> getString(R.string.unread) - READING -> getString(R.string.reading) - COMPLETED -> getString(R.string.completed) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + UNREAD -> R.string.unread + READING -> R.string.reading + COMPLETED -> R.string.completed + else -> null } override fun getReadingStatus(): Int = READING 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 17c6c0ae9f..1afe7914e5 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.mangaupdates -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -10,7 +9,7 @@ import eu.kanade.tachiyomi.data.track.mangaupdates.dto.copyTo import eu.kanade.tachiyomi.data.track.mangaupdates.dto.toTrackSearch import eu.kanade.tachiyomi.data.track.model.TrackSearch -class MangaUpdates(private val context: Context, id: Long) : TrackService(id) { +class MangaUpdates(id: Long) : TrackService(id) { companion object { const val READING_LIST = 0 @@ -35,15 +34,14 @@ class MangaUpdates(private val context: Context, id: Long) : TrackService(id) { return listOf(READING_LIST, COMPLETE_LIST, ON_HOLD_LIST, UNFINISHED_LIST, WISH_LIST) } - override fun getStatus(status: Int): String = with(context) { - when (status) { - READING_LIST -> getString(R.string.reading_list) - WISH_LIST -> getString(R.string.wish_list) - COMPLETE_LIST -> getString(R.string.complete_list) - ON_HOLD_LIST -> getString(R.string.on_hold_list) - UNFINISHED_LIST -> getString(R.string.unfinished_list) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + READING_LIST -> R.string.reading_list + WISH_LIST -> R.string.wish_list + COMPLETE_LIST -> R.string.complete_list + ON_HOLD_LIST -> R.string.on_hold_list + UNFINISHED_LIST -> R.string.unfinished_list + else -> null } override fun getReadingStatus(): Int = READING_LIST 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 d3e85a63f7..3fca9e478b 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.myanimelist -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -12,7 +11,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class MyAnimeList(private val context: Context, id: Long) : TrackService(id) { +class MyAnimeList(id: Long) : TrackService(id) { companion object { const val READING = 1 @@ -44,16 +43,15 @@ class MyAnimeList(private val context: Context, id: Long) : TrackService(id) { return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ, REREADING) } - override fun getStatus(status: Int): String = with(context) { - when (status) { - READING -> getString(R.string.reading) - PLAN_TO_READ -> getString(R.string.plan_to_read) - COMPLETED -> getString(R.string.completed) - ON_HOLD -> getString(R.string.on_hold) - DROPPED -> getString(R.string.dropped) - REREADING -> getString(R.string.repeating) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + READING -> R.string.reading + PLAN_TO_READ -> R.string.plan_to_read + COMPLETED -> R.string.completed + ON_HOLD -> R.string.on_hold + DROPPED -> R.string.dropped + REREADING -> R.string.repeating + else -> null } override fun getReadingStatus(): Int = READING 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 33c04e044e..07d80a2e88 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.shikimori -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -12,7 +11,7 @@ import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import uy.kohesive.injekt.injectLazy -class Shikimori(private val context: Context, id: Long) : TrackService(id) { +class Shikimori(id: Long) : TrackService(id) { companion object { const val READING = 1 @@ -98,16 +97,15 @@ class Shikimori(private val context: Context, id: Long) : TrackService(id) { return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ, REREADING) } - override fun getStatus(status: Int): String = with(context) { - when (status) { - READING -> getString(R.string.reading) - PLAN_TO_READ -> getString(R.string.plan_to_read) - COMPLETED -> getString(R.string.completed) - ON_HOLD -> getString(R.string.on_hold) - DROPPED -> getString(R.string.dropped) - REREADING -> getString(R.string.repeating) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + READING -> R.string.reading + PLAN_TO_READ -> R.string.plan_to_read + COMPLETED -> R.string.completed + ON_HOLD -> R.string.on_hold + DROPPED -> R.string.dropped + REREADING -> R.string.repeating + else -> null } override fun getReadingStatus(): Int = READING 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 367a6cf41e..8b00dfe9f5 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 @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.data.track.suwayomi -import android.content.Context import android.graphics.Color import androidx.annotation.StringRes import eu.kanade.tachiyomi.R @@ -12,7 +11,8 @@ import eu.kanade.tachiyomi.source.Source import tachiyomi.domain.manga.model.Manga as DomainManga import tachiyomi.domain.track.model.Track as DomainTrack -class Suwayomi(private val context: Context, id: Long) : TrackService(id), EnhancedTrackService { +class Suwayomi(id: Long) : TrackService(id), EnhancedTrackService { + val api by lazy { TachideskApi() } @StringRes @@ -30,13 +30,12 @@ class Suwayomi(private val context: Context, id: Long) : TrackService(id), Enhan override fun getStatusList() = listOf(UNREAD, READING, COMPLETED) - override fun getStatus(status: Int): String = with(context) { - when (status) { - UNREAD -> getString(R.string.unread) - READING -> getString(R.string.reading) - COMPLETED -> getString(R.string.completed) - else -> "" - } + @StringRes + override fun getStatus(status: Int): Int? = when (status) { + UNREAD -> R.string.unread + READING -> R.string.reading + COMPLETED -> R.string.completed + else -> null } override fun getReadingStatus(): Int = READING 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 7305bd5578..0bbe71eaeb 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 @@ -293,7 +293,7 @@ private data class TrackStatusSelectorScreen( private val service: TrackService, ) : StateScreenModel(State(track.status)) { - fun getSelections(): Map { + fun getSelections(): Map { return service.getStatusList().associateWith { service.getStatus(it) } }