Refactor tracker status string mappings

Should fix #9195
This commit is contained in:
arkon 2023-03-10 23:01:10 -05:00
parent ce66ed0389
commit 47a2d06682
14 changed files with 92 additions and 105 deletions

View File

@ -1,5 +1,6 @@
package eu.kanade.presentation.track package eu.kanade.presentation.track
import androidx.annotation.StringRes
import androidx.compose.animation.animateContentSize import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@ -125,7 +126,7 @@ fun TrackInfoDialogHome(
private fun TrackInfoItem( private fun TrackInfoItem(
title: String, title: String,
service: TrackService, service: TrackService,
status: String, @StringRes status: Int?,
onStatusClick: () -> Unit, onStatusClick: () -> Unit,
chapters: String, chapters: String,
onChaptersClick: () -> Unit, onChaptersClick: () -> Unit,
@ -187,7 +188,7 @@ private fun TrackInfoItem(
Row(modifier = Modifier.height(IntrinsicSize.Min)) { Row(modifier = Modifier.height(IntrinsicSize.Min)) {
TrackDetailsItem( TrackDetailsItem(
modifier = Modifier.weight(1f), modifier = Modifier.weight(1f),
text = status, text = status?.let { stringResource(it) } ?: "",
onClick = onStatusClick, onClick = onStatusClick,
) )
VerticalDivider() VerticalDivider()

View File

@ -41,7 +41,7 @@ import tachiyomi.presentation.core.util.isScrolledToStart
fun TrackStatusSelector( fun TrackStatusSelector(
selection: Int, selection: Int,
onSelectionChange: (Int) -> Unit, onSelectionChange: (Int) -> Unit,
selections: Map<Int, String>, selections: Map<Int, Int?>,
onConfirm: () -> Unit, onConfirm: () -> Unit,
onDismissRequest: () -> Unit, onDismissRequest: () -> Unit,
) { ) {
@ -69,7 +69,7 @@ fun TrackStatusSelector(
onClick = null, onClick = null,
) )
Text( Text(
text = value, text = value?.let { stringResource(it) } ?: "",
style = MaterialTheme.typography.bodyLarge.merge(), style = MaterialTheme.typography.bodyLarge.merge(),
modifier = Modifier.padding(start = 24.dp), modifier = Modifier.padding(start = 24.dp),
) )

View File

@ -25,15 +25,15 @@ class TrackManager(context: Context) {
const val SUWAYOMI = 9L const val SUWAYOMI = 9L
} }
val myAnimeList = MyAnimeList(context, MYANIMELIST) val myAnimeList = MyAnimeList(MYANIMELIST)
val aniList = Anilist(context, ANILIST) val aniList = Anilist(ANILIST)
val kitsu = Kitsu(context, KITSU) val kitsu = Kitsu(KITSU)
val shikimori = Shikimori(context, SHIKIMORI) val shikimori = Shikimori(SHIKIMORI)
val bangumi = Bangumi(context, BANGUMI) val bangumi = Bangumi(BANGUMI)
val komga = Komga(context, KOMGA) val komga = Komga(context, KOMGA)
val mangaUpdates = MangaUpdates(context, MANGA_UPDATES) val mangaUpdates = MangaUpdates(MANGA_UPDATES)
val kavita = Kavita(context, KAVITA) 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) val services = listOf(myAnimeList, aniList, kitsu, shikimori, bangumi, komga, mangaUpdates, kavita, suwayomi)

View File

@ -50,7 +50,8 @@ abstract class TrackService(val id: Long) {
abstract fun getStatusList(): List<Int> abstract fun getStatusList(): List<Int>
abstract fun getStatus(status: Int): String @StringRes
abstract fun getStatus(status: Int): Int?
abstract fun getReadingStatus(): Int abstract fun getReadingStatus(): Int

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.anilist package eu.kanade.tachiyomi.data.track.anilist
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -13,7 +12,7 @@ import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import tachiyomi.domain.track.model.Track as DomainTrack 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 { companion object {
const val READING = 1 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) return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ, REREADING)
} }
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
READING -> getString(R.string.reading) READING -> R.string.reading
PLAN_TO_READ -> getString(R.string.plan_to_read) PLAN_TO_READ -> R.string.plan_to_read
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
ON_HOLD -> getString(R.string.on_hold) ON_HOLD -> R.string.on_hold
DROPPED -> getString(R.string.dropped) DROPPED -> R.string.dropped
REREADING -> getString(R.string.repeating) REREADING -> R.string.repeating
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.bangumi package eu.kanade.tachiyomi.data.track.bangumi
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -12,7 +11,7 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy 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() 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) return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ)
} }
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
READING -> getString(R.string.reading) READING -> R.string.reading
PLAN_TO_READ -> getString(R.string.plan_to_read) PLAN_TO_READ -> R.string.plan_to_read
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
ON_HOLD -> getString(R.string.on_hold) ON_HOLD -> R.string.on_hold
DROPPED -> getString(R.string.dropped) DROPPED -> R.string.dropped
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -36,13 +36,12 @@ class Kavita(private val context: Context, id: Long) : TrackService(id), Enhance
override fun getStatusList() = listOf(UNREAD, READING, COMPLETED) override fun getStatusList() = listOf(UNREAD, READING, COMPLETED)
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
UNREAD -> getString(R.string.unread) UNREAD -> R.string.unread
READING -> getString(R.string.reading) READING -> R.string.reading
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.kitsu package eu.kanade.tachiyomi.data.track.kitsu
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -13,7 +12,7 @@ import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
import java.text.DecimalFormat import java.text.DecimalFormat
class Kitsu(private val context: Context, id: Long) : TrackService(id) { class Kitsu(id: Long) : TrackService(id) {
companion object { companion object {
const val READING = 1 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) return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ)
} }
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
READING -> getString(R.string.reading) READING -> R.string.reading
PLAN_TO_READ -> getString(R.string.plan_to_read) PLAN_TO_READ -> R.string.plan_to_read
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
ON_HOLD -> getString(R.string.on_hold) ON_HOLD -> R.string.on_hold
DROPPED -> getString(R.string.dropped) DROPPED -> R.string.dropped
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -38,13 +38,12 @@ class Komga(private val context: Context, id: Long) : TrackService(id), Enhanced
override fun getStatusList() = listOf(UNREAD, READING, COMPLETED) override fun getStatusList() = listOf(UNREAD, READING, COMPLETED)
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
UNREAD -> getString(R.string.unread) UNREAD -> R.string.unread
READING -> getString(R.string.reading) READING -> R.string.reading
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.mangaupdates package eu.kanade.tachiyomi.data.track.mangaupdates
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R 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.mangaupdates.dto.toTrackSearch
import eu.kanade.tachiyomi.data.track.model.TrackSearch 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 { companion object {
const val READING_LIST = 0 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) return listOf(READING_LIST, COMPLETE_LIST, ON_HOLD_LIST, UNFINISHED_LIST, WISH_LIST)
} }
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
READING_LIST -> getString(R.string.reading_list) READING_LIST -> R.string.reading_list
WISH_LIST -> getString(R.string.wish_list) WISH_LIST -> R.string.wish_list
COMPLETE_LIST -> getString(R.string.complete_list) COMPLETE_LIST -> R.string.complete_list
ON_HOLD_LIST -> getString(R.string.on_hold_list) ON_HOLD_LIST -> R.string.on_hold_list
UNFINISHED_LIST -> getString(R.string.unfinished_list) UNFINISHED_LIST -> R.string.unfinished_list
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING_LIST override fun getReadingStatus(): Int = READING_LIST

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.myanimelist package eu.kanade.tachiyomi.data.track.myanimelist
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -12,7 +11,7 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class MyAnimeList(private val context: Context, id: Long) : TrackService(id) { class MyAnimeList(id: Long) : TrackService(id) {
companion object { companion object {
const val READING = 1 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) return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ, REREADING)
} }
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
READING -> getString(R.string.reading) READING -> R.string.reading
PLAN_TO_READ -> getString(R.string.plan_to_read) PLAN_TO_READ -> R.string.plan_to_read
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
ON_HOLD -> getString(R.string.on_hold) ON_HOLD -> R.string.on_hold
DROPPED -> getString(R.string.dropped) DROPPED -> R.string.dropped
REREADING -> getString(R.string.repeating) REREADING -> R.string.repeating
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.shikimori package eu.kanade.tachiyomi.data.track.shikimori
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
@ -12,7 +11,7 @@ import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import uy.kohesive.injekt.injectLazy import uy.kohesive.injekt.injectLazy
class Shikimori(private val context: Context, id: Long) : TrackService(id) { class Shikimori(id: Long) : TrackService(id) {
companion object { companion object {
const val READING = 1 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) return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ, REREADING)
} }
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
READING -> getString(R.string.reading) READING -> R.string.reading
PLAN_TO_READ -> getString(R.string.plan_to_read) PLAN_TO_READ -> R.string.plan_to_read
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
ON_HOLD -> getString(R.string.on_hold) ON_HOLD -> R.string.on_hold
DROPPED -> getString(R.string.dropped) DROPPED -> R.string.dropped
REREADING -> getString(R.string.repeating) REREADING -> R.string.repeating
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -1,6 +1,5 @@
package eu.kanade.tachiyomi.data.track.suwayomi package eu.kanade.tachiyomi.data.track.suwayomi
import android.content.Context
import android.graphics.Color import android.graphics.Color
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.tachiyomi.R 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.manga.model.Manga as DomainManga
import tachiyomi.domain.track.model.Track as DomainTrack 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() } val api by lazy { TachideskApi() }
@StringRes @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 getStatusList() = listOf(UNREAD, READING, COMPLETED)
override fun getStatus(status: Int): String = with(context) { @StringRes
when (status) { override fun getStatus(status: Int): Int? = when (status) {
UNREAD -> getString(R.string.unread) UNREAD -> R.string.unread
READING -> getString(R.string.reading) READING -> R.string.reading
COMPLETED -> getString(R.string.completed) COMPLETED -> R.string.completed
else -> "" else -> null
}
} }
override fun getReadingStatus(): Int = READING override fun getReadingStatus(): Int = READING

View File

@ -293,7 +293,7 @@ private data class TrackStatusSelectorScreen(
private val service: TrackService, private val service: TrackService,
) : StateScreenModel<Model.State>(State(track.status)) { ) : StateScreenModel<Model.State>(State(track.status)) {
fun getSelections(): Map<Int, String> { fun getSelections(): Map<Int, Int?> {
return service.getStatusList().associateWith { service.getStatus(it) } return service.getStatusList().associateWith { service.getStatus(it) }
} }