mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-08 18: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.LocalNavigator
|
||||||
import cafe.adriel.voyager.navigator.currentOrThrow
|
import cafe.adriel.voyager.navigator.currentOrThrow
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
|
import eu.kanade.domain.sync.SyncPreferences
|
||||||
import eu.kanade.presentation.more.settings.Preference
|
import eu.kanade.presentation.more.settings.Preference
|
||||||
import eu.kanade.presentation.more.settings.screen.data.CreateBackupScreen
|
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.RestoreBackupScreen
|
||||||
import eu.kanade.presentation.more.settings.screen.data.StorageInfo
|
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.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.BasePreferenceWidget
|
||||||
import eu.kanade.presentation.more.settings.widget.PrefsHorizontalPadding
|
import eu.kanade.presentation.more.settings.widget.PrefsHorizontalPadding
|
||||||
import eu.kanade.presentation.util.relativeTimeSpanString
|
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.backup.service.BackupPreferences
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences
|
import tachiyomi.domain.library.service.LibraryPreferences
|
||||||
import tachiyomi.domain.storage.service.StoragePreferences
|
import tachiyomi.domain.storage.service.StoragePreferences
|
||||||
import tachiyomi.domain.sync.SyncPreferences
|
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.presentation.core.i18n.stringResource
|
import tachiyomi.presentation.core.i18n.stringResource
|
||||||
import tachiyomi.presentation.core.util.collectAsState
|
import tachiyomi.presentation.core.util.collectAsState
|
||||||
@@ -443,13 +443,13 @@ object SettingsDataScreen : SearchableSettings {
|
|||||||
Preference.PreferenceItem.EditTextPreference(
|
Preference.PreferenceItem.EditTextPreference(
|
||||||
title = stringResource(MR.strings.pref_sync_host),
|
title = stringResource(MR.strings.pref_sync_host),
|
||||||
subtitle = stringResource(MR.strings.pref_sync_host_summ),
|
subtitle = stringResource(MR.strings.pref_sync_host_summ),
|
||||||
pref = syncPreferences.syncHost(),
|
pref = syncPreferences.clientHost(),
|
||||||
onValueChanged = { newValue ->
|
onValueChanged = { newValue ->
|
||||||
scope.launch {
|
scope.launch {
|
||||||
// Trim spaces at the beginning and end, then remove trailing slash if present
|
// Trim spaces at the beginning and end, then remove trailing slash if present
|
||||||
val trimmedValue = newValue.trim()
|
val trimmedValue = newValue.trim()
|
||||||
val modifiedValue = trimmedValue.trimEnd { it == '/' }
|
val modifiedValue = trimmedValue.trimEnd { it == '/' }
|
||||||
syncPreferences.syncHost().set(modifiedValue)
|
syncPreferences.clientHost().set(modifiedValue)
|
||||||
}
|
}
|
||||||
true
|
true
|
||||||
},
|
},
|
||||||
@@ -457,7 +457,7 @@ object SettingsDataScreen : SearchableSettings {
|
|||||||
Preference.PreferenceItem.EditTextPreference(
|
Preference.PreferenceItem.EditTextPreference(
|
||||||
title = stringResource(MR.strings.pref_sync_api_key),
|
title = stringResource(MR.strings.pref_sync_api_key),
|
||||||
subtitle = stringResource(MR.strings.pref_sync_api_key_summ),
|
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(
|
return Preference.PreferenceItem.TextPreference(
|
||||||
title = stringResource(MR.strings.pref_sync_options),
|
title = stringResource(MR.strings.pref_sync_options),
|
||||||
subtitle = stringResource(MR.strings.pref_sync_options_summ),
|
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 coil.util.DebugLogger
|
||||||
import eu.kanade.domain.DomainModule
|
import eu.kanade.domain.DomainModule
|
||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
|
import eu.kanade.domain.sync.SyncPreferences
|
||||||
import eu.kanade.domain.ui.UiPreferences
|
import eu.kanade.domain.ui.UiPreferences
|
||||||
import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode
|
import eu.kanade.domain.ui.model.setAppCompatDelegateThemeMode
|
||||||
import eu.kanade.tachiyomi.crash.CrashActivity
|
import eu.kanade.tachiyomi.crash.CrashActivity
|
||||||
@@ -52,7 +53,6 @@ import logcat.LogcatLogger
|
|||||||
import org.conscrypt.Conscrypt
|
import org.conscrypt.Conscrypt
|
||||||
import tachiyomi.core.i18n.stringResource
|
import tachiyomi.core.i18n.stringResource
|
||||||
import tachiyomi.core.util.system.logcat
|
import tachiyomi.core.util.system.logcat
|
||||||
import tachiyomi.domain.sync.SyncPreferences
|
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import tachiyomi.presentation.widget.WidgetManager
|
import tachiyomi.presentation.widget.WidgetManager
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
@@ -133,10 +133,8 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val syncPreferences: SyncPreferences by injectLazy()
|
val syncPreferences: SyncPreferences by injectLazy()
|
||||||
val syncFlags = syncPreferences.syncFlags().get()
|
val syncTriggerOpt = syncPreferences.getSyncTriggerOptions()
|
||||||
if (syncPreferences.isSyncEnabled() && syncFlags and
|
if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnAppStart) {
|
||||||
SyncPreferences.Flags.SYNC_ON_APP_START == SyncPreferences.Flags.SYNC_ON_APP_START
|
|
||||||
) {
|
|
||||||
SyncDataJob.startNow(this@App)
|
SyncDataJob.startNow(this@App)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,9 +172,8 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
|
|||||||
SecureActivityDelegate.onApplicationStart()
|
SecureActivityDelegate.onApplicationStart()
|
||||||
|
|
||||||
val syncPreferences: SyncPreferences by injectLazy()
|
val syncPreferences: SyncPreferences by injectLazy()
|
||||||
val syncFlags = syncPreferences.syncFlags().get()
|
val syncTriggerOpt = syncPreferences.getSyncTriggerOptions()
|
||||||
if (syncPreferences.isSyncEnabled() && syncFlags
|
if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnAppResume
|
||||||
and SyncPreferences.Flags.SYNC_ON_APP_RESUME == SyncPreferences.Flags.SYNC_ON_APP_RESUME
|
|
||||||
) {
|
) {
|
||||||
SyncDataJob.startNow(this@App)
|
SyncDataJob.startNow(this@App)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import androidx.work.workDataOf
|
|||||||
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
|
import eu.kanade.domain.chapter.interactor.SyncChaptersWithSource
|
||||||
import eu.kanade.domain.manga.interactor.UpdateManga
|
import eu.kanade.domain.manga.interactor.UpdateManga
|
||||||
import eu.kanade.domain.manga.model.toSManga
|
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.cache.CoverCache
|
||||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
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.manga.model.Manga
|
||||||
import tachiyomi.domain.source.model.SourceNotInstalledException
|
import tachiyomi.domain.source.model.SourceNotInstalledException
|
||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import tachiyomi.domain.sync.SyncPreferences
|
|
||||||
import tachiyomi.i18n.MR
|
import tachiyomi.i18n.MR
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@@ -480,9 +480,8 @@ class LibraryUpdateJob(private val context: Context, workerParams: WorkerParamet
|
|||||||
val syncPreferences: SyncPreferences = Injekt.get()
|
val syncPreferences: SyncPreferences = Injekt.get()
|
||||||
|
|
||||||
// Only proceed with SyncDataJob if sync is enabled and the specific sync on library update flag is set
|
// 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
|
val syncTriggerOpt = syncPreferences.getSyncTriggerOptions()
|
||||||
SyncPreferences.Flags.SYNC_ON_LIBRARY_UPDATE == SyncPreferences.Flags.SYNC_ON_LIBRARY_UPDATE
|
if (syncPreferences.isSyncEnabled() && syncTriggerOpt.syncOnLibraryUpdate) {
|
||||||
) {
|
|
||||||
// Check if SyncDataJob is already running
|
// Check if SyncDataJob is already running
|
||||||
if (wm.isRunning(SyncDataJob.TAG_MANUAL)) {
|
if (wm.isRunning(SyncDataJob.TAG_MANUAL)) {
|
||||||
// SyncDataJob is already running
|
// SyncDataJob is already running
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.di
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import eu.kanade.domain.base.BasePreferences
|
import eu.kanade.domain.base.BasePreferences
|
||||||
import eu.kanade.domain.source.service.SourcePreferences
|
import eu.kanade.domain.source.service.SourcePreferences
|
||||||
|
import eu.kanade.domain.sync.SyncPreferences
|
||||||
import eu.kanade.domain.track.service.TrackPreferences
|
import eu.kanade.domain.track.service.TrackPreferences
|
||||||
import eu.kanade.domain.ui.UiPreferences
|
import eu.kanade.domain.ui.UiPreferences
|
||||||
import eu.kanade.tachiyomi.core.security.SecurityPreferences
|
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.download.service.DownloadPreferences
|
||||||
import tachiyomi.domain.library.service.LibraryPreferences
|
import tachiyomi.domain.library.service.LibraryPreferences
|
||||||
import tachiyomi.domain.storage.service.StoragePreferences
|
import tachiyomi.domain.storage.service.StoragePreferences
|
||||||
import tachiyomi.domain.sync.SyncPreferences
|
|
||||||
import uy.kohesive.injekt.api.InjektModule
|
import uy.kohesive.injekt.api.InjektModule
|
||||||
import uy.kohesive.injekt.api.InjektRegistrar
|
import uy.kohesive.injekt.api.InjektRegistrar
|
||||||
import uy.kohesive.injekt.api.addSingletonFactory
|
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.interactor.SetMangaViewerFlags
|
||||||
import eu.kanade.domain.manga.model.readerOrientation
|
import eu.kanade.domain.manga.model.readerOrientation
|
||||||
import eu.kanade.domain.manga.model.readingMode
|
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.interactor.TrackChapter
|
||||||
import eu.kanade.domain.track.service.TrackPreferences
|
import eu.kanade.domain.track.service.TrackPreferences
|
||||||
import eu.kanade.tachiyomi.data.database.models.toDomainChapter
|
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.interactor.GetManga
|
||||||
import tachiyomi.domain.manga.model.Manga
|
import tachiyomi.domain.manga.model.Manga
|
||||||
import tachiyomi.domain.source.service.SourceManager
|
import tachiyomi.domain.source.service.SourceManager
|
||||||
import tachiyomi.domain.sync.SyncPreferences
|
|
||||||
import tachiyomi.source.local.isLocal
|
import tachiyomi.source.local.isLocal
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
@@ -519,7 +519,8 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
*/
|
*/
|
||||||
private suspend fun updateChapterProgress(readerChapter: ReaderChapter, page: Page) {
|
private suspend fun updateChapterProgress(readerChapter: ReaderChapter, page: Page) {
|
||||||
val pageIndex = page.index
|
val pageIndex = page.index
|
||||||
val syncFlags = syncPreferences.syncFlags().get()
|
val syncTriggerOpt = syncPreferences.getSyncTriggerOptions()
|
||||||
|
val isSyncEnabled = syncPreferences.isSyncEnabled()
|
||||||
|
|
||||||
mutableState.update {
|
mutableState.update {
|
||||||
it.copy(currentPage = pageIndex + 1)
|
it.copy(currentPage = pageIndex + 1)
|
||||||
@@ -536,10 +537,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
deleteChapterIfNeeded(readerChapter)
|
deleteChapterIfNeeded(readerChapter)
|
||||||
|
|
||||||
// Check if syncing is enabled for chapter read:
|
// Check if syncing is enabled for chapter read:
|
||||||
if (syncPreferences.isSyncEnabled() &&
|
if (isSyncEnabled && syncTriggerOpt.syncOnChapterRead) {
|
||||||
syncFlags and
|
|
||||||
SyncPreferences.Flags.SYNC_ON_CHAPTER_READ == SyncPreferences.Flags.SYNC_ON_CHAPTER_READ
|
|
||||||
) {
|
|
||||||
SyncDataJob.startNow(Injekt.get<Application>())
|
SyncDataJob.startNow(Injekt.get<Application>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -553,9 +551,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Check if syncing is enabled for chapter open:
|
// Check if syncing is enabled for chapter open:
|
||||||
if (syncPreferences.isSyncEnabled() &&
|
if (isSyncEnabled && syncTriggerOpt.syncOnChapterOpen && readerChapter.chapter.last_page_read == 0) {
|
||||||
syncFlags and SyncPreferences.Flags.SYNC_ON_CHAPTER_OPEN == SyncPreferences.Flags.SYNC_ON_CHAPTER_OPEN
|
|
||||||
) {
|
|
||||||
SyncDataJob.startNow(Injekt.get<Application>())
|
SyncDataJob.startNow(Injekt.get<Application>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
<string name="label_data_storage">Data and storage</string>
|
<string name="label_data_storage">Data and storage</string>
|
||||||
<string name="label_backup">Backup</string>
|
<string name="label_backup">Backup</string>
|
||||||
<string name="label_sync">Sync</string>
|
<string name="label_sync">Sync</string>
|
||||||
|
<string name="label_triggers">Triggers</string>
|
||||||
<string name="label_stats">Statistics</string>
|
<string name="label_stats">Statistics</string>
|
||||||
<string name="label_migration">Migrate</string>
|
<string name="label_migration">Migrate</string>
|
||||||
<string name="label_extensions">Extensions</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">Create sync triggers</string>
|
||||||
<string name="pref_sync_options_summ">Can be used to set 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_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_start">Sync on App Start</string>
|
||||||
<string name="sync_on_app_resume">Sync on App Resume</string>
|
<string name="sync_on_app_resume">Sync on App Resume</string>
|
||||||
<string name="sync_on_library_update">Sync on Library Update</string>
|
<string name="sync_on_library_update">Sync on Library Update</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user