fix remember stuff

This commit is contained in:
Aria Moradi 2023-07-06 20:29:12 +03:30
parent 733181957a
commit 75b9871e55

View File

@ -16,13 +16,13 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import eu.kanade.presentation.more.settings.Preference import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.util.collectAsState import eu.kanade.presentation.util.collectAsState
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.sync.SyncDataJob import eu.kanade.tachiyomi.data.sync.SyncDataJob
import eu.kanade.tachiyomi.data.sync.SyncManager
import eu.kanade.tachiyomi.data.sync.SyncManager.SyncService import eu.kanade.tachiyomi.data.sync.SyncManager.SyncService
import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.system.toast
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
@ -90,13 +90,12 @@ object SettingsSyncScreen : SearchableSettings {
@Composable @Composable
private fun getSyncNowPref(): Preference.PreferenceGroup { private fun getSyncNowPref(): Preference.PreferenceGroup {
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val showDialog = remember { mutableStateOf(false) } var showDialog by remember { mutableStateOf(false) }
val context = LocalContext.current val context = LocalContext.current
if (showDialog) {
if (showDialog.value) {
SyncConfirmationDialog( SyncConfirmationDialog(
onConfirm = { onConfirm = {
showDialog.value = false showDialog = false
scope.launch { scope.launch {
if (!SyncDataJob.isAnyJobRunning(context)) { if (!SyncDataJob.isAnyJobRunning(context)) {
SyncDataJob.startNow(context) SyncDataJob.startNow(context)
@ -105,7 +104,7 @@ object SettingsSyncScreen : SearchableSettings {
} }
} }
}, },
onDismissRequest = { showDialog.value = false }, onDismissRequest = { showDialog = false },
) )
} }
return Preference.PreferenceGroup( return Preference.PreferenceGroup(
@ -115,7 +114,7 @@ object SettingsSyncScreen : SearchableSettings {
title = stringResource(R.string.pref_sync_now), title = stringResource(R.string.pref_sync_now),
subtitle = stringResource(R.string.pref_sync_now_subtitle), subtitle = stringResource(R.string.pref_sync_now_subtitle),
onClick = { onClick = {
showDialog.value = true showDialog = true
}, },
icon = Icons.Outlined.Sync, icon = Icons.Outlined.Sync,
), ),