mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-20 02:49:20 +01:00
parent
a0bc45af46
commit
922f115c78
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.data.database.models
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
import eu.kanade.tachiyomi.source.model.SManga
|
||||||
@ -146,7 +147,7 @@ interface Manga : SManga {
|
|||||||
*/
|
*/
|
||||||
fun defaultReaderType(): Int {
|
fun defaultReaderType(): Int {
|
||||||
val sourceName = Injekt.get<SourceManager>().getOrStub(source).name
|
val sourceName = Injekt.get<SourceManager>().getOrStub(source).name
|
||||||
val currentTags = genre?.split(",")?.map { it.trim().toLowerCase(Locale.US) } ?: emptyList()
|
val currentTags = genre?.split(",")?.map { it.trim().lowercase(Locale.US) } ?: emptyList()
|
||||||
return if (currentTags.any
|
return if (currentTags.any
|
||||||
{ tag ->
|
{ tag ->
|
||||||
isManhwaTag(tag) || tag.contains("webtoon")
|
isManhwaTag(tag) || tag.contains("webtoon")
|
||||||
@ -219,6 +220,20 @@ interface Manga : SManga {
|
|||||||
sourceName.contains("ComicExtra", true)
|
sourceName.contains("ComicExtra", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isOneShotOrCompleted(db: DatabaseHelper): Boolean {
|
||||||
|
val tags by lazy { genre?.split(",")?.map { it.trim().lowercase(Locale.US) } }
|
||||||
|
val chapters by lazy { db.getChapters(this).executeAsBlocking() }
|
||||||
|
val firstChapterName by lazy { chapters.firstOrNull()?.name?.lowercase() ?: "" }
|
||||||
|
return status == SManga.COMPLETED || tags?.contains("oneshot") == true ||
|
||||||
|
(
|
||||||
|
chapters.size == 1 &&
|
||||||
|
(
|
||||||
|
Regex("one.?shot").containsMatchIn(firstChapterName) ||
|
||||||
|
firstChapterName.contains("oneshot")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
fun key(): String {
|
fun key(): String {
|
||||||
return "manga-id-$id"
|
return "manga-id-$id"
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@ import eu.kanade.tachiyomi.data.database.models.Track
|
|||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
import eu.kanade.tachiyomi.data.track.model.TrackSearch
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||||
import eu.kanade.tachiyomi.source.model.SManga
|
|
||||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
@ -85,13 +84,16 @@ abstract class TrackService(val id: Int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun TrackService.updateNewTrackInfo(track: Track, planningStatus: Int) {
|
suspend fun TrackService.updateNewTrackInfo(track: Track, planningStatus: Int) {
|
||||||
val allRead = db.getManga(track.manga_id).executeOnIO()?.status == SManga.COMPLETED &&
|
val manga = db.getManga(track.manga_id).executeOnIO()
|
||||||
|
val allRead = manga?.isOneShotOrCompleted(db) == true &&
|
||||||
db.getChapters(track.manga_id).executeOnIO().all { it.read }
|
db.getChapters(track.manga_id).executeOnIO().all { it.read }
|
||||||
if (supportsReadingDates) {
|
if (supportsReadingDates) {
|
||||||
track.started_reading_date = getStartDate(track)
|
track.started_reading_date = getStartDate(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).takeUnless {
|
||||||
|
it == 0 && allRead
|
||||||
|
} ?: 1
|
||||||
if (track.last_chapter_read == 0) {
|
if (track.last_chapter_read == 0) {
|
||||||
track.status = planningStatus
|
track.status = planningStatus
|
||||||
}
|
}
|
||||||
@ -120,5 +122,6 @@ suspend fun TrackService.getCompletedDate(track: Track, allRead: Boolean): Long
|
|||||||
|
|
||||||
suspend fun TrackService.getLastChapterRead(track: Track): Int {
|
suspend fun TrackService.getLastChapterRead(track: Track): Int {
|
||||||
val chapters = db.getChapters(track.manga_id).executeOnIO()
|
val chapters = db.getChapters(track.manga_id).executeOnIO()
|
||||||
return chapters.filter { it.read }.minByOrNull { it.source_order }?.chapter_number?.toInt() ?: 0
|
val lastChapterRead = chapters.filter { it.read }.minByOrNull { it.source_order }
|
||||||
|
return lastChapterRead?.takeIf { it.isRecognizedNumber }?.chapter_number?.toInt() ?: 0
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user