diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt index 987c7f509..0a36e5d14 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsDataScreen.kt @@ -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))), ), ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestorer.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestorer.kt index 80f3e5382..3d223b6ce 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestorer.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupRestorer.kt @@ -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) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt index 8a31b5315..d86c22c85 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncManager.kt @@ -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" } } diff --git a/domain/src/main/java/tachiyomi/domain/sync/SyncPreferences.kt b/domain/src/main/java/tachiyomi/domain/sync/SyncPreferences.kt index b6a81eba4..5717b6ba1 100644 --- a/domain/src/main/java/tachiyomi/domain/sync/SyncPreferences.kt +++ b/domain/src/main/java/tachiyomi/domain/sync/SyncPreferences.kt @@ -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)