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 8249713ae3..ca12e19a20 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 @@ -41,9 +41,6 @@ import eu.kanade.tachiyomi.data.sync.SyncDataJob import eu.kanade.tachiyomi.data.sync.SyncManager import eu.kanade.tachiyomi.data.sync.service.GoogleDriveService import eu.kanade.tachiyomi.data.sync.service.GoogleDriveSyncService -import eu.kanade.tachiyomi.util.storage.DiskUtil -import eu.kanade.tachiyomi.util.system.DeviceUtil -import eu.kanade.tachiyomi.util.system.copyToClipboard import eu.kanade.tachiyomi.util.system.toast import kotlinx.collections.immutable.persistentListOf import kotlinx.collections.immutable.persistentMapOf @@ -284,7 +281,6 @@ object SettingsDataScreen : SearchableSettings { ) + getSyncServicePreferences(syncPreferences, syncService) } - @Composable private fun getSyncServicePreferences(syncPreferences: SyncPreferences, syncService: Int): List { val syncServiceType = SyncManager.SyncService.fromInt(syncService) @@ -505,5 +501,4 @@ object SettingsDataScreen : SearchableSettings { }, ) } - } 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 8ad1b14268..46ce465924 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 @@ -130,11 +130,16 @@ class SyncManager( val backupUri = writeSyncDataToCache(context, newSyncData) logcat(LogPriority.DEBUG) { "Got Backup Uri: $backupUri" } if (backupUri != null) { - BackupRestoreJob.start(context, backupUri, sync = true, options = RestoreOptions( - appSettings = true, - sourceSettings = true, - library = true, - )) + BackupRestoreJob.start( + context, + backupUri, + sync = true, + options = RestoreOptions( + appSettings = true, + sourceSettings = true, + library = true, + ), + ) } else { logcat(LogPriority.ERROR) { "Failed to write sync data to file" } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncService.kt index 0b6ec74048..b4e2e062ec 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncService.kt @@ -90,7 +90,7 @@ abstract class SyncService( */ private fun mergeMangaLists( localMangaList: List?, - remoteMangaList: List? + remoteMangaList: List?, ): List { // Convert null lists to empty to simplify logic val localMangaListSafe = localMangaList.orEmpty() @@ -114,35 +114,37 @@ abstract class SyncService( val remoteTime = Instant.ofEpochMilli(remote.lastModifiedAt) val mergedChapters = mergeChapters(local.chapters, remote.chapters) - if (localTime >= remoteTime) local.copy(chapters = mergedChapters) - else remote.copy(chapters = mergedChapters) + if (localTime >= remoteTime) { + local.copy(chapters = mergedChapters) + } else { + remote.copy(chapters = mergedChapters) + } } else -> null // This case occurs if both are null, which shouldn't happen but is handled for completeness. } } } - /** - * Merges two lists of BackupChapter objects, selecting the most recent chapter based on the lastModifiedAt value. - * If lastModifiedAt is null for a chapter, it treats that chapter as the oldest possible for comparison purposes. - * This function is designed to reconcile local and remote chapter lists, ensuring the most up-to-date chapter is retained. - * - * @param localChapters The list of local BackupChapter objects. - * @param remoteChapters The list of remote BackupChapter objects. - * @return A list of BackupChapter objects, each representing the most recent version of the chapter from either local or remote sources. - * - * - This function is used in scenarios where local and remote chapter lists need to be synchronized. - * - It iterates over the union of the URLs from both local and remote chapters. - * - For each URL, it compares the corresponding local and remote chapters based on the lastModifiedAt value. - * - If only one source (local or remote) has the chapter for a URL, that chapter is used. - * - If both sources have the chapter, the one with the more recent lastModifiedAt value is chosen. - * - If lastModifiedAt is null or missing, the chapter is considered the oldest for safety, ensuring that any chapter with a valid timestamp is preferred. - * - The resulting list contains the most recent chapters from the combined set of local and remote chapters. - */ + * Merges two lists of BackupChapter objects, selecting the most recent chapter based on the lastModifiedAt value. + * If lastModifiedAt is null for a chapter, it treats that chapter as the oldest possible for comparison purposes. + * This function is designed to reconcile local and remote chapter lists, ensuring the most up-to-date chapter is retained. + * + * @param localChapters The list of local BackupChapter objects. + * @param remoteChapters The list of remote BackupChapter objects. + * @return A list of BackupChapter objects, each representing the most recent version of the chapter from either local or remote sources. + * + * - This function is used in scenarios where local and remote chapter lists need to be synchronized. + * - It iterates over the union of the URLs from both local and remote chapters. + * - For each URL, it compares the corresponding local and remote chapters based on the lastModifiedAt value. + * - If only one source (local or remote) has the chapter for a URL, that chapter is used. + * - If both sources have the chapter, the one with the more recent lastModifiedAt value is chosen. + * - If lastModifiedAt is null or missing, the chapter is considered the oldest for safety, ensuring that any chapter with a valid timestamp is preferred. + * - The resulting list contains the most recent chapters from the combined set of local and remote chapters. + */ private fun mergeChapters( localChapters: List, - remoteChapters: List + remoteChapters: List, ): List { // Associate chapters by URL for both local and remote val localChapterMap = localChapters.associateBy { it.url }