update error content
This commit is contained in:
+48
-11
@@ -29,10 +29,14 @@ import androidx.compose.material3.LinearWavyProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.withFrameNanos
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.arkivanov.decompose.extensions.compose.subscribeAsState
|
||||
@@ -58,16 +62,19 @@ fun UpdateDialog(
|
||||
onDismissRequest = { component.reset() },
|
||||
canDismiss = canDismiss,
|
||||
content = {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
when (val currentState = state) {
|
||||
is UpdateState.Checking -> UpdateCheckingContent()
|
||||
is UpdateState.UpdateAvailable -> UpdateAvailableContent(
|
||||
versionName = currentState.versionName,
|
||||
changeLog = currentState.changeLog,
|
||||
onDownloadClick = { component.downloadUpdate(currentState.url) }
|
||||
onDownloadClick = { component.downloadUpdate(currentState.url) },
|
||||
focusRequester = focusRequester
|
||||
)
|
||||
|
||||
is UpdateState.InstallPermissionRequired -> UpdatePermissionContent(
|
||||
onGrantClick = { component.requestPermission() }
|
||||
onGrantClick = { component.requestPermission() },
|
||||
focusRequester = focusRequester
|
||||
)
|
||||
|
||||
is UpdateState.Downloading -> UpdateDownloadingContent(
|
||||
@@ -77,12 +84,14 @@ fun UpdateDialog(
|
||||
)
|
||||
|
||||
is UpdateState.ReadyToInstall -> UpdateReadyContent(
|
||||
onInstallClick = { component.installApk(currentState.filePath) }
|
||||
onInstallClick = { component.installApk(currentState.filePath) },
|
||||
focusRequester = focusRequester
|
||||
)
|
||||
|
||||
is UpdateState.Error -> UpdateErrorContent(
|
||||
message = currentState.message,
|
||||
onRetryClick = { component.checkUpdates() }
|
||||
onRetryClick = { component.checkUpdates() },
|
||||
focusRequester = focusRequester
|
||||
)
|
||||
|
||||
is UpdateState.UpToDate -> {
|
||||
@@ -98,6 +107,10 @@ fun UpdateDialog(
|
||||
|
||||
else -> Unit
|
||||
}
|
||||
LaunchedEffect(state) {
|
||||
withFrameNanos {}
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -113,6 +126,7 @@ private fun UpdateAvailableContent(
|
||||
versionName: String,
|
||||
changeLog: String?,
|
||||
onDownloadClick: () -> Unit,
|
||||
focusRequester: FocusRequester,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
@@ -141,7 +155,10 @@ private fun UpdateAvailableContent(
|
||||
)
|
||||
}
|
||||
item {
|
||||
Button(onClick = onDownloadClick, modifier = Modifier.fillMaxWidth()) {
|
||||
Button(
|
||||
onClick = onDownloadClick,
|
||||
modifier = Modifier.focusRequester(focusRequester).fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
stringResource(Res.string.updater_btn_download),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
@@ -155,6 +172,7 @@ private fun UpdateAvailableContent(
|
||||
@Composable
|
||||
private fun UpdatePermissionContent(
|
||||
onGrantClick: () -> Unit,
|
||||
focusRequester: FocusRequester,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
@@ -170,7 +188,10 @@ private fun UpdatePermissionContent(
|
||||
text = stringResource(Res.string.updater_desc_permission),
|
||||
style = MaterialTheme.typography.bodyMedium
|
||||
)
|
||||
Button(onClick = onGrantClick, modifier = Modifier.fillMaxWidth()) {
|
||||
Button(
|
||||
onClick = onGrantClick,
|
||||
modifier = Modifier.focusRequester(focusRequester).fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
stringResource(Res.string.updater_btn_grant),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
@@ -215,6 +236,7 @@ private fun UpdateDownloadingContent(
|
||||
@Composable
|
||||
private fun UpdateReadyContent(
|
||||
onInstallClick: () -> Unit,
|
||||
focusRequester: FocusRequester,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
@@ -226,7 +248,10 @@ private fun UpdateReadyContent(
|
||||
text = stringResource(Res.string.updater_title_ready),
|
||||
style = MaterialTheme.typography.titleLarge
|
||||
)
|
||||
Button(onClick = onInstallClick, modifier = Modifier.fillMaxWidth()) {
|
||||
Button(
|
||||
onClick = onInstallClick,
|
||||
modifier = Modifier.focusRequester(focusRequester).fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
stringResource(Res.string.updater_btn_install),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
@@ -260,6 +285,7 @@ private fun UpdateFinishedContent(
|
||||
private fun UpdateErrorContent(
|
||||
message: String,
|
||||
onRetryClick: () -> Unit,
|
||||
focusRequester: FocusRequester,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
@@ -273,7 +299,10 @@ private fun UpdateErrorContent(
|
||||
color = MaterialTheme.colorScheme.error
|
||||
)
|
||||
Text(text = message, style = MaterialTheme.typography.bodyMedium)
|
||||
Button(onClick = onRetryClick, modifier = Modifier.fillMaxWidth()) {
|
||||
Button(
|
||||
onClick = onRetryClick,
|
||||
modifier = Modifier.focusRequester(focusRequester).fillMaxWidth()
|
||||
) {
|
||||
Text(
|
||||
stringResource(Res.string.updater_btn_retry),
|
||||
style = MaterialTheme.typography.labelLarge
|
||||
@@ -289,7 +318,8 @@ private fun UpdateAvailablePreview() {
|
||||
UpdateAvailableContent(
|
||||
versionName = "v1.4.0",
|
||||
changeLog = "- Добавили темную тему\n- Исправили падение на главном экране\n- Повысили стабильность",
|
||||
onDownloadClick = {}
|
||||
onDownloadClick = {},
|
||||
focusRequester = FocusRequester()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -310,7 +340,10 @@ private fun UpdateDownloadingPreview() {
|
||||
@Composable
|
||||
private fun UpdatePermissionPreview() {
|
||||
MaterialTheme {
|
||||
UpdatePermissionContent(onGrantClick = {})
|
||||
UpdatePermissionContent(
|
||||
onGrantClick = {},
|
||||
focusRequester = FocusRequester()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -318,6 +351,10 @@ private fun UpdatePermissionPreview() {
|
||||
@Composable
|
||||
private fun UpdateErrorPreview() {
|
||||
MaterialTheme {
|
||||
UpdateErrorContent(message = "Http status 503: Service Unavailable", onRetryClick = {})
|
||||
UpdateErrorContent(
|
||||
message = "Http status 503: Service Unavailable",
|
||||
onRetryClick = {},
|
||||
focusRequester = FocusRequester()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user