chore: lint

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2023-12-29 05:58:47 +11:00
parent 57f9aed411
commit 8cd7774054
No known key found for this signature in database
GPG Key ID: 14D73B142042BBA9
3 changed files with 33 additions and 31 deletions

View File

@ -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<Preference> {
val syncServiceType = SyncManager.SyncService.fromInt(syncService)
@ -505,5 +501,4 @@ object SettingsDataScreen : SearchableSettings {
},
)
}
}

View File

@ -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" }
}

View File

@ -90,7 +90,7 @@ abstract class SyncService(
*/
private fun mergeMangaLists(
localMangaList: List<BackupManga>?,
remoteMangaList: List<BackupManga>?
remoteMangaList: List<BackupManga>?,
): List<BackupManga> {
// 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<BackupChapter>,
remoteChapters: List<BackupChapter>
remoteChapters: List<BackupChapter>,
): List<BackupChapter> {
// Associate chapters by URL for both local and remote
val localChapterMap = localChapters.associateBy { it.url }