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 f26c318bf..307586055 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 @@ -80,23 +80,24 @@ object SettingsDataScreen : SearchableSettings { return listOf( getBackupAndRestoreGroup(backupPreferences = backupPreferences), - getDataGroup()) + listOf( - Preference.PreferenceGroup( - title = stringResource(R.string.label_sync), - preferenceItems = listOf( - Preference.PreferenceItem.ListPreference( - pref = syncPreferences.syncService(), - title = stringResource(R.string.pref_sync_service), - entries = mapOf( - SyncManager.SyncService.NONE.value to stringResource(R.string.off), - SyncManager.SyncService.SYNCYOMI.value to stringResource(R.string.syncyomi), - SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(R.string.google_drive), - ), - onValueChanged = { true }, + getDataGroup(), + ) + listOf( + Preference.PreferenceGroup( + title = stringResource(R.string.label_sync), + preferenceItems = listOf( + Preference.PreferenceItem.ListPreference( + pref = syncPreferences.syncService(), + title = stringResource(R.string.pref_sync_service), + entries = mapOf( + SyncManager.SyncService.NONE.value to stringResource(R.string.off), + SyncManager.SyncService.SYNCYOMI.value to stringResource(R.string.syncyomi), + SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(R.string.google_drive), ), + onValueChanged = { true }, ), ), - ) + getSyncServicePreferences(syncPreferences, syncService) + ), + ) + getSyncServicePreferences(syncPreferences, syncService) } @Composable @@ -388,9 +389,15 @@ private fun getGoogleDrivePurge(): Preference.PreferenceItem.TextPreference { scope.launch { val result = googleDriveSync.deleteSyncDataFromGoogleDrive() when (result) { - GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast(R.string.google_drive_not_signed_in) - GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast(R.string.google_drive_sync_data_not_found) - GoogleDriveSyncService.DeleteSyncDataStatus.SUCCESS -> context.toast(R.string.google_drive_sync_data_purged) + GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast( + R.string.google_drive_not_signed_in, + ) + GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast( + R.string.google_drive_sync_data_not_found, + ) + GoogleDriveSyncService.DeleteSyncDataStatus.SUCCESS -> context.toast( + R.string.google_drive_sync_data_purged, + ) } } }, @@ -486,7 +493,11 @@ private fun getAutomaticSyncGroup(syncPreferences: SyncPreferences): Preference. val context = LocalContext.current val syncIntervalPref = syncPreferences.syncInterval() val lastSync by syncPreferences.syncLastSync().collectAsState() - val formattedLastSync = DateUtils.getRelativeTimeSpanString(lastSync.toEpochMilli(), System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS) + val formattedLastSync = DateUtils.getRelativeTimeSpanString( + lastSync.toEpochMilli(), + System.currentTimeMillis(), + DateUtils.MINUTE_IN_MILLIS, + ) return Preference.PreferenceGroup( title = stringResource(R.string.pref_sync_service_category), diff --git a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt index 595f1d3b1..0cee2c70c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/AppModule.kt @@ -19,8 +19,8 @@ import eu.kanade.tachiyomi.data.download.DownloadCache import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.saver.ImageSaver -import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.data.sync.service.GoogleDriveService +import eu.kanade.tachiyomi.data.track.TrackerManager import eu.kanade.tachiyomi.extension.ExtensionManager import eu.kanade.tachiyomi.network.JavaScriptEngine import eu.kanade.tachiyomi.network.NetworkHelper diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt index 3b7309e67..fb65ba040 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreator.kt @@ -138,7 +138,7 @@ class BackupCreator( } } - fun prepExtensionInfoForSync(mangas: List): List { + fun prepExtensionInfoForSync(mangas: List): List { return mangas .asSequence() .map(Manga::source) @@ -177,7 +177,7 @@ class BackupCreator( * @param options options for the backup * @return [BackupManga] containing manga in a serializable form */ - suspend fun backupManga(manga: Manga, options: Int): BackupManga { + suspend fun backupManga(manga: Manga, options: Int): BackupManga { // Entry for this manga val mangaObject = BackupManga.copyFrom(manga) 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 677f60c3d..80f3e5382 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 @@ -257,7 +257,7 @@ class BackupRestorer( return updatedManga } - suspend fun updateManga(manga: Manga): Long { + suspend fun updateManga(manga: Manga): Long { handler.await(true) { mangasQueries.update( source = manga.source, @@ -326,7 +326,11 @@ class BackupRestorer( // Update lastPageRead if the chapter is marked as read if (updatedChapter.read) { updatedChapter = updatedChapter.copy( - lastPageRead = if (updatedChapter.lastPageRead > 0) updatedChapter.lastPageRead else dbChapter.lastPageRead, + lastPageRead = if (updatedChapter.lastPageRead > 0) { + updatedChapter.lastPageRead + } else { + dbChapter.lastPageRead + }, ) } } @@ -339,7 +343,6 @@ class BackupRestorer( insertChapters(newChapters) } - /** * Inserts list of chapters */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt index a8f50fd0c..32dc25688 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/NotificationReceiver.kt @@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.backup.BackupRestoreJob import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.library.LibraryUpdateJob +import eu.kanade.tachiyomi.data.sync.SyncDataJob import eu.kanade.tachiyomi.data.updater.AppUpdateDownloadJob import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.reader.ReaderActivity @@ -37,7 +38,6 @@ import uy.kohesive.injekt.api.get import uy.kohesive.injekt.injectLazy import java.io.File import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID -import eu.kanade.tachiyomi.data.sync.SyncDataJob /** * Global [BroadcastReceiver] that runs on UI thread @@ -704,7 +704,12 @@ class NotificationReceiver : BroadcastReceiver() { action = ACTION_CANCEL_SYNC putExtra(EXTRA_NOTIFICATION_ID, notificationId) } - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) + return PendingIntent.getBroadcast( + context, + 0, + intent, + PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE, + ) } } } 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 95b3f5296..8a31b5315 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 @@ -77,7 +77,7 @@ class SyncManager( suspend fun syncData() { val databaseManga = getAllMangaFromDB() val backup = Backup( - backupCreator.backupMangas(databaseManga, BackupCreateFlags.AutomaticDefaults ), + backupCreator.backupMangas(databaseManga, BackupCreateFlags.AutomaticDefaults), backupCreator.backupCategories(BackupCreateFlags.AutomaticDefaults), emptyList(), backupCreator.prepExtensionInfoForSync(databaseManga), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncNotifier.kt index b0f079b8d..39596d7b4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/SyncNotifier.kt @@ -16,7 +16,9 @@ class SyncNotifier(private val context: Context) { private val preferences: SecurityPreferences by injectLazy() - private val progressNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS) { + private val progressNotificationBuilder = context.notificationBuilder( + Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS, + ) { setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher)) setSmallIcon(R.drawable.ic_tachi) setAutoCancel(false) @@ -24,7 +26,9 @@ class SyncNotifier(private val context: Context) { setOnlyAlertOnce(true) } - private val completeNotificationBuilder = context.notificationBuilder(Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS) { + private val completeNotificationBuilder = context.notificationBuilder( + Notifications.CHANNEL_BACKUP_RESTORE_PROGRESS, + ) { setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher)) setSmallIcon(R.drawable.ic_tachi) setAutoCancel(false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt index 8710f857f..6c0e1ba52 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/GoogleDriveSyncService.kt @@ -36,7 +36,11 @@ import java.io.InputStreamReader import java.util.zip.GZIPInputStream import java.util.zip.GZIPOutputStream -class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: SyncPreferences) : SyncService(context, json, syncPreferences) { +class GoogleDriveSyncService(context: Context, json: Json, syncPreferences: SyncPreferences) : SyncService( + context, + json, + syncPreferences, +) { constructor(context: Context) : this( context, Json { @@ -308,7 +312,12 @@ class GoogleDriveService(private val context: Context) { * @param onSuccess A callback function to be called on successful authorization. * @param onFailure A callback function to be called on authorization failure. */ - fun handleAuthorizationCode(authorizationCode: String, activity: Activity, onSuccess: () -> Unit, onFailure: (String) -> Unit) { + fun handleAuthorizationCode( + authorizationCode: String, + activity: Activity, + onSuccess: () -> Unit, + onFailure: (String) -> Unit, + ) { val jsonFactory: JsonFactory = JacksonFactory.getDefaultInstance() val secrets = GoogleClientSecrets.load( jsonFactory, 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 cbe85cb13..222c8a979 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 @@ -68,7 +68,8 @@ abstract class SyncService( */ fun mergeSyncData(localSyncData: SyncData, remoteSyncData: SyncData): SyncData { val mergedMangaList = mergeMangaLists(localSyncData.backup?.backupManga, remoteSyncData.backup?.backupManga) - val mergedCategoriesList = mergeCategoriesLists(localSyncData.backup?.backupCategories, remoteSyncData.backup?.backupCategories) + val mergedCategoriesList = + mergeCategoriesLists(localSyncData.backup?.backupCategories, remoteSyncData.backup?.backupCategories) // Create the merged Backup object val mergedBackup = Backup( @@ -94,7 +95,10 @@ abstract class SyncService( * @param remoteMangaList The list of remote SyncManga objects. * @return The merged list of SyncManga objects. */ - private fun mergeMangaLists(localMangaList: List?, remoteMangaList: List?): List { + private fun mergeMangaLists( + localMangaList: List?, + remoteMangaList: List?, + ): List { if (localMangaList == null) return remoteMangaList ?: emptyList() if (remoteMangaList == null) return localMangaList @@ -139,7 +143,10 @@ abstract class SyncService( * @param remoteChapters The list of remote SyncChapter objects. * @return The merged list of SyncChapter objects. */ - private fun mergeChapters(localChapters: List, remoteChapters: List): List { + private fun mergeChapters( + localChapters: List, + remoteChapters: List, + ): List { val localChapterMap = localChapters.associateBy { it.url } val remoteChapterMap = remoteChapters.associateBy { it.url } val mergedChapterMap = mutableMapOf() @@ -178,7 +185,10 @@ abstract class SyncService( * @param remoteCategoriesList The list of remote SyncCategory objects. * @return The merged list of SyncCategory objects. */ - private fun mergeCategoriesLists(localCategoriesList: List?, remoteCategoriesList: List?): List { + private fun mergeCategoriesLists( + localCategoriesList: List?, + remoteCategoriesList: List?, + ): List { if (localCategoriesList == null) return remoteCategoriesList ?: emptyList() if (remoteCategoriesList == null) return localCategoriesList val localCategoriesMap = localCategoriesList.associateBy { it.name } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt index 7abd45b80..11de2cae1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/sync/service/SyncYomiSyncService.kt @@ -55,7 +55,10 @@ class SyncYomiSyncService( val client = OkHttpClient() - val headers = Headers.Builder().add("Content-Type", "application/gzip").add("Content-Encoding", "gzip").add("X-API-Token", apiKey).build() + val headers = Headers.Builder().add( + "Content-Type", + "application/gzip", + ).add("Content-Encoding", "gzip").add("X-API-Token", apiKey).build() val mediaType = "application/gzip".toMediaTypeOrNull()