mirror of
https://github.com/mihonapp/mihon.git
synced 2025-10-20 10:09:43 +02:00
Refactor: Replace Certain SyncPreferences with appStateKey
- Revised several fields to utilize `appStateKey` for enhanced state management. - Modified notification behavior: - Removed frequent 'sync completed' notifications to reduce redundancy. - Notifications now trigger only on sync errors, streamlining user alerts. - Users should refer to the 'last sync timestamp' to verify successful synchronizations. - The timestamp updates only when syncs complete successfully, providing a reliable success indicator. Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
@@ -492,7 +492,7 @@ private fun getSyncNowPref(): Preference.PreferenceGroup {
|
||||
private fun getAutomaticSyncGroup(syncPreferences: SyncPreferences): Preference.PreferenceGroup {
|
||||
val context = LocalContext.current
|
||||
val syncIntervalPref = syncPreferences.syncInterval()
|
||||
val lastSync by syncPreferences.syncLastSync().collectAsState()
|
||||
val lastSync by syncPreferences.lastSyncTimestamp().collectAsState()
|
||||
|
||||
return Preference.PreferenceGroup(
|
||||
title = stringResource(R.string.pref_sync_service_category),
|
||||
@@ -516,7 +516,7 @@ private fun getAutomaticSyncGroup(syncPreferences: SyncPreferences): Preference.
|
||||
true
|
||||
},
|
||||
),
|
||||
Preference.PreferenceItem.InfoPreference(stringResource(R.string.last_synchronization, relativeTimeSpanString(lastSync.toEpochMilli()))),
|
||||
Preference.PreferenceItem.InfoPreference(stringResource(R.string.last_synchronization, relativeTimeSpanString(lastSync))),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ import tachiyomi.domain.history.model.HistoryUpdate
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
import tachiyomi.domain.manga.interactor.FetchInterval
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.sync.SyncPreferences
|
||||
import tachiyomi.domain.track.model.Track
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@@ -59,6 +60,7 @@ class BackupRestorer(
|
||||
|
||||
private val preferenceStore: PreferenceStore = Injekt.get()
|
||||
private val libraryPreferences: LibraryPreferences = Injekt.get()
|
||||
private val syncPreferences: SyncPreferences = Injekt.get()
|
||||
|
||||
private var now = ZonedDateTime.now()
|
||||
private var currentFetchWindow = fetchInterval.getWindow(now)
|
||||
@@ -88,13 +90,7 @@ class BackupRestorer(
|
||||
val logFile = writeErrorLog()
|
||||
|
||||
if (sync) {
|
||||
notifier.showRestoreComplete(
|
||||
time,
|
||||
errors.size,
|
||||
logFile.parent,
|
||||
logFile.name,
|
||||
contentTitle = context.getString(R.string.library_sync_complete),
|
||||
)
|
||||
syncPreferences.lastSyncTimestamp().set(Date().time)
|
||||
} else {
|
||||
notifier.showRestoreComplete(time, errors.size, logFile.parent, logFile.name)
|
||||
}
|
||||
|
@@ -34,6 +34,7 @@ import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.io.IOException
|
||||
import java.time.Instant
|
||||
import java.util.Date
|
||||
|
||||
/**
|
||||
* A manager to handle synchronization tasks in the app, such as updating
|
||||
@@ -139,7 +140,8 @@ class SyncManager(
|
||||
|
||||
// It's local sync no need to restore data. (just update remote data)
|
||||
if (filteredFavorites.isEmpty()) {
|
||||
backupNotify.showRestoreComplete(0, 0, "", "", contentTitle = context.getString(R.string.sync_complete))
|
||||
// update the sync timestamp
|
||||
syncPreferences.lastSyncTimestamp().set(Date().time)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -147,7 +149,6 @@ class SyncManager(
|
||||
logcat(LogPriority.DEBUG) { "Got Backup Uri: $backupUri" }
|
||||
if (backupUri != null) {
|
||||
BackupRestoreJob.start(context, backupUri, sync = true)
|
||||
syncPreferences.syncLastSync().set(Instant.now())
|
||||
} else {
|
||||
logcat(LogPriority.ERROR) { "Failed to write sync data to file" }
|
||||
}
|
||||
|
Reference in New Issue
Block a user