mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 08:09:21 +01:00
Set newly tracked manga as "Plan to read" if nothing has been read yet
and it'll be set automatically to reading status when read in the reader
This commit is contained in:
parent
c884963672
commit
4c06966870
@ -54,7 +54,7 @@ abstract class TrackService(val id: Int) {
|
|||||||
|
|
||||||
abstract suspend fun add(track: Track): Track
|
abstract suspend fun add(track: Track): Track
|
||||||
|
|
||||||
abstract suspend fun update(track: Track): Track
|
abstract suspend fun update(track: Track, setToReadStatus: Boolean = false): Track
|
||||||
|
|
||||||
abstract suspend fun bind(track: Track): Track
|
abstract suspend fun bind(track: Track): Track
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ abstract class TrackService(val id: Int) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun TrackService.updateNewTrackInfo(track: Track) {
|
suspend fun TrackService.updateNewTrackInfo(track: Track, planningStatus: Int) {
|
||||||
val allRead = db.getManga(track.manga_id).executeOnIO()?.status == SManga.COMPLETED &&
|
val allRead = db.getManga(track.manga_id).executeOnIO()?.status == SManga.COMPLETED &&
|
||||||
db.getChapters(track.manga_id).executeOnIO().all { it.read }
|
db.getChapters(track.manga_id).executeOnIO().all { it.read }
|
||||||
if (supportsReadingDates) {
|
if (supportsReadingDates) {
|
||||||
@ -92,6 +92,9 @@ suspend fun TrackService.updateNewTrackInfo(track: Track) {
|
|||||||
track.finished_reading_date = getCompletedDate(track, allRead)
|
track.finished_reading_date = getCompletedDate(track, allRead)
|
||||||
}
|
}
|
||||||
track.last_chapter_read = getLastChapterRead(track)
|
track.last_chapter_read = getLastChapterRead(track)
|
||||||
|
if (track.last_chapter_read == 0) {
|
||||||
|
track.status = planningStatus
|
||||||
|
}
|
||||||
if (allRead) {
|
if (allRead) {
|
||||||
track.status = completedStatus()
|
track.status = completedStatus()
|
||||||
}
|
}
|
||||||
@ -99,7 +102,7 @@ suspend fun TrackService.updateNewTrackInfo(track: Track) {
|
|||||||
|
|
||||||
suspend fun TrackService.getStartDate(track: Track): Long {
|
suspend fun TrackService.getStartDate(track: Track): Long {
|
||||||
if (db.getChapters(track.manga_id).executeOnIO().any { it.read }) {
|
if (db.getChapters(track.manga_id).executeOnIO().any { it.read }) {
|
||||||
val chapters = db.getHistoryByMangaId(track.manga_id).executeOnIO()
|
val chapters = db.getHistoryByMangaId(track.manga_id).executeOnIO().filter { it.last_read > 0 }
|
||||||
val date = chapters.minOfOrNull { it.last_read } ?: return 0L
|
val date = chapters.minOfOrNull { it.last_read } ?: return 0L
|
||||||
return if (date <= 0L) 0L else date
|
return if (date <= 0L) 0L else date
|
||||||
}
|
}
|
||||||
|
@ -130,11 +130,14 @@ class Anilist(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
override suspend fun add(track: Track): Track {
|
override suspend fun add(track: Track): Track {
|
||||||
track.score = DEFAULT_SCORE.toFloat()
|
track.score = DEFAULT_SCORE.toFloat()
|
||||||
track.status = DEFAULT_STATUS
|
track.status = DEFAULT_STATUS
|
||||||
updateNewTrackInfo(track)
|
updateNewTrackInfo(track, PLANNING)
|
||||||
return api.addLibManga(track)
|
return api.addLibManga(track)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(track: Track): Track {
|
override suspend fun update(track: Track, setToReadStatus: Boolean): Track {
|
||||||
|
if (setToReadStatus && track.status == PLANNING && track.last_chapter_read != 0) {
|
||||||
|
track.status = READING
|
||||||
|
}
|
||||||
if (track.status == READING && track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) {
|
if (track.status == READING && track.total_chapters != 0 && track.last_chapter_read == track.total_chapters) {
|
||||||
track.status = COMPLETED
|
track.status = COMPLETED
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,10 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
return track.score.toInt().toString()
|
return track.score.toInt().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(track: Track): Track {
|
override suspend fun update(track: Track, setToReadStatus: Boolean): Track {
|
||||||
|
if (setToReadStatus && track.status == PLANNING && track.last_chapter_read != 0) {
|
||||||
|
track.status = READING
|
||||||
|
}
|
||||||
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 = COMPLETED
|
track.status = COMPLETED
|
||||||
}
|
}
|
||||||
@ -42,7 +45,7 @@ class Bangumi(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
override suspend fun add(track: Track): Track {
|
override suspend fun add(track: Track): Track {
|
||||||
track.score = DEFAULT_SCORE.toFloat()
|
track.score = DEFAULT_SCORE.toFloat()
|
||||||
track.status = DEFAULT_STATUS
|
track.status = DEFAULT_STATUS
|
||||||
updateNewTrackInfo(track)
|
updateNewTrackInfo(track, PLANNING)
|
||||||
api.addLibManga(track)
|
api.addLibManga(track)
|
||||||
return update(track)
|
return update(track)
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,10 @@ class Kitsu(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
return df.format(track.score)
|
return df.format(track.score)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(track: Track): Track {
|
override suspend fun update(track: Track, setToReadStatus: Boolean): Track {
|
||||||
|
if (setToReadStatus && track.status == PLAN_TO_READ && track.last_chapter_read != 0) {
|
||||||
|
track.status = READING
|
||||||
|
}
|
||||||
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 = COMPLETED
|
track.status = COMPLETED
|
||||||
}
|
}
|
||||||
|
@ -70,11 +70,14 @@ class MyAnimeList(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
override suspend fun add(track: Track): Track {
|
override suspend fun add(track: Track): Track {
|
||||||
track.status = READING
|
track.status = READING
|
||||||
track.score = 0F
|
track.score = 0F
|
||||||
updateNewTrackInfo(track)
|
updateNewTrackInfo(track, PLAN_TO_READ)
|
||||||
return api.updateItem(track)
|
return api.updateItem(track)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(track: Track): Track {
|
override suspend fun update(track: Track, setToReadStatus: Boolean): Track {
|
||||||
|
if (setToReadStatus && track.status == PLAN_TO_READ && track.last_chapter_read != 0) {
|
||||||
|
track.status = READING
|
||||||
|
}
|
||||||
return api.updateItem(track)
|
return api.updateItem(track)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,10 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
return track.score.toInt().toString()
|
return track.score.toInt().toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(track: Track): Track {
|
override suspend fun update(track: Track, setToReadStatus: Boolean): Track {
|
||||||
|
if (setToReadStatus && track.status == PLANNING && track.last_chapter_read != 0) {
|
||||||
|
track.status = READING
|
||||||
|
}
|
||||||
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 = COMPLETED
|
track.status = COMPLETED
|
||||||
}
|
}
|
||||||
@ -77,7 +80,7 @@ class Shikimori(private val context: Context, id: Int) : TrackService(id) {
|
|||||||
override suspend fun add(track: Track): Track {
|
override suspend fun add(track: Track): Track {
|
||||||
track.score = DEFAULT_SCORE.toFloat()
|
track.score = DEFAULT_SCORE.toFloat()
|
||||||
track.status = DEFAULT_STATUS
|
track.status = DEFAULT_STATUS
|
||||||
updateNewTrackInfo(track)
|
updateNewTrackInfo(track, PLANNING)
|
||||||
return api.addLibManga(track, getUsername())
|
return api.addLibManga(track, getUsername())
|
||||||
}
|
}
|
||||||
override suspend fun bind(track: Track): Track {
|
override suspend fun bind(track: Track): Track {
|
||||||
|
@ -860,7 +860,7 @@ class ReaderPresenter(
|
|||||||
if (service != null && service.isLogged && chapterRead > track.last_chapter_read) {
|
if (service != null && service.isLogged && chapterRead > track.last_chapter_read) {
|
||||||
try {
|
try {
|
||||||
track.last_chapter_read = chapterRead
|
track.last_chapter_read = chapterRead
|
||||||
service.update(track)
|
service.update(track, true)
|
||||||
db.insertTrack(track).executeAsBlocking()
|
db.insertTrack(track).executeAsBlocking()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Timber.e(e)
|
Timber.e(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user