Rename MangaDex's FollowStatus's property to better reflect its type (#1082)

This commit is contained in:
Cuong M. Tran
2024-03-02 23:56:11 +07:00
committed by GitHub
parent 94e5c33785
commit dd412e33ad
7 changed files with 27 additions and 27 deletions
@@ -34,7 +34,7 @@ class TrackChapter(
service == null ||
!service.isLoggedIn ||
chapterNumber <= track.lastChapterRead /* SY --> */ ||
(service is MdList && track.status == FollowStatus.UNFOLLOWED.int.toLong())/* SY <-- */
(service is MdList && track.status == FollowStatus.UNFOLLOWED.long)/* SY <-- */
) {
return@mapNotNull null
}
@@ -634,9 +634,9 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
var tracker = dbTracks.firstOrNull { it.trackerId == TrackerManager.MDLIST }
?: mdList.createInitialTracker(manga).toDomainTrack(idRequired = false)
if (tracker?.status == FollowStatus.UNFOLLOWED.int.toLong()) {
if (tracker?.status == FollowStatus.UNFOLLOWED.long) {
tracker = tracker.copy(
status = FollowStatus.READING.int.toLong(),
status = FollowStatus.READING.long,
)
val updatedTrack = mdList.update(tracker.toDbTrack())
insertTrack.await(updatedTrack.toDomainTrack(false)!!)
@@ -26,7 +26,7 @@ enum class TrackStatus(val int: Int, val res: StringResource) {
fun parseTrackerStatus(trackerManager: TrackerManager, tracker: Long, status: Long): TrackStatus? {
return when (tracker) {
trackerManager.mdList.id -> {
when (FollowStatus.fromInt(status)) {
when (FollowStatus.fromLong(status)) {
FollowStatus.UNFOLLOWED -> null
FollowStatus.READING -> READING
FollowStatus.COMPLETED -> COMPLETED
@@ -41,7 +41,7 @@ class MdList(id: Long) : BaseTracker(id, "MDList") {
}
override fun getStatusList(): List<Long> {
return FollowStatus.entries.map { it.int }
return FollowStatus.entries.map { it.long }
}
override fun getStatus(status: Long): StringResource? = when (status) {
@@ -64,13 +64,13 @@ class MdList(id: Long) : BaseTracker(id, "MDList") {
val mdex = mdex ?: throw MangaDexNotFoundException()
val remoteTrack = mdex.fetchTrackingInfo(track.tracking_url)
val followStatus = FollowStatus.fromInt(track.status)
val followStatus = FollowStatus.fromLong(track.status)
// this updates the follow status in the metadata
// allow follow status to update
if (remoteTrack.status != followStatus.int) {
if (remoteTrack.status != followStatus.long) {
if (mdex.updateFollowStatus(MdUtil.getMangaId(track.tracking_url), followStatus)) {
remoteTrack.status = followStatus.int
remoteTrack.status = followStatus.long
} else {
track.status = remoteTrack.status
}
@@ -103,19 +103,19 @@ class MdList(id: Long) : BaseTracker(id, "MDList") {
}
}
override fun getCompletionStatus(): Long = FollowStatus.COMPLETED.int
override fun getCompletionStatus(): Long = FollowStatus.COMPLETED.long
override fun getReadingStatus(): Long = FollowStatus.READING.int
override fun getReadingStatus(): Long = FollowStatus.READING.long
override fun getRereadingStatus(): Long = FollowStatus.RE_READING.int
override fun getRereadingStatus(): Long = FollowStatus.RE_READING.long
override suspend fun bind(track: Track, hasReadChapters: Boolean): Track = update(
refresh(track).also {
if (it.status == FollowStatus.UNFOLLOWED.int) {
if (it.status == FollowStatus.UNFOLLOWED.long) {
it.status = if (hasReadChapters) {
FollowStatus.READING.int
FollowStatus.READING.long
} else {
FollowStatus.PLAN_TO_READ.int
FollowStatus.PLAN_TO_READ.long
}
}
},
@@ -136,7 +136,7 @@ class MdList(id: Long) : BaseTracker(id, "MDList") {
fun createInitialTracker(dbManga: Manga, mdManga: Manga = dbManga): Track {
return Track.create(id).apply {
manga_id = dbManga.id
status = FollowStatus.UNFOLLOWED.int
status = FollowStatus.UNFOLLOWED.long
tracking_url = MdUtil.baseUrl + mdManga.url
title = mdManga.title
}
@@ -1679,7 +1679,7 @@ class MangaScreenModel(
val trackingCount: Int
get() = trackItems.count {
it.track != null && ((it.tracker is MdList && it.track.status != FollowStatus.UNFOLLOWED.int.toLong()) || it.tracker !is MdList)
it.track != null && ((it.tracker is MdList && it.track.status != FollowStatus.UNFOLLOWED.long) || it.tracker !is MdList)
}
/**