mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 15:02:49 +01: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:
parent
dac701bb35
commit
a08a815022
@ -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" }
|
||||
}
|
||||
|
@ -1,25 +1,25 @@
|
||||
package tachiyomi.domain.sync
|
||||
|
||||
import tachiyomi.core.preference.PreferenceStore
|
||||
import java.time.Instant
|
||||
import tachiyomi.core.preference.Preference
|
||||
|
||||
class SyncPreferences(
|
||||
private val preferenceStore: PreferenceStore,
|
||||
) {
|
||||
fun syncHost() = preferenceStore.getString("sync_host", "https://sync.tachiyomi.org")
|
||||
fun syncAPIKey() = preferenceStore.getString("sync_api_key", "")
|
||||
fun syncLastSync() = preferenceStore.getInstant("sync_last_sync", Instant.EPOCH)
|
||||
fun lastSyncTimestamp() = preferenceStore.getLong(Preference.appStateKey("last_sync_timestamp"), 0L)
|
||||
|
||||
fun syncInterval() = preferenceStore.getInt("sync_interval", 0)
|
||||
|
||||
fun deviceName() = preferenceStore.getString(
|
||||
"device_name",
|
||||
Preference.appStateKey("device_name"),
|
||||
android.os.Build.MANUFACTURER + android.os.Build.PRODUCT,
|
||||
)
|
||||
|
||||
fun syncService() = preferenceStore.getInt("sync_service", 0)
|
||||
|
||||
private fun googleDriveAccessToken() = preferenceStore.getString("google_drive_access_token", "")
|
||||
private fun googleDriveAccessToken() = preferenceStore.getString(Preference.appStateKey("google_drive_access_token"), "")
|
||||
|
||||
fun setGoogleDriveAccessToken(accessToken: String) {
|
||||
googleDriveAccessToken().set(accessToken)
|
||||
@ -27,7 +27,7 @@ class SyncPreferences(
|
||||
|
||||
fun getGoogleDriveAccessToken() = googleDriveAccessToken().get()
|
||||
|
||||
private fun googleDriveRefreshToken() = preferenceStore.getString("google_drive_refresh_token", "")
|
||||
private fun googleDriveRefreshToken() = preferenceStore.getString(Preference.appStateKey("google_drive_refresh_token"), "")
|
||||
|
||||
fun setGoogleDriveRefreshToken(refreshToken: String) {
|
||||
googleDriveRefreshToken().set(refreshToken)
|
||||
|
Loading…
Reference in New Issue
Block a user