Skip to content

Commit

Permalink
Move "Choose what to sync" out of "Sync now" (#1264)
Browse files Browse the repository at this point in the history
  • Loading branch information
NGB-Was-Taken committed Sep 1, 2024
1 parent 2cb8f8f commit 19bc086
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,11 +394,23 @@ object SettingsDataScreen : SearchableSettings {
syncServiceType: SyncManager.SyncService,
syncPreferences: SyncPreferences,
): List<Preference> {
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
Expand Down Expand Up @@ -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(
Expand All @@ -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)
}
},
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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 {
Expand Down

0 comments on commit 19bc086

Please sign in to comment.