fix force update stuff
This commit is contained in:
+7
-3
@@ -20,7 +20,9 @@ class UpdateComponent(
|
|||||||
private val interactor: UpdateInteractor
|
private val interactor: UpdateInteractor
|
||||||
) : ComponentContext by componentContext {
|
) : ComponentContext by componentContext {
|
||||||
val hasSupport = interactor.hasSupport
|
val hasSupport = interactor.hasSupport
|
||||||
private val exceptionHandler = CoroutineExceptionHandler { context, throwable ->
|
var isForceUpdate = false
|
||||||
|
private set
|
||||||
|
private val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
|
||||||
_state.value = UpdateState.Error(throwable.message ?: "$throwable", throwable)
|
_state.value = UpdateState.Error(throwable.message ?: "$throwable", throwable)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +35,6 @@ class UpdateComponent(
|
|||||||
|
|
||||||
init {
|
init {
|
||||||
lifecycle.doOnDestroy { scope.cancel() }
|
lifecycle.doOnDestroy { scope.cancel() }
|
||||||
|
|
||||||
lifecycle.doOnResume {
|
lifecycle.doOnResume {
|
||||||
val url = pendingUrl
|
val url = pendingUrl
|
||||||
if (_state.value is UpdateState.InstallPermissionRequired && url != null) {
|
if (_state.value is UpdateState.InstallPermissionRequired && url != null) {
|
||||||
@@ -46,7 +47,10 @@ class UpdateComponent(
|
|||||||
|
|
||||||
fun checkUpdates() {
|
fun checkUpdates() {
|
||||||
scope.launch {
|
scope.launch {
|
||||||
interactor.checkUpdate().collect { _state.value = it }
|
interactor.checkUpdate().collect {
|
||||||
|
isForceUpdate = (it as? UpdateState.UpdateAvailable)?.isForceUpdate ?: false
|
||||||
|
_state.value = it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
@@ -39,6 +39,7 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.compose.ui.window.DialogProperties
|
||||||
import com.arkivanov.decompose.extensions.compose.subscribeAsState
|
import com.arkivanov.decompose.extensions.compose.subscribeAsState
|
||||||
import org.jetbrains.compose.resources.stringResource
|
import org.jetbrains.compose.resources.stringResource
|
||||||
import ru.shadowsparky.ui.components.Loading
|
import ru.shadowsparky.ui.components.Loading
|
||||||
@@ -51,11 +52,16 @@ fun UpdateDialog(
|
|||||||
modifier: Modifier = Modifier
|
modifier: Modifier = Modifier
|
||||||
) {
|
) {
|
||||||
val state by component.state.subscribeAsState()
|
val state by component.state.subscribeAsState()
|
||||||
|
val canDismiss = remember(state) { !component.isForceUpdate }
|
||||||
val isVisible = remember(state) { state !is UpdateState.Idle }
|
val isVisible = remember(state) { state !is UpdateState.Idle }
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
BasicAlertDialog(
|
BasicAlertDialog(
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
onDismissRequest = { component.reset() },
|
onDismissRequest = { component.reset() },
|
||||||
|
properties = DialogProperties(
|
||||||
|
canDismiss,
|
||||||
|
canDismiss,
|
||||||
|
),
|
||||||
content = {
|
content = {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier.clip(RoundedCornerShape(28.dp))
|
modifier = Modifier.clip(RoundedCornerShape(28.dp))
|
||||||
|
|||||||
Reference in New Issue
Block a user