mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	apply review pointers
This commit is contained in:
		| @@ -22,6 +22,8 @@ import eu.kanade.presentation.more.settings.Preference | ||||
| import eu.kanade.presentation.util.collectAsState | ||||
| import eu.kanade.tachiyomi.R | ||||
| import eu.kanade.tachiyomi.data.sync.SyncDataJob | ||||
| import eu.kanade.tachiyomi.data.sync.SyncManager | ||||
| import eu.kanade.tachiyomi.data.sync.SyncManager.SyncService | ||||
| import eu.kanade.tachiyomi.util.system.toast | ||||
| import kotlinx.coroutines.launch | ||||
| import tachiyomi.domain.sync.SyncPreferences | ||||
| @@ -37,7 +39,7 @@ object SettingsSyncScreen : SearchableSettings { | ||||
|  | ||||
|     @Composable | ||||
|     override fun getPreferences(): List<Preference> { | ||||
|         val syncPreferences = Injekt.get<SyncPreferences>() | ||||
|         val syncPreferences = remember { Injekt.get<SyncPreferences>() } | ||||
|         val syncService by syncPreferences.syncService().collectAsState() | ||||
|  | ||||
|         return listOf( | ||||
| @@ -45,8 +47,8 @@ object SettingsSyncScreen : SearchableSettings { | ||||
|                 pref = syncPreferences.syncService(), | ||||
|                 title = stringResource(R.string.pref_sync_service), | ||||
|                 entries = mapOf( | ||||
|                     0 to stringResource(R.string.off), | ||||
|                     1 to stringResource(R.string.syncyomi), | ||||
|                     SyncService.NONE.value to stringResource(R.string.off), | ||||
|                     SyncService.SYNCYOMI.value to stringResource(R.string.syncyomi), | ||||
|                 ), | ||||
|                 onValueChanged = { true }, | ||||
|             ), | ||||
| @@ -55,16 +57,10 @@ object SettingsSyncScreen : SearchableSettings { | ||||
|  | ||||
|     @Composable | ||||
|     private fun getSyncServicePreferences(syncPreferences: SyncPreferences, syncService: Int): List<Preference> { | ||||
|         val servicePreferences = when (syncService) { | ||||
|             1 -> getSelfHostPreferences(syncPreferences) | ||||
|             else -> emptyList() | ||||
|         } | ||||
|  | ||||
|         return if (syncService != 0) { | ||||
|             servicePreferences + getSyncNowPref() + getAutomaticSyncGroup(syncPreferences) | ||||
|         } else { | ||||
|             servicePreferences | ||||
|         } | ||||
|         return when (SyncService.fromInt(syncService)) { | ||||
|             SyncService.NONE -> emptyList() | ||||
|             SyncService.SYNCYOMI -> getSelfHostPreferences(syncPreferences) | ||||
|         } + getSyncNowPref() + getAutomaticSyncGroup(syncPreferences) | ||||
|     } | ||||
|  | ||||
|     @Composable | ||||
| @@ -102,7 +98,7 @@ object SettingsSyncScreen : SearchableSettings { | ||||
|                 onConfirm = { | ||||
|                     showDialog.value = false | ||||
|                     scope.launch { | ||||
|                         if (!SyncDataJob.isManualJobRunning(context)) { | ||||
|                         if (!SyncDataJob.isAnyJobRunning(context)) { | ||||
|                             SyncDataJob.startNow(context) | ||||
|                         } else { | ||||
|                             context.toast(R.string.sync_in_progress) | ||||
| @@ -156,7 +152,7 @@ object SettingsSyncScreen : SearchableSettings { | ||||
|                         true | ||||
|                     }, | ||||
|                 ), | ||||
|                 Preference.PreferenceItem.InfoPreference(stringResource(R.string.last_synchronization) + ": " + formattedLastSync), | ||||
|                 Preference.PreferenceItem.InfoPreference(stringResource(R.string.last_synchronization, formattedLastSync)), | ||||
|             ), | ||||
|         ) | ||||
|     } | ||||
|   | ||||
| @@ -454,7 +454,7 @@ class BackupManager( | ||||
|                 updatedChapter = updatedChapter.copy(id = dbChapter._id) | ||||
|                 updatedChapter = updatedChapter.copyFrom(dbChapter) | ||||
|                 if (dbChapter.read && !updatedChapter.read) { | ||||
|                     updatedChapter = updatedChapter.copy(read = chapter.read, lastPageRead = dbChapter.last_page_read) | ||||
|                     updatedChapter = updatedChapter.copy(read = true, lastPageRead = dbChapter.last_page_read) | ||||
|                 } else if (updatedChapter.lastPageRead == 0L && dbChapter.last_page_read != 0L) { | ||||
|                     updatedChapter = updatedChapter.copy(lastPageRead = dbChapter.last_page_read) | ||||
|                 } | ||||
|   | ||||
| @@ -56,8 +56,10 @@ class SyncDataJob(private val context: Context, workerParams: WorkerParameters) | ||||
|         private const val TAG_AUTO = "$TAG_JOB:auto" | ||||
|         private const val TAG_MANUAL = "$TAG_JOB:manual" | ||||
|  | ||||
|         fun isManualJobRunning(context: Context): Boolean { | ||||
|             return context.workManager.isRunning(TAG_MANUAL) | ||||
|         private val jobTagList = listOf(TAG_AUTO, TAG_MANUAL) | ||||
|  | ||||
|         fun isAnyJobRunning(context: Context): Boolean { | ||||
|             return jobTagList.any { context.workManager.isRunning(it) } | ||||
|         } | ||||
|  | ||||
|         fun setupTask(context: Context, prefInterval: Int? = null) { | ||||
|   | ||||
| @@ -8,7 +8,7 @@ import eu.kanade.tachiyomi.data.backup.BackupRestoreJob | ||||
| import eu.kanade.tachiyomi.data.backup.models.Backup | ||||
| import eu.kanade.tachiyomi.data.backup.models.BackupChapter | ||||
| import eu.kanade.tachiyomi.data.backup.models.BackupManga | ||||
| import eu.kanade.tachiyomi.data.sync.models.SData | ||||
| import eu.kanade.tachiyomi.data.sync.models.SyncData | ||||
| import eu.kanade.tachiyomi.data.sync.models.SyncDevice | ||||
| import eu.kanade.tachiyomi.data.sync.models.SyncStatus | ||||
| import eu.kanade.tachiyomi.data.sync.service.SyncYomiSyncService | ||||
| @@ -87,7 +87,7 @@ class SyncManager( | ||||
|         ) | ||||
|  | ||||
|         // Create the SyncData object | ||||
|         val syncData = SData( | ||||
|         val syncData = SyncData( | ||||
|             sync = syncStatus, | ||||
|             backup = backup, | ||||
|             device = device, | ||||
|   | ||||
| @@ -17,7 +17,7 @@ data class SyncDevice( | ||||
| ) | ||||
|  | ||||
| @Serializable | ||||
| data class SData( | ||||
| data class SyncData( | ||||
|     val sync: SyncStatus? = null, | ||||
|     val backup: Backup? = null, | ||||
|     val device: SyncDevice? = null, | ||||
|   | ||||
| @@ -2,7 +2,7 @@ package eu.kanade.tachiyomi.data.sync.service | ||||
|  | ||||
| import android.content.Context | ||||
| import eu.kanade.tachiyomi.data.backup.models.Backup | ||||
| import eu.kanade.tachiyomi.data.sync.models.SData | ||||
| import eu.kanade.tachiyomi.data.sync.models.SyncData | ||||
| import kotlinx.serialization.json.Json | ||||
| import tachiyomi.domain.sync.SyncPreferences | ||||
|  | ||||
| @@ -11,7 +11,7 @@ abstract class SyncService( | ||||
|     val json: Json, | ||||
|     val syncPreferences: SyncPreferences, | ||||
| ) { | ||||
|     abstract suspend fun doSync(syncData: SData): Backup? | ||||
|     abstract suspend fun doSync(syncData: SyncData): Backup? | ||||
|  | ||||
|     /** | ||||
|      * Decodes the given sync data string into a Backup object. | ||||
| @@ -20,7 +20,7 @@ abstract class SyncService( | ||||
|      * @return The decoded Backup object. | ||||
|      */ | ||||
|     protected fun decodeSyncBackup(data: String): Backup { | ||||
|         val sData = json.decodeFromString(SData.serializer(), data) | ||||
|         return sData.backup!! | ||||
|         val syncData = json.decodeFromString(SyncData.serializer(), data) | ||||
|         return syncData.backup!! | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -3,7 +3,7 @@ package eu.kanade.tachiyomi.data.sync.service | ||||
| import android.content.Context | ||||
| import eu.kanade.tachiyomi.data.backup.models.Backup | ||||
| import eu.kanade.tachiyomi.data.sync.SyncNotifier | ||||
| import eu.kanade.tachiyomi.data.sync.models.SData | ||||
| import eu.kanade.tachiyomi.data.sync.models.SyncData | ||||
| import eu.kanade.tachiyomi.network.POST | ||||
| import kotlinx.serialization.encodeToString | ||||
| import kotlinx.serialization.json.Json | ||||
| @@ -22,7 +22,7 @@ class SyncYomiSyncService( | ||||
|     syncPreferences: SyncPreferences, | ||||
|     private val notifier: SyncNotifier, | ||||
| ) : SyncService(context, json, syncPreferences) { | ||||
|     override suspend fun doSync(syncData: SData): Backup? { | ||||
|     override suspend fun doSync(syncData: SyncData): Backup? { | ||||
|         logcat( | ||||
|             LogPriority.DEBUG, | ||||
|         ) { "SyncYomi sync started!" } | ||||
| @@ -49,7 +49,7 @@ class SyncYomiSyncService( | ||||
|             val responseBody = response.body.string() | ||||
|  | ||||
|             if (response.isSuccessful) { | ||||
|                 val syncDataResponse: SData = json.decodeFromString(responseBody) | ||||
|                 val syncDataResponse: SyncData = json.decodeFromString(responseBody) | ||||
|  | ||||
|                 // If the device ID is 0 and not equal to the server device ID (this happens when the DB is fresh and the app is not), update it | ||||
|                 if (syncPreferences.deviceID().get() == 0 || syncPreferences.deviceID().get() != syncDataResponse.device?.id) { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user