chore: lint.

Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
KaiserBh 2023-11-10 00:16:33 +11:00
parent bdf6839291
commit 67b93bb177
No known key found for this signature in database
GPG Key ID: 14D73B142042BBA9
10 changed files with 81 additions and 36 deletions

View File

@ -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),

View File

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

View File

@ -138,7 +138,7 @@ class BackupCreator(
}
}
fun prepExtensionInfoForSync(mangas: List<Manga>): List<BackupSource> {
fun prepExtensionInfoForSync(mangas: List<Manga>): List<BackupSource> {
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)

View File

@ -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
*/

View File

@ -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,
)
}
}
}

View File

@ -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),

View File

@ -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)

View File

@ -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,

View File

@ -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<BackupManga>?, remoteMangaList: List<BackupManga>?): List<BackupManga> {
private fun mergeMangaLists(
localMangaList: List<BackupManga>?,
remoteMangaList: List<BackupManga>?,
): List<BackupManga> {
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<BackupChapter>, remoteChapters: List<BackupChapter>): List<BackupChapter> {
private fun mergeChapters(
localChapters: List<BackupChapter>,
remoteChapters: List<BackupChapter>,
): List<BackupChapter> {
val localChapterMap = localChapters.associateBy { it.url }
val remoteChapterMap = remoteChapters.associateBy { it.url }
val mergedChapterMap = mutableMapOf<String, BackupChapter>()
@ -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<BackupCategory>?, remoteCategoriesList: List<BackupCategory>?): List<BackupCategory> {
private fun mergeCategoriesLists(
localCategoriesList: List<BackupCategory>?,
remoteCategoriesList: List<BackupCategory>?,
): List<BackupCategory> {
if (localCategoriesList == null) return remoteCategoriesList ?: emptyList()
if (remoteCategoriesList == null) return localCategoriesList
val localCategoriesMap = localCategoriesList.associateBy { it.name }

View File

@ -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()