mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-15 15:02:49 +01:00
chore: lint.
Signed-off-by: KaiserBh <kaiserbh@proton.me>
This commit is contained in:
parent
bdf6839291
commit
67b93bb177
@ -80,23 +80,24 @@ object SettingsDataScreen : SearchableSettings {
|
|||||||
|
|
||||||
return listOf(
|
return listOf(
|
||||||
getBackupAndRestoreGroup(backupPreferences = backupPreferences),
|
getBackupAndRestoreGroup(backupPreferences = backupPreferences),
|
||||||
getDataGroup()) + listOf(
|
getDataGroup(),
|
||||||
Preference.PreferenceGroup(
|
) + listOf(
|
||||||
title = stringResource(R.string.label_sync),
|
Preference.PreferenceGroup(
|
||||||
preferenceItems = listOf(
|
title = stringResource(R.string.label_sync),
|
||||||
Preference.PreferenceItem.ListPreference(
|
preferenceItems = listOf(
|
||||||
pref = syncPreferences.syncService(),
|
Preference.PreferenceItem.ListPreference(
|
||||||
title = stringResource(R.string.pref_sync_service),
|
pref = syncPreferences.syncService(),
|
||||||
entries = mapOf(
|
title = stringResource(R.string.pref_sync_service),
|
||||||
SyncManager.SyncService.NONE.value to stringResource(R.string.off),
|
entries = mapOf(
|
||||||
SyncManager.SyncService.SYNCYOMI.value to stringResource(R.string.syncyomi),
|
SyncManager.SyncService.NONE.value to stringResource(R.string.off),
|
||||||
SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(R.string.google_drive),
|
SyncManager.SyncService.SYNCYOMI.value to stringResource(R.string.syncyomi),
|
||||||
),
|
SyncManager.SyncService.GOOGLE_DRIVE.value to stringResource(R.string.google_drive),
|
||||||
onValueChanged = { true },
|
|
||||||
),
|
),
|
||||||
|
onValueChanged = { true },
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
) + getSyncServicePreferences(syncPreferences, syncService)
|
),
|
||||||
|
) + getSyncServicePreferences(syncPreferences, syncService)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -388,9 +389,15 @@ private fun getGoogleDrivePurge(): Preference.PreferenceItem.TextPreference {
|
|||||||
scope.launch {
|
scope.launch {
|
||||||
val result = googleDriveSync.deleteSyncDataFromGoogleDrive()
|
val result = googleDriveSync.deleteSyncDataFromGoogleDrive()
|
||||||
when (result) {
|
when (result) {
|
||||||
GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast(R.string.google_drive_not_signed_in)
|
GoogleDriveSyncService.DeleteSyncDataStatus.NOT_INITIALIZED -> context.toast(
|
||||||
GoogleDriveSyncService.DeleteSyncDataStatus.NO_FILES -> context.toast(R.string.google_drive_sync_data_not_found)
|
R.string.google_drive_not_signed_in,
|
||||||
GoogleDriveSyncService.DeleteSyncDataStatus.SUCCESS -> context.toast(R.string.google_drive_sync_data_purged)
|
)
|
||||||
|
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 context = LocalContext.current
|
||||||
val syncIntervalPref = syncPreferences.syncInterval()
|
val syncIntervalPref = syncPreferences.syncInterval()
|
||||||
val lastSync by syncPreferences.syncLastSync().collectAsState()
|
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(
|
return Preference.PreferenceGroup(
|
||||||
title = stringResource(R.string.pref_sync_service_category),
|
title = stringResource(R.string.pref_sync_service_category),
|
||||||
|
@ -19,8 +19,8 @@ import eu.kanade.tachiyomi.data.download.DownloadCache
|
|||||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
||||||
import eu.kanade.tachiyomi.data.saver.ImageSaver
|
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.sync.service.GoogleDriveService
|
||||||
|
import eu.kanade.tachiyomi.data.track.TrackerManager
|
||||||
import eu.kanade.tachiyomi.extension.ExtensionManager
|
import eu.kanade.tachiyomi.extension.ExtensionManager
|
||||||
import eu.kanade.tachiyomi.network.JavaScriptEngine
|
import eu.kanade.tachiyomi.network.JavaScriptEngine
|
||||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||||
|
@ -138,7 +138,7 @@ class BackupCreator(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun prepExtensionInfoForSync(mangas: List<Manga>): List<BackupSource> {
|
fun prepExtensionInfoForSync(mangas: List<Manga>): List<BackupSource> {
|
||||||
return mangas
|
return mangas
|
||||||
.asSequence()
|
.asSequence()
|
||||||
.map(Manga::source)
|
.map(Manga::source)
|
||||||
@ -177,7 +177,7 @@ class BackupCreator(
|
|||||||
* @param options options for the backup
|
* @param options options for the backup
|
||||||
* @return [BackupManga] containing manga in a serializable form
|
* @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
|
// Entry for this manga
|
||||||
val mangaObject = BackupManga.copyFrom(manga)
|
val mangaObject = BackupManga.copyFrom(manga)
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ class BackupRestorer(
|
|||||||
return updatedManga
|
return updatedManga
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun updateManga(manga: Manga): Long {
|
suspend fun updateManga(manga: Manga): Long {
|
||||||
handler.await(true) {
|
handler.await(true) {
|
||||||
mangasQueries.update(
|
mangasQueries.update(
|
||||||
source = manga.source,
|
source = manga.source,
|
||||||
@ -326,7 +326,11 @@ class BackupRestorer(
|
|||||||
// Update lastPageRead if the chapter is marked as read
|
// Update lastPageRead if the chapter is marked as read
|
||||||
if (updatedChapter.read) {
|
if (updatedChapter.read) {
|
||||||
updatedChapter = updatedChapter.copy(
|
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)
|
insertChapters(newChapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts list of chapters
|
* Inserts list of chapters
|
||||||
*/
|
*/
|
||||||
|
@ -11,6 +11,7 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreJob
|
import eu.kanade.tachiyomi.data.backup.BackupRestoreJob
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateJob
|
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.data.updater.AppUpdateDownloadJob
|
||||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
|
||||||
@ -37,7 +38,6 @@ import uy.kohesive.injekt.api.get
|
|||||||
import uy.kohesive.injekt.injectLazy
|
import uy.kohesive.injekt.injectLazy
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
|
import eu.kanade.tachiyomi.BuildConfig.APPLICATION_ID as ID
|
||||||
import eu.kanade.tachiyomi.data.sync.SyncDataJob
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Global [BroadcastReceiver] that runs on UI thread
|
* Global [BroadcastReceiver] that runs on UI thread
|
||||||
@ -704,7 +704,12 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
action = ACTION_CANCEL_SYNC
|
action = ACTION_CANCEL_SYNC
|
||||||
putExtra(EXTRA_NOTIFICATION_ID, notificationId)
|
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,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ class SyncManager(
|
|||||||
suspend fun syncData() {
|
suspend fun syncData() {
|
||||||
val databaseManga = getAllMangaFromDB()
|
val databaseManga = getAllMangaFromDB()
|
||||||
val backup = Backup(
|
val backup = Backup(
|
||||||
backupCreator.backupMangas(databaseManga, BackupCreateFlags.AutomaticDefaults ),
|
backupCreator.backupMangas(databaseManga, BackupCreateFlags.AutomaticDefaults),
|
||||||
backupCreator.backupCategories(BackupCreateFlags.AutomaticDefaults),
|
backupCreator.backupCategories(BackupCreateFlags.AutomaticDefaults),
|
||||||
emptyList(),
|
emptyList(),
|
||||||
backupCreator.prepExtensionInfoForSync(databaseManga),
|
backupCreator.prepExtensionInfoForSync(databaseManga),
|
||||||
|
@ -16,7 +16,9 @@ class SyncNotifier(private val context: Context) {
|
|||||||
|
|
||||||
private val preferences: SecurityPreferences by injectLazy()
|
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))
|
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
|
||||||
setSmallIcon(R.drawable.ic_tachi)
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
setAutoCancel(false)
|
setAutoCancel(false)
|
||||||
@ -24,7 +26,9 @@ class SyncNotifier(private val context: Context) {
|
|||||||
setOnlyAlertOnce(true)
|
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))
|
setLargeIcon(BitmapFactory.decodeResource(context.resources, R.mipmap.ic_launcher))
|
||||||
setSmallIcon(R.drawable.ic_tachi)
|
setSmallIcon(R.drawable.ic_tachi)
|
||||||
setAutoCancel(false)
|
setAutoCancel(false)
|
||||||
|
@ -36,7 +36,11 @@ import java.io.InputStreamReader
|
|||||||
import java.util.zip.GZIPInputStream
|
import java.util.zip.GZIPInputStream
|
||||||
import java.util.zip.GZIPOutputStream
|
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(
|
constructor(context: Context) : this(
|
||||||
context,
|
context,
|
||||||
Json {
|
Json {
|
||||||
@ -308,7 +312,12 @@ class GoogleDriveService(private val context: Context) {
|
|||||||
* @param onSuccess A callback function to be called on successful authorization.
|
* @param onSuccess A callback function to be called on successful authorization.
|
||||||
* @param onFailure A callback function to be called on authorization failure.
|
* @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 jsonFactory: JsonFactory = JacksonFactory.getDefaultInstance()
|
||||||
val secrets = GoogleClientSecrets.load(
|
val secrets = GoogleClientSecrets.load(
|
||||||
jsonFactory,
|
jsonFactory,
|
||||||
|
@ -68,7 +68,8 @@ abstract class SyncService(
|
|||||||
*/
|
*/
|
||||||
fun mergeSyncData(localSyncData: SyncData, remoteSyncData: SyncData): SyncData {
|
fun mergeSyncData(localSyncData: SyncData, remoteSyncData: SyncData): SyncData {
|
||||||
val mergedMangaList = mergeMangaLists(localSyncData.backup?.backupManga, remoteSyncData.backup?.backupManga)
|
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
|
// Create the merged Backup object
|
||||||
val mergedBackup = Backup(
|
val mergedBackup = Backup(
|
||||||
@ -94,7 +95,10 @@ abstract class SyncService(
|
|||||||
* @param remoteMangaList The list of remote SyncManga objects.
|
* @param remoteMangaList The list of remote SyncManga objects.
|
||||||
* @return The merged list of 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 (localMangaList == null) return remoteMangaList ?: emptyList()
|
||||||
if (remoteMangaList == null) return localMangaList
|
if (remoteMangaList == null) return localMangaList
|
||||||
|
|
||||||
@ -139,7 +143,10 @@ abstract class SyncService(
|
|||||||
* @param remoteChapters The list of remote SyncChapter objects.
|
* @param remoteChapters The list of remote SyncChapter objects.
|
||||||
* @return The merged list of 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 localChapterMap = localChapters.associateBy { it.url }
|
||||||
val remoteChapterMap = remoteChapters.associateBy { it.url }
|
val remoteChapterMap = remoteChapters.associateBy { it.url }
|
||||||
val mergedChapterMap = mutableMapOf<String, BackupChapter>()
|
val mergedChapterMap = mutableMapOf<String, BackupChapter>()
|
||||||
@ -178,7 +185,10 @@ abstract class SyncService(
|
|||||||
* @param remoteCategoriesList The list of remote SyncCategory objects.
|
* @param remoteCategoriesList The list of remote SyncCategory objects.
|
||||||
* @return The merged list of 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 (localCategoriesList == null) return remoteCategoriesList ?: emptyList()
|
||||||
if (remoteCategoriesList == null) return localCategoriesList
|
if (remoteCategoriesList == null) return localCategoriesList
|
||||||
val localCategoriesMap = localCategoriesList.associateBy { it.name }
|
val localCategoriesMap = localCategoriesList.associateBy { it.name }
|
||||||
|
@ -55,7 +55,10 @@ class SyncYomiSyncService(
|
|||||||
|
|
||||||
val client = OkHttpClient()
|
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()
|
val mediaType = "application/gzip".toMediaTypeOrNull()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user