mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 14:07:28 +01:00
Add Komga as an unattended track service (#5049)
* fix: prevent crash if TrackService.getScoreList() is empty * disabled track score button if service doesn't support scoring * first implementation of the Komga tracking this doesn't work for read lists * auto track when adding to library * handle refresh * 2-way sync of chapters for unattended tracking services * Update app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSheet.kt Co-authored-by: Andreas <andreas.everos@gmail.com> * group strings together * support for read lists * sync read chapters on bind * only mark local chapters as read during 2-way sync (incoming) * local progress from read chapters will be sent to remote tracker on bind/refresh this enables syncing after reading offline * remove unused variable * refactor the 2-way sync in a util function * handle auto add to track for unattended services from the browse source screen when long clicking this will also sync chapters, as it is possible to have read or marked as read chapters from there * 2-way sync when library update for TRACKING * refactor * better handling of what has been read server side * refactor: extract function * fix: localLastRead could be -1 when all chapters are read * refactor to rethrow exception so it can be shown in toast * extract strings * replace komga logo Co-authored-by: Andreas <andreas.everos@gmail.com>
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package eu.kanade.tachiyomi.util.chapter
|
||||
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.database.models.Chapter
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.util.lang.launchIO
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
* Helper method for syncing a remote track with the local chapters, and back
|
||||
*
|
||||
* @param db the database.
|
||||
* @param chapters a list of chapters from the source.
|
||||
* @param remoteTrack the remote Track object.
|
||||
* @param service the tracker service.
|
||||
*/
|
||||
fun syncChaptersWithTrackServiceTwoWay(db: DatabaseHelper, chapters: List<Chapter>, remoteTrack: Track, service: TrackService) {
|
||||
val sortedChapters = chapters.sortedBy { it.chapter_number }
|
||||
sortedChapters
|
||||
.filterIndexed { index, chapter -> index < remoteTrack.last_chapter_read && !chapter.read }
|
||||
.forEach { it.read = true }
|
||||
db.updateChaptersProgress(sortedChapters).executeAsBlocking()
|
||||
|
||||
val localLastRead = when {
|
||||
sortedChapters.all { it.read } -> sortedChapters.size
|
||||
sortedChapters.any { !it.read } -> sortedChapters.indexOfFirst { !it.read }
|
||||
else -> 0
|
||||
}
|
||||
|
||||
// update remote
|
||||
remoteTrack.last_chapter_read = localLastRead
|
||||
|
||||
launchIO {
|
||||
try {
|
||||
service.update(remoteTrack)
|
||||
db.insertTrack(remoteTrack).executeAsBlocking()
|
||||
} catch (e: Throwable) {
|
||||
Timber.w(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user