From 19bc08659b84498b1c1786ddc3d925528765f4d9 Mon Sep 17 00:00:00 2001 From: NGB-Was-Taken <76197326+NGB-Was-Taken@users.noreply.github.com> Date: Sun, 1 Sep 2024 20:30:30 +0545 Subject: [PATCH] Move "Choose what to sync" out of "Sync now" (#1264) --- .../settings/screen/SettingsDataScreen.kt | 22 ++++++++++++++++--- .../screen/data/SyncSettingsSelector.kt | 14 +++--------- 2 files changed, 22 insertions(+), 14 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 dd4b18dab4b6..b58a44427eba 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 @@ -394,11 +394,23 @@ object SettingsDataScreen : SearchableSettings { syncServiceType: SyncManager.SyncService, syncPreferences: SyncPreferences, ): List { - return when (syncServiceType) { + val navigator = LocalNavigator.currentOrThrow + val preferences = when (syncServiceType) { SyncManager.SyncService.NONE -> emptyList() SyncManager.SyncService.SYNCYOMI -> getSelfHostPreferences(syncPreferences) SyncManager.SyncService.GOOGLE_DRIVE -> getGoogleDrivePreferences() } + + return if (syncServiceType != SyncManager.SyncService.NONE) { + preferences + Preference.PreferenceItem.TextPreference( + title = stringResource(SYMR.strings.pref_choose_what_to_sync), + onClick = { + navigator.push(SyncSettingsSelector()) + }, + ) + } else { + preferences + } } @Composable @@ -515,7 +527,7 @@ object SettingsDataScreen : SearchableSettings { @Composable private fun getSyncNowPref(): Preference.PreferenceGroup { - val navigator = LocalNavigator.currentOrThrow + val context = LocalContext.current return Preference.PreferenceGroup( title = stringResource(SYMR.strings.pref_sync_now_group_title), preferenceItems = persistentListOf( @@ -524,7 +536,11 @@ object SettingsDataScreen : SearchableSettings { title = stringResource(SYMR.strings.pref_sync_now), subtitle = stringResource(SYMR.strings.pref_sync_now_subtitle), onClick = { - navigator.push(SyncSettingsSelector()) + if (!SyncDataJob.isRunning(context)) { + SyncDataJob.startNow(context) + } else { + context.toast(SYMR.strings.sync_in_progress) + } }, ), ), diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/SyncSettingsSelector.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/SyncSettingsSelector.kt index 2622c7bfddc3..6041864d6051 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/SyncSettingsSelector.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/data/SyncSettingsSelector.kt @@ -5,7 +5,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.Immutable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue -import androidx.compose.ui.platform.LocalContext import cafe.adriel.voyager.core.model.StateScreenModel import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.navigator.LocalNavigator @@ -16,7 +15,6 @@ import eu.kanade.presentation.components.AppBar import eu.kanade.presentation.util.Screen import eu.kanade.tachiyomi.data.backup.create.BackupOptions import eu.kanade.tachiyomi.data.sync.SyncDataJob -import eu.kanade.tachiyomi.util.system.toast import kotlinx.collections.immutable.ImmutableList import kotlinx.coroutines.flow.update import tachiyomi.i18n.MR @@ -32,7 +30,6 @@ import uy.kohesive.injekt.api.get class SyncSettingsSelector : Screen() { @Composable override fun Content() { - val context = LocalContext.current val navigator = LocalNavigator.currentOrThrow val model = rememberScreenModel { SyncSettingsSelectorModel() } val state by model.state.collectAsState() @@ -48,15 +45,10 @@ class SyncSettingsSelector : Screen() { ) { contentPadding -> LazyColumnWithAction( contentPadding = contentPadding, - actionLabel = stringResource(SYMR.strings.label_sync), - actionEnabled = state.options.canCreate(), + actionLabel = stringResource(MR.strings.action_save), + actionEnabled = true, onClickAction = { - if (!SyncDataJob.isRunning(context)) { - model.syncNow(context) - navigator.pop() - } else { - context.toast(SYMR.strings.sync_in_progress) - } + navigator.pop() }, ) { item {