Fixing #178 and adding #171

This commit is contained in:
Jay 2020-04-07 00:34:23 -04:00
parent 4d8340a0c3
commit 963e125d64
7 changed files with 16 additions and 1 deletions

View File

@ -27,6 +27,8 @@ abstract class TrackService(val id: Int) {
abstract fun getStatusList(): List<Int>
abstract fun isCompletedStatus(index: Int): Boolean
abstract fun getStatus(status: Int): String
abstract fun getScoreList(): List<String>

View File

@ -38,6 +38,8 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
override fun getStatusList() = listOf(READING, PLANNING, COMPLETED, REPEATING, PAUSED, DROPPED)
override fun isCompletedStatus(index: Int) = getStatusList()[index] == COMPLETED
override fun getStatus(status: Int): String = with(context) {
when (status) {
READING -> getString(R.string.reading)

View File

@ -76,6 +76,8 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLANNING)
}
override fun isCompletedStatus(index: Int) = getStatusList()[index] == COMPLETED
override fun getStatus(status: Int): String = with(context) {
when (status) {
READING -> getString(R.string.reading)

View File

@ -44,6 +44,8 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
return listOf(READING, PLAN_TO_READ, COMPLETED, ON_HOLD, DROPPED)
}
override fun isCompletedStatus(index: Int) = getStatusList()[index] == COMPLETED
override fun getStatus(status: Int): String = with(context) {
when (status) {
READING -> getString(R.string.currently_reading)

View File

@ -36,6 +36,8 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLAN_TO_READ)
}
override fun isCompletedStatus(index: Int) = getStatusList()[index] == COMPLETED
override fun getScoreList(): List<String> {
return IntRange(0, 10).map(Int::toString)
}
@ -121,7 +123,8 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
networkService.cookieManager.remove(BASE_URL.toHttpUrlOrNull()!!)
}
private val isAuthorized = super.isLogged && getCSRF().isNotEmpty() && checkCookies()
private val isAuthorized: Boolean
get() = super.isLogged && getCSRF().isNotEmpty() && checkCookies()
fun getCSRF(): String = preferences.trackToken(this).getOrDefault()

View File

@ -27,6 +27,8 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
return listOf(READING, COMPLETED, ON_HOLD, DROPPED, PLANNING, REPEATING)
}
override fun isCompletedStatus(index: Int) = getStatusList()[index] == COMPLETED
override fun getStatus(status: Int): String = with(context) {
when (status) {
READING -> getString(R.string.reading)

View File

@ -821,6 +821,8 @@ class MangaDetailsPresenter(
fun setStatus(item: TrackItem, index: Int) {
val track = item.track!!
track.status = item.service.getStatusList()[index]
if (item.service.isCompletedStatus(index) && track.total_chapters > 0)
track.last_chapter_read = track.total_chapters
updateRemote(track, item.service)
}