From bc326f8fb4ea05bef304919ec1fbe1e975761912 Mon Sep 17 00:00:00 2001 From: kaiserbh Date: Sat, 20 Jan 2024 17:13:02 +1100 Subject: [PATCH] refactor: fix up the sync triggers, and update imports. --- .../more/settings/screen/SettingsDataScreen.kt | 12 ++++++------ app/src/main/java/eu/kanade/tachiyomi/App.kt | 13 +++++-------- .../tachiyomi/data/library/LibraryUpdateJob.kt | 7 +++---- .../eu/kanade/tachiyomi/di/PreferenceModule.kt | 2 +- .../kanade/tachiyomi/ui/reader/ReaderViewModel.kt | 14 +++++--------- i18n/src/commonMain/resources/MR/base/strings.xml | 3 ++- 6 files changed, 22 insertions(+), 29 deletions(-) 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 acbcb50c36..bb670b22a9 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 @@ -35,12 +35,13 @@ import androidx.core.net.toUri import cafe.adriel.voyager.navigator.LocalNavigator import cafe.adriel.voyager.navigator.currentOrThrow import com.hippo.unifile.UniFile +import eu.kanade.domain.sync.SyncPreferences import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.screen.data.CreateBackupScreen import eu.kanade.presentation.more.settings.screen.data.RestoreBackupScreen import eu.kanade.presentation.more.settings.screen.data.StorageInfo -import eu.kanade.presentation.more.settings.screen.data.SyncOptionsScreen import eu.kanade.presentation.more.settings.screen.data.SyncSettingsSelector +import eu.kanade.presentation.more.settings.screen.data.SyncTriggerOptionsScreen import eu.kanade.presentation.more.settings.widget.BasePreferenceWidget import eu.kanade.presentation.more.settings.widget.PrefsHorizontalPadding import eu.kanade.presentation.util.relativeTimeSpanString @@ -65,7 +66,6 @@ import tachiyomi.core.util.system.logcat import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.storage.service.StoragePreferences -import tachiyomi.domain.sync.SyncPreferences import tachiyomi.i18n.MR import tachiyomi.presentation.core.i18n.stringResource import tachiyomi.presentation.core.util.collectAsState @@ -443,13 +443,13 @@ object SettingsDataScreen : SearchableSettings { Preference.PreferenceItem.EditTextPreference( title = stringResource(MR.strings.pref_sync_host), subtitle = stringResource(MR.strings.pref_sync_host_summ), - pref = syncPreferences.syncHost(), + pref = syncPreferences.clientHost(), onValueChanged = { newValue -> scope.launch { // Trim spaces at the beginning and end, then remove trailing slash if present val trimmedValue = newValue.trim() val modifiedValue = trimmedValue.trimEnd { it == '/' } - syncPreferences.syncHost().set(modifiedValue) + syncPreferences.clientHost().set(modifiedValue) } true }, @@ -457,7 +457,7 @@ object SettingsDataScreen : SearchableSettings { Preference.PreferenceItem.EditTextPreference( title = stringResource(MR.strings.pref_sync_api_key), subtitle = stringResource(MR.strings.pref_sync_api_key_summ), - pref = syncPreferences.syncAPIKey(), + pref = syncPreferences.clientAPIKey(), ), ) } @@ -486,7 +486,7 @@ object SettingsDataScreen : SearchableSettings { return Preference.PreferenceItem.TextPreference( title = stringResource(MR.strings.pref_sync_options), subtitle = stringResource(MR.strings.pref_sync_options_summ), - onClick = { navigator.push(SyncOptionsScreen()) }, + onClick = { navigator.push(SyncTriggerOptionsScreen()) }, ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index ef9659d1a2..832e88077a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -23,6 +23,7 @@ import coil.disk.DiskCache import coil.util.DebugLogger import eu.kanade.domain.DomainModule import eu.kanade.domain.base.BasePreferences +import eu.kanade.domain.sync.SyncPreferences import eu.kanade.domain.ui.UiPreferences import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode import eu.kanade.tachiyomi.crash.CrashActivity @@ -52,7 +53,6 @@ import logcat.LogcatLogger import org.conscrypt.Conscrypt import tachiyomi.core.i18n.stringResource import tachiyomi.core.util.system.logcat -import tachiyomi.domain.sync.SyncPreferences import tachiyomi.i18n.MR import tachiyomi.presentation.widget.WidgetManager import uy.kohesive.injekt.Injekt @@ -133,10 +133,8 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { } val syncPreferences: SyncPreferences by injectLazy() - val syncFlags = syncPreferences.syncFlags().get() - if (syncPreferences.isSyncEnabled() && syncFlags and - SyncPreferences.Flags.SYNC_ON_APP_START == SyncPreferences.Flags.SYNC_ON_APP_START - ) { + val syncTriggerOpt = syncPreferences.getSyncTriggerOptions() + if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnAppStart) { SyncDataJob.startNow(this@App) } } @@ -174,9 +172,8 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { SecureActivityDelegate.onApplicationStart() val syncPreferences: SyncPreferences by injectLazy() - val syncFlags = syncPreferences.syncFlags().get() - if (syncPreferences.isSyncEnabled() && syncFlags - and SyncPreferences.Flags.SYNC_ON_APP_RESUME == SyncPreferences.Flags.SYNC_ON_APP_RESUME + val syncTriggerOpt = syncPreferences.getSyncTriggerOptions() + if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnAppResume ) { SyncDataJob.startNow(this@App) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt index 3b85d03eef..9872a47aa7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/LibraryUpdateJob.kt @@ -19,6 +19,7 @@ import androidx.work.workDataOf import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource import eu.kanade.domain.manga.interactor.UpdateManga import eu.kanade.domain.manga.model.toSManga +import eu.kanade.domain.sync.SyncPreferences import eu.kanade.tachiyomi.data.cache.CoverCache import eu.kanade.tachiyomi.data.download.DownloadManager import eu.kanade.tachiyomi.data.notification.Notifications @@ -64,7 +65,6 @@ import tachiyomi.domain.manga.interactor.GetManga import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.source.model.SourceNotInstalledException import tachiyomi.domain.source.service.SourceManager -import tachiyomi.domain.sync.SyncPreferences import tachiyomi.i18n.MR import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -480,9 +480,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet val syncPreferences: SyncPreferences = Injekt.get() // Only proceed with SyncDataJob if sync is enabled and the specific sync on library update flag is set - if (syncPreferences.isSyncEnabled() && syncPreferences.syncFlags().get() and - SyncPreferences.Flags.SYNC_ON_LIBRARY_UPDATE == SyncPreferences.Flags.SYNC_ON_LIBRARY_UPDATE - ) { + val syncTriggerOpt = syncPreferences.getSyncTriggerOptions() + if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnLibraryUpdate) { // Check if SyncDataJob is already running if (wm.isRunning(SyncDataJob.TAG_MANUAL)) { // SyncDataJob is already running diff --git a/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt b/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt index 0981ead0f9..539e53687d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/di/PreferenceModule.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.di import android.app.Application import eu.kanade.domain.base.BasePreferences import eu.kanade.domain.source.service.SourcePreferences +import eu.kanade.domain.sync.SyncPreferences import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.domain.ui.UiPreferences import eu.kanade.tachiyomi.core.security.SecurityPreferences @@ -16,7 +17,6 @@ import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.domain.download.service.DownloadPreferences import tachiyomi.domain.library.service.LibraryPreferences import tachiyomi.domain.storage.service.StoragePreferences -import tachiyomi.domain.sync.SyncPreferences import uy.kohesive.injekt.api.InjektModule import uy.kohesive.injekt.api.InjektRegistrar import uy.kohesive.injekt.api.addSingletonFactory diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt index 8170c53107..48597a3e09 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt @@ -12,6 +12,7 @@ import eu.kanade.domain.chapter.model.toDbChapter import eu.kanade.domain.manga.interactor.SetMangaViewerFlags import eu.kanade.domain.manga.model.readerOrientation import eu.kanade.domain.manga.model.readingMode +import eu.kanade.domain.sync.SyncPreferences import eu.kanade.domain.track.interactor.TrackChapter import eu.kanade.domain.track.service.TrackPreferences import eu.kanade.tachiyomi.data.database.models.toDomainChapter @@ -73,7 +74,6 @@ import tachiyomi.domain.history.model.HistoryUpdate import tachiyomi.domain.manga.interactor.GetManga import tachiyomi.domain.manga.model.Manga import tachiyomi.domain.source.service.SourceManager -import tachiyomi.domain.sync.SyncPreferences import tachiyomi.source.local.isLocal import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -519,7 +519,8 @@ class ReaderViewModel @JvmOverloads constructor( */ private suspend fun updateChapterProgress(readerChapter: ReaderChapter, page: Page) { val pageIndex = page.index - val syncFlags = syncPreferences.syncFlags().get() + val syncTriggerOpt = syncPreferences.getSyncTriggerOptions() + val isSyncEnabled = syncPreferences.isSyncEnabled() mutableState.update { it.copy(currentPage = pageIndex + 1) @@ -536,10 +537,7 @@ class ReaderViewModel @JvmOverloads constructor( deleteChapterIfNeeded(readerChapter) // Check if syncing is enabled for chapter read: - if (syncPreferences.isSyncEnabled() && - syncFlags and - SyncPreferences.Flags.SYNC_ON_CHAPTER_READ == SyncPreferences.Flags.SYNC_ON_CHAPTER_READ - ) { + if (isSyncEnabled && syncTriggerOpt.syncOnChapterRead) { SyncDataJob.startNow(Injekt.get()) } } @@ -553,9 +551,7 @@ class ReaderViewModel @JvmOverloads constructor( ) // Check if syncing is enabled for chapter open: - if (syncPreferences.isSyncEnabled() && - syncFlags and SyncPreferences.Flags.SYNC_ON_CHAPTER_OPEN == SyncPreferences.Flags.SYNC_ON_CHAPTER_OPEN - ) { + if (isSyncEnabled && syncTriggerOpt.syncOnChapterOpen && readerChapter.chapter.last_page_read == 0) { SyncDataJob.startNow(Injekt.get()) } } diff --git a/i18n/src/commonMain/resources/MR/base/strings.xml b/i18n/src/commonMain/resources/MR/base/strings.xml index 5ee613351d..b96002f3df 100644 --- a/i18n/src/commonMain/resources/MR/base/strings.xml +++ b/i18n/src/commonMain/resources/MR/base/strings.xml @@ -31,6 +31,7 @@ Data and storage Backup Sync + Triggers Statistics Migrate Extensions @@ -586,7 +587,7 @@ Create sync triggers Can be used to set sync triggers Sync on Chapter Read - Sync on Every Chapter Page + Sync on Chapter Open Sync on App Start Sync on App Resume Sync on Library Update