Make default tracking status depend if the user has read chapter or not (#5567)

- When user reads a chapter change tracking status to reading
This commit is contained in:
Andreas 2021-07-17 17:26:29 +02:00 committed by GitHub
parent ef84ed4982
commit c0647c3110
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 120 additions and 23 deletions

View File

@ -36,6 +36,10 @@ abstract class TrackService(val id: Int) {
abstract fun getStatus(status: Int): String abstract fun getStatus(status: Int): String
abstract fun getReadingStatus(): Int
abstract fun getRereadingStatus(): Int
abstract fun getCompletionStatus(): Int abstract fun getCompletionStatus(): Int
abstract fun getScoreList(): List<String> abstract fun getScoreList(): List<String>
@ -46,9 +50,9 @@ abstract class TrackService(val id: Int) {
abstract fun displayScore(track: Track): String abstract fun displayScore(track: Track): String
abstract suspend fun update(track: Track): Track abstract suspend fun update(track: Track, didReadChapter: Boolean = false): Track
abstract suspend fun bind(track: Track): Track abstract suspend fun bind(track: Track, hasReadChapters: Boolean = false): Track
abstract suspend fun search(query: String): List<TrackSearch> abstract suspend fun search(query: String): List<TrackSearch>

View File

@ -72,6 +72,10 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
} }
} }
override fun getReadingStatus(): Int = READING
override fun getRereadingStatus(): Int = REPEATING
override fun getCompletionStatus(): Int = COMPLETED override fun getCompletionStatus(): Int = COMPLETED
override fun getScoreList(): List<String> { override fun getScoreList(): List<String> {
@ -134,7 +138,7 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
return api.addLibManga(track) return api.addLibManga(track)
} }
override suspend fun update(track: Track): Track { override suspend fun update(track: Track, didReadChapter: Boolean): Track {
// If user was using API v1 fetch library_id // If user was using API v1 fetch library_id
if (track.library_id == null || track.library_id!! == 0L) { if (track.library_id == null || track.library_id!! == 0L) {
val libManga = api.findLibManga(track, getUsername().toInt()) val libManga = api.findLibManga(track, getUsername().toInt())
@ -142,18 +146,31 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
track.library_id = libManga.library_id track.library_id = libManga.library_id
} }
if (track.status != COMPLETED) {
if (track.status != REPEATING && didReadChapter) {
track.status = READING
}
}
return api.updateLibManga(track) return api.updateLibManga(track)
} }
override suspend fun bind(track: Track): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
val remoteTrack = api.findLibManga(track, getUsername().toInt()) val remoteTrack = api.findLibManga(track, getUsername().toInt())
return if (remoteTrack != null) { return if (remoteTrack != null) {
track.copyPersonalFrom(remoteTrack) track.copyPersonalFrom(remoteTrack)
track.library_id = remoteTrack.library_id track.library_id = remoteTrack.library_id
if (track.status != COMPLETED) {
val isRereading = track.status == REPEATING
track.status = if (isRereading.not() && hasReadChapters) READING else track.status
}
update(track) update(track)
} else { } else {
// Set default fields if it's not found in the list // Set default fields if it's not found in the list
track.status = READING track.status = if (hasReadChapters) READING else PLANNING
track.score = 0F track.score = 0F
add(track) add(track)
} }

View File

@ -35,24 +35,34 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
return api.addLibManga(track) return api.addLibManga(track)
} }
override suspend fun update(track: Track): Track { override suspend fun update(track: Track, didReadChapter: Boolean): Track {
if (track.status != COMPLETED) {
if (didReadChapter) {
track.status = READING
}
}
return api.updateLibManga(track) return api.updateLibManga(track)
} }
override suspend fun bind(track: Track): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
val statusTrack = api.statusLibManga(track) val statusTrack = api.statusLibManga(track)
val remoteTrack = api.findLibManga(track) val remoteTrack = api.findLibManga(track)
return if (remoteTrack != null && statusTrack != null) { return if (remoteTrack != null && statusTrack != null) {
track.copyPersonalFrom(remoteTrack) track.copyPersonalFrom(remoteTrack)
track.library_id = remoteTrack.library_id track.library_id = remoteTrack.library_id
track.status = statusTrack.status
if (track.status != COMPLETED) {
track.status = if (hasReadChapters) READING else statusTrack.status
}
track.score = statusTrack.score track.score = statusTrack.score
track.last_chapter_read = statusTrack.last_chapter_read track.last_chapter_read = statusTrack.last_chapter_read
track.total_chapters = remoteTrack.total_chapters track.total_chapters = remoteTrack.total_chapters
refresh(track) refresh(track)
} else { } else {
// Set default fields if it's not found in the list // Set default fields if it's not found in the list
track.status = READING track.status = if (hasReadChapters) READING else PLANNING
track.score = 0F track.score = 0F
add(track) add(track)
update(track) update(track)
@ -91,6 +101,10 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
} }
} }
override fun getReadingStatus(): Int = READING
override fun getRereadingStatus(): Int = -1
override fun getCompletionStatus(): Int = COMPLETED override fun getCompletionStatus(): Int = COMPLETED
override suspend fun login(username: String, password: String) = login(password) override suspend fun login(username: String, password: String) = login(password)

View File

@ -51,6 +51,10 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
} }
} }
override fun getReadingStatus(): Int = READING
override fun getRereadingStatus(): Int = -1
override fun getCompletionStatus(): Int = COMPLETED override fun getCompletionStatus(): Int = COMPLETED
override fun getScoreList(): List<String> { override fun getScoreList(): List<String> {
@ -71,18 +75,29 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
return api.addLibManga(track, getUserId()) return api.addLibManga(track, getUserId())
} }
override suspend fun update(track: Track): Track { override suspend fun update(track: Track, didReadChapter: Boolean): Track {
if (track.status != COMPLETED) {
if (didReadChapter) {
track.status = READING
}
}
return api.updateLibManga(track) return api.updateLibManga(track)
} }
override suspend fun bind(track: Track): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
val remoteTrack = api.findLibManga(track, getUserId()) val remoteTrack = api.findLibManga(track, getUserId())
return if (remoteTrack != null) { return if (remoteTrack != null) {
track.copyPersonalFrom(remoteTrack) track.copyPersonalFrom(remoteTrack)
track.media_id = remoteTrack.media_id track.media_id = remoteTrack.media_id
if (track.status != COMPLETED) {
track.status = if (hasReadChapters) READING else track.status
}
update(track) update(track)
} else { } else {
track.status = READING track.status = if (hasReadChapters) READING else PLAN_TO_READ
track.score = 0F track.score = 0F
add(track) add(track)
} }

View File

@ -49,17 +49,27 @@ class Komga(private val context: Context, id: Int) : TrackService(id), Unattende
} }
} }
override fun getReadingStatus(): Int = READING
override fun getRereadingStatus(): Int = -1
override fun getCompletionStatus(): Int = COMPLETED override fun getCompletionStatus(): Int = COMPLETED
override fun getScoreList(): List<String> = emptyList() override fun getScoreList(): List<String> = emptyList()
override fun displayScore(track: Track): String = "" override fun displayScore(track: Track): String = ""
override suspend fun update(track: Track): Track { override suspend fun update(track: Track, didReadChapter: Boolean): Track {
if (track.status != COMPLETED) {
if (didReadChapter) {
track.status = READING
}
}
return api.updateProgress(track) return api.updateProgress(track)
} }
override suspend fun bind(track: Track): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
return track return track
} }

View File

@ -56,6 +56,10 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
} }
} }
override fun getReadingStatus(): Int = READING
override fun getRereadingStatus(): Int = REREADING
override fun getCompletionStatus(): Int = COMPLETED override fun getCompletionStatus(): Int = COMPLETED
override fun getScoreList(): List<String> { override fun getScoreList(): List<String> {
@ -67,22 +71,35 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
} }
private suspend fun add(track: Track): Track { private suspend fun add(track: Track): Track {
return api.updateItem(track)
}
override suspend fun update(track: Track, didReadChapter: Boolean): Track {
if (track.status != COMPLETED) {
if (track.status != REREADING && didReadChapter) {
track.status = READING track.status = READING
track.score = 0F }
}
return api.updateItem(track) return api.updateItem(track)
} }
override suspend fun update(track: Track): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
return api.updateItem(track)
}
override suspend fun bind(track: Track): Track {
val remoteTrack = api.findListItem(track) val remoteTrack = api.findListItem(track)
return if (remoteTrack != null) { return if (remoteTrack != null) {
track.copyPersonalFrom(remoteTrack) track.copyPersonalFrom(remoteTrack)
track.media_id = remoteTrack.media_id track.media_id = remoteTrack.media_id
if (track.status != COMPLETED) {
val isRereading = track.status == REREADING
track.status = if (isRereading.not() && hasReadChapters) READING else track.status
}
update(track) update(track)
} else { } else {
// Set default fields if it's not found in the list
track.status = if (hasReadChapters) READING else PLAN_TO_READ
track.score = 0F
add(track) add(track)
} }
} }

View File

@ -44,19 +44,31 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
return api.addLibManga(track, getUsername()) return api.addLibManga(track, getUsername())
} }
override suspend fun update(track: Track): Track { override suspend fun update(track: Track, didReadChapter: Boolean): Track {
if (track.status != COMPLETED) {
if (track.status != REPEATING && didReadChapter) {
track.status = READING
}
}
return api.updateLibManga(track, getUsername()) return api.updateLibManga(track, getUsername())
} }
override suspend fun bind(track: Track): Track { override suspend fun bind(track: Track, hasReadChapters: Boolean): Track {
val remoteTrack = api.findLibManga(track, getUsername()) val remoteTrack = api.findLibManga(track, getUsername())
return if (remoteTrack != null) { return if (remoteTrack != null) {
track.copyPersonalFrom(remoteTrack) track.copyPersonalFrom(remoteTrack)
track.library_id = remoteTrack.library_id track.library_id = remoteTrack.library_id
if (track.status != COMPLETED) {
val isRereading = track.status == REPEATING
track.status = if (isRereading.not() && hasReadChapters) READING else track.status
}
update(track) update(track)
} else { } else {
// Set default fields if it's not found in the list // Set default fields if it's not found in the list
track.status = READING track.status = if (hasReadChapters) READING else PLANNING
track.score = 0F track.score = 0F
add(track) add(track)
} }
@ -94,6 +106,10 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
} }
} }
override fun getReadingStatus(): Int = READING
override fun getRereadingStatus(): Int = REPEATING
override fun getCompletionStatus(): Int = COMPLETED override fun getCompletionStatus(): Int = COMPLETED
override suspend fun login(username: String, password: String) = login(password) override suspend fun login(username: String, password: String) = login(password)

View File

@ -779,7 +779,8 @@ class MangaPresenter(
item.manga_id = manga.id!! item.manga_id = manga.id!!
launchIO { launchIO {
try { try {
service.bind(item) val hasReadChapters = allChapters.any { it.read }
service.bind(item, hasReadChapters)
db.insertTrack(item).executeAsBlocking() db.insertTrack(item).executeAsBlocking()
if (service is UnattendedTrackService) { if (service is UnattendedTrackService) {
@ -830,6 +831,9 @@ class MangaPresenter(
fun setTrackerLastChapterRead(item: TrackItem, chapterNumber: Int) { fun setTrackerLastChapterRead(item: TrackItem, chapterNumber: Int) {
val track = item.track!! val track = item.track!!
if (track.last_chapter_read == 0 && track.last_chapter_read < chapterNumber && track.status != item.service.getRereadingStatus()) {
track.status = item.service.getReadingStatus()
}
track.last_chapter_read = chapterNumber track.last_chapter_read = chapterNumber
if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) { if (track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) {
track.status = item.service.getCompletionStatus() track.status = item.service.getCompletionStatus()

View File

@ -713,7 +713,7 @@ class ReaderPresenter(
// for a while. The view can still be garbage collected. // for a while. The view can still be garbage collected.
async { async {
runCatching { runCatching {
service.update(track) service.update(track, true)
db.insertTrack(track).executeAsBlocking() db.insertTrack(track).executeAsBlocking()
} }
} }