Set tracker finished date when manually updating to last chapter

Closes #9834
Individual tracker implementations already handle setting it too on update.
This commit is contained in:
arkon 2023-08-11 09:30:35 -04:00
parent efa7a3a167
commit 8a6a104987
2 changed files with 6 additions and 6 deletions

View file

@ -5,7 +5,6 @@ import androidx.annotation.CallSuper
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.annotation.StringRes import androidx.annotation.StringRes
import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay import eu.kanade.domain.chapter.interactor.SyncChaptersWithTrackServiceTwoWay
import eu.kanade.domain.track.model.toDbTrack import eu.kanade.domain.track.model.toDbTrack
import eu.kanade.domain.track.model.toDomainTrack import eu.kanade.domain.track.model.toDomainTrack
@ -31,9 +30,9 @@ import tachiyomi.domain.track.model.Track as DomainTrack
abstract class TrackService(val id: Long) { abstract class TrackService(val id: Long) {
val preferences: BasePreferences by injectLazy()
val trackPreferences: TrackPreferences by injectLazy() val trackPreferences: TrackPreferences by injectLazy()
val networkService: NetworkHelper by injectLazy() val networkService: NetworkHelper by injectLazy()
private val insertTrack: InsertTrack by injectLazy()
open val client: OkHttpClient open val client: OkHttpClient
get() = networkService.client get() = networkService.client
@ -112,7 +111,7 @@ abstract class TrackService(val id: Long) {
var track = item.toDomainTrack(idRequired = false) ?: return@withIOContext var track = item.toDomainTrack(idRequired = false) ?: return@withIOContext
Injekt.get<InsertTrack>().await(track) insertTrack.await(track)
// Update chapter progress if newer chapters marked read locally // Update chapter progress if newer chapters marked read locally
if (hasReadChapters) { if (hasReadChapters) {
@ -120,7 +119,7 @@ abstract class TrackService(val id: Long) {
.sortedBy { it.chapterNumber } .sortedBy { it.chapterNumber }
.takeWhile { it.read } .takeWhile { it.read }
.lastOrNull() .lastOrNull()
?.chapterNumber?.toDouble() ?: -1.0 ?.chapterNumber ?: -1.0
if (latestLocalReadChapterNumber > track.lastChapterRead) { if (latestLocalReadChapterNumber > track.lastChapterRead) {
track = track.copy( track = track.copy(
@ -169,6 +168,7 @@ abstract class TrackService(val id: Long) {
track.last_chapter_read = chapterNumber.toFloat() track.last_chapter_read = chapterNumber.toFloat()
if (track.total_chapters != 0 && track.last_chapter_read.toInt() == track.total_chapters) { if (track.total_chapters != 0 && track.last_chapter_read.toInt() == track.total_chapters) {
track.status = getCompletionStatus() track.status = getCompletionStatus()
track.finished_reading_date = System.currentTimeMillis()
} }
withIOContext { updateRemote(track) } withIOContext { updateRemote(track) }
} }
@ -193,7 +193,7 @@ abstract class TrackService(val id: Long) {
try { try {
update(track) update(track)
track.toDomainTrack(idRequired = false)?.let { track.toDomainTrack(idRequired = false)?.let {
Injekt.get<InsertTrack>().await(it) insertTrack.await(it)
} }
} catch (e: Exception) { } catch (e: Exception) {
logcat(LogPriority.ERROR, e) { "Failed to update remote track data id=$id" } logcat(LogPriority.ERROR, e) { "Failed to update remote track data id=$id" }

View file

@ -58,7 +58,7 @@ class ChapterRepositoryImpl(
read = chapterUpdate.read, read = chapterUpdate.read,
bookmark = chapterUpdate.bookmark, bookmark = chapterUpdate.bookmark,
lastPageRead = chapterUpdate.lastPageRead, lastPageRead = chapterUpdate.lastPageRead,
chapterNumber = chapterUpdate.chapterNumber?.toDouble(), chapterNumber = chapterUpdate.chapterNumber,
sourceOrder = chapterUpdate.sourceOrder, sourceOrder = chapterUpdate.sourceOrder,
dateFetch = chapterUpdate.dateFetch, dateFetch = chapterUpdate.dateFetch,
dateUpload = chapterUpdate.dateUpload, dateUpload = chapterUpdate.dateUpload,