mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-06 17:18:56 +01:00
refactor: fix up the sync triggers, and update imports.
This commit is contained in:
@@ -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()) },
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Application>())
|
||||
}
|
||||
}
|
||||
@@ -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<Application>())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<string name="label_data_storage">Data and storage</string>
|
||||
<string name="label_backup">Backup</string>
|
||||
<string name="label_sync">Sync</string>
|
||||
<string name="label_triggers">Triggers</string>
|
||||
<string name="label_stats">Statistics</string>
|
||||
<string name="label_migration">Migrate</string>
|
||||
<string name="label_extensions">Extensions</string>
|
||||
@@ -586,7 +587,7 @@
|
||||
<string name="pref_sync_options">Create sync triggers</string>
|
||||
<string name="pref_sync_options_summ">Can be used to set sync triggers</string>
|
||||
<string name="sync_on_chapter_read">Sync on Chapter Read</string>
|
||||
<string name="sync_on_chapter_open">Sync on Every Chapter Page</string>
|
||||
<string name="sync_on_chapter_open">Sync on Chapter Open</string>
|
||||
<string name="sync_on_app_start">Sync on App Start</string>
|
||||
<string name="sync_on_app_resume">Sync on App Resume</string>
|
||||
<string name="sync_on_library_update">Sync on Library Update</string>
|
||||
|
||||
Reference in New Issue
Block a user