show a toast whenever progress is synced from Trackers
This commit is contained in:
parent
bcb05c4b3a
commit
cb6566e500
7 changed files with 55 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.domain.track.interactor
|
||||
|
||||
import android.app.Application
|
||||
import eu.kanade.domain.track.model.toDbTrack
|
||||
import eu.kanade.domain.track.model.toDomainTrack
|
||||
import eu.kanade.tachiyomi.data.database.models.Track
|
||||
|
|
@ -8,14 +9,18 @@ import eu.kanade.tachiyomi.data.track.Tracker
|
|||
import eu.kanade.tachiyomi.data.track.TrackerManager
|
||||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.util.lang.convertEpochMillisZone
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.common.i18n.stringResource
|
||||
import tachiyomi.core.common.util.lang.withIOContext
|
||||
import tachiyomi.core.common.util.lang.withNonCancellableContext
|
||||
import tachiyomi.core.common.util.lang.withUIContext
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import tachiyomi.domain.chapter.interactor.GetChaptersByMangaId
|
||||
import tachiyomi.domain.history.interactor.GetHistory
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.track.interactor.InsertTrack
|
||||
import tachiyomi.i18n.kmk.KMR
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.time.ZoneOffset
|
||||
|
|
@ -74,6 +79,14 @@ class AddTracks(
|
|||
}
|
||||
|
||||
syncChapterProgressWithTrack.await(mangaId, track, tracker)
|
||||
// KMK -->
|
||||
?.let {
|
||||
val context = Injekt.get<Application>()
|
||||
withUIContext {
|
||||
context.toast(context.stringResource(KMR.strings.sync_progress_from_trackers_up_to_chapter, it))
|
||||
}
|
||||
}
|
||||
// KMK <--
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,6 +107,14 @@ class AddTracks(
|
|||
track.toDomainTrack(idRequired = false)!!,
|
||||
service,
|
||||
)
|
||||
// KMK -->
|
||||
?.let {
|
||||
val context = Injekt.get<Application>()
|
||||
withUIContext {
|
||||
context.toast(context.stringResource(KMR.strings.sync_progress_from_trackers_up_to_chapter, it))
|
||||
}
|
||||
}
|
||||
// KMK <--
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(
|
||||
|
|
|
|||
|
|
@ -1,14 +1,21 @@
|
|||
package eu.kanade.domain.track.interactor
|
||||
|
||||
import android.app.Application
|
||||
import eu.kanade.domain.track.model.toDbTrack
|
||||
import eu.kanade.domain.track.model.toDomainTrack
|
||||
import eu.kanade.tachiyomi.data.track.Tracker
|
||||
import eu.kanade.tachiyomi.data.track.TrackerManager
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import kotlinx.coroutines.async
|
||||
import kotlinx.coroutines.awaitAll
|
||||
import kotlinx.coroutines.supervisorScope
|
||||
import tachiyomi.core.common.i18n.stringResource
|
||||
import tachiyomi.core.common.util.lang.withUIContext
|
||||
import tachiyomi.domain.track.interactor.GetTracks
|
||||
import tachiyomi.domain.track.interactor.InsertTrack
|
||||
import tachiyomi.i18n.kmk.KMR
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
class RefreshTracks(
|
||||
private val getTracks: GetTracks,
|
||||
|
|
@ -33,6 +40,14 @@ class RefreshTracks(
|
|||
val updatedTrack = service!!.refresh(track.toDbTrack()).toDomainTrack()!!
|
||||
insertTrack.await(updatedTrack)
|
||||
syncChapterProgressWithTrack.await(mangaId, updatedTrack, service)
|
||||
// KMK -->
|
||||
?.let {
|
||||
val context = Injekt.get<Application>()
|
||||
withUIContext {
|
||||
context.toast(context.stringResource(KMR.strings.sync_progress_from_trackers_up_to_chapter, it))
|
||||
}
|
||||
}
|
||||
// KMK <--
|
||||
null
|
||||
} catch (e: Throwable) {
|
||||
service to e
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ class SyncChapterProgressWithTrack(
|
|||
mangaId: Long,
|
||||
remoteTrack: Track,
|
||||
tracker: Tracker,
|
||||
) {
|
||||
): Int? {
|
||||
// KKM -->
|
||||
// if (tracker !is EnhancedTracker) {
|
||||
// return
|
||||
|
|
@ -70,17 +70,26 @@ class SyncChapterProgressWithTrack(
|
|||
|
||||
try {
|
||||
// Update Tracker to localLastRead if needed
|
||||
if (updatedTrack.lastChapterRead > remoteTrack.lastChapterRead) {
|
||||
if (lastRead > remoteTrack.lastChapterRead) {
|
||||
tracker.update(updatedTrack.toDbTrack())
|
||||
// update Track in database
|
||||
insertTrack.await(updatedTrack)
|
||||
}
|
||||
// Update local chapters following Tracker
|
||||
if (trackPreferences.autoSyncReadChapters().get() && !tracker.hasNotStartedReading(remoteTrack.status)) {
|
||||
// KMK -->
|
||||
// Always update local chapters following Tracker even past chapters
|
||||
if (chapterUpdates.isNotEmpty() &&
|
||||
trackPreferences.autoSyncProgressFromTrackers().get() &&
|
||||
!tracker.hasNotStartedReading(remoteTrack.status)
|
||||
) {
|
||||
updateChapter.awaitAll(chapterUpdates)
|
||||
return lastRead.toInt()
|
||||
}
|
||||
// KMK <--
|
||||
} catch (e: Throwable) {
|
||||
logcat(LogPriority.WARN, e)
|
||||
}
|
||||
// KMK -->
|
||||
return null
|
||||
// KMK <--
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,6 @@ class TrackPreferences(
|
|||
)
|
||||
|
||||
// KMK -->
|
||||
fun autoSyncReadChapters() = preferenceStore.getBoolean("pref_auto_sync_read_chapters_key", true)
|
||||
fun autoSyncProgressFromTrackers() = preferenceStore.getBoolean("pref_auto_sync_progress_from_trackers_key", true)
|
||||
// KMK <--
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ object SettingsTrackingScreen : SearchableSettings {
|
|||
),
|
||||
// KMK -->
|
||||
Preference.PreferenceItem.SwitchPreference(
|
||||
pref = trackPreferences.autoSyncReadChapters(),
|
||||
title = stringResource(KMR.strings.pref_auto_sync_read_chapters),
|
||||
pref = trackPreferences.autoSyncProgressFromTrackers(),
|
||||
title = stringResource(KMR.strings.pref_auto_sync_progress_from_trackers),
|
||||
),
|
||||
// KMK <--
|
||||
Preference.PreferenceGroup(
|
||||
|
|
|
|||
|
|
@ -559,7 +559,7 @@ class MangaScreenModel(
|
|||
}
|
||||
|
||||
private suspend fun syncTrackers() {
|
||||
if (!trackPreferences.autoSyncReadChapters().get()) return
|
||||
if (!trackPreferences.autoSyncProgressFromTrackers().get()) return
|
||||
|
||||
val refreshTracks = Injekt.get<RefreshTracks>()
|
||||
refreshTracks.await(mangaId)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,8 @@
|
|||
<string name="download_cache_renew_interval_info">If set to "manual", either refresh each manga or using the "Invalidate downloads index" action in "Advanced"</string>
|
||||
|
||||
<!-- Tracking section -->
|
||||
<string name="pref_auto_sync_read_chapters">Auto sync read chapters from Trackers</string>
|
||||
<string name="pref_auto_sync_progress_from_trackers">Auto sync progress from Trackers</string>
|
||||
<string name="sync_progress_from_trackers_up_to_chapter">Sync progress from Trackers up to chapter %d</string>
|
||||
|
||||
<!-- Sync section -->
|
||||
<string name="pref_show_restoring_progress_banner">Show restoring progress banner</string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue