Commit 6d2ef98d authored by Mikolai Gütschow's avatar Mikolai Gütschow Committed by Nico
Browse files

let users see about dialog from startup and error screen

parent 823f55ff
Pipeline #9397 passed with stage
in 3 minutes and 27 seconds
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.briarproject.briar.desktop.login package org.briarproject.briar.desktop.login
import androidx.compose.foundation.layout.Arrangement.spacedBy import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
...@@ -34,11 +35,13 @@ import androidx.compose.material.Text ...@@ -34,11 +35,13 @@ import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Error import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Info
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue 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.setValue import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
...@@ -69,16 +72,19 @@ fun main() = preview { ...@@ -69,16 +72,19 @@ fun main() = preview {
} }
} }
ErrorScreen(error) {} ErrorScreen(error, {}) {}
} }
@Composable @Composable
fun ErrorScreen(viewHolder: ErrorSubViewModel) = fun ErrorScreen(
ErrorScreen(viewHolder.error, viewHolder.onBackButton) onShowAbout: () -> Unit,
viewHolder: ErrorSubViewModel
) = ErrorScreen(viewHolder.error, onShowAbout, viewHolder.onBackButton)
@Composable @Composable
fun ErrorScreen( fun ErrorScreen(
error: ErrorSubViewModel.Error, error: ErrorSubViewModel.Error,
onShowAbout: () -> Unit,
onBackButton: (() -> Unit)?, onBackButton: (() -> Unit)?,
) { ) {
val text = when (error) { val text = when (error) {
...@@ -95,37 +101,47 @@ fun ErrorScreen( ...@@ -95,37 +101,47 @@ fun ErrorScreen(
} }
} }
ErrorScreen(text, onBackButton) ErrorScreen(text, onShowAbout, onBackButton)
} }
@Composable @Composable
fun ErrorScreen( fun ErrorScreen(
text: String, text: String,
onShowAbout: () -> Unit,
onBackButton: (() -> Unit)? = null, onBackButton: (() -> Unit)? = null,
) = Surface { ) = Surface {
if (onBackButton != null) { Box {
IconButton(onClick = onBackButton) { Column(
Icon(Icons.Filled.ArrowBack, i18n("back")) modifier = Modifier.fillMaxSize().padding(32.dp),
horizontalAlignment = CenterHorizontally,
verticalArrangement = spacedBy(32.dp)
) {
Icon(
imageVector = Icons.Filled.Error,
contentDescription = i18n("error"),
modifier = Modifier.size(128.dp),
tint = Red500
)
Text(i18n("sorry"), style = MaterialTheme.typography.h5)
Text(
text = text,
style = MaterialTheme.typography.body1,
modifier = Modifier.widthIn(max = STARTUP_FIELDS_WIDTH)
)
} }
}
Column( if (onBackButton != null) {
modifier = Modifier.fillMaxSize().padding(32.dp), IconButton(onClick = onBackButton) {
horizontalAlignment = CenterHorizontally, Icon(Icons.Filled.ArrowBack, i18n("back"))
verticalArrangement = spacedBy(32.dp) }
) { }
Icon(
imageVector = Icons.Filled.Error,
contentDescription = i18n("error"),
modifier = Modifier.size(128.dp),
tint = Red500
)
Text(i18n("sorry"), style = MaterialTheme.typography.h5) IconButton(
Text( onClick = onShowAbout,
text = text, modifier = Modifier.align(Alignment.BottomStart)
style = MaterialTheme.typography.body1, ) {
modifier = Modifier.widthIn(max = STARTUP_FIELDS_WIDTH) Icon(Icons.Filled.Info, i18n("access.about_briar_desktop"))
) }
} }
} }
...@@ -47,8 +47,12 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n ...@@ -47,8 +47,12 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
fun LoginScreen( fun LoginScreen(
onShowAbout: () -> Unit,
viewHolder: LoginSubViewModel, viewHolder: LoginSubViewModel,
) = StartupScreenScaffold(i18n("startup.title.login")) { ) = StartupScreenScaffold(
title = i18n("startup.title.login"),
onShowAbout = onShowAbout,
) {
when (viewHolder.state.value) { when (viewHolder.state.value) {
SIGNED_OUT -> SIGNED_OUT ->
FormScaffold( FormScaffold(
......
...@@ -47,9 +47,11 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n ...@@ -47,9 +47,11 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
@Composable @Composable
fun RegistrationScreen( fun RegistrationScreen(
onShowAbout: () -> Unit,
viewHolder: RegistrationSubViewModel, viewHolder: RegistrationSubViewModel,
) = StartupScreenScaffold( ) = StartupScreenScaffold(
title = i18n("startup.title.registration"), title = i18n("startup.title.registration"),
onShowAbout = onShowAbout,
showBackButton = viewHolder.showBackButton.value, showBackButton = viewHolder.showBackButton.value,
onBackButton = viewHolder::goBack onBackButton = viewHolder::goBack
) { ) {
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package org.briarproject.briar.desktop.login package org.briarproject.briar.desktop.login
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
...@@ -31,7 +32,9 @@ import androidx.compose.material.Surface ...@@ -31,7 +32,9 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Info
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Alignment.Companion.CenterVertically import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
...@@ -42,12 +45,13 @@ import org.briarproject.briar.desktop.viewmodel.viewModel ...@@ -42,12 +45,13 @@ import org.briarproject.briar.desktop.viewmodel.viewModel
@Composable @Composable
fun StartupScreen( fun StartupScreen(
onShowAbout: () -> Unit,
viewModel: StartupViewModel = viewModel(), viewModel: StartupViewModel = viewModel(),
) { ) {
when (val holder = viewModel.currentSubViewModel.value) { when (val holder = viewModel.currentSubViewModel.value) {
is LoginSubViewModel -> LoginScreen(holder) is LoginSubViewModel -> LoginScreen(onShowAbout, holder)
is RegistrationSubViewModel -> RegistrationScreen(holder) is RegistrationSubViewModel -> RegistrationScreen(onShowAbout, holder)
is ErrorSubViewModel -> ErrorScreen(holder) is ErrorSubViewModel -> ErrorScreen(onShowAbout, holder)
} }
} }
...@@ -56,20 +60,33 @@ fun StartupScreenScaffold( ...@@ -56,20 +60,33 @@ fun StartupScreenScaffold(
title: String, title: String,
showBackButton: Boolean = false, showBackButton: Boolean = false,
onBackButton: () -> Unit = {}, onBackButton: () -> Unit = {},
onShowAbout: () -> Unit = {},
content: @Composable () -> Unit content: @Composable () -> Unit
) = Surface { ) = Surface {
if (showBackButton) { Box {
IconButton(onClick = onBackButton) { Column(
Icon(Icons.Filled.ArrowBack, i18n("back")) modifier = Modifier.padding(16.dp).fillMaxSize(),
horizontalAlignment = CenterHorizontally
) {
HeaderLine(title)
content()
} }
}
Column( if (showBackButton) {
modifier = Modifier.padding(16.dp).fillMaxSize(), IconButton(
horizontalAlignment = CenterHorizontally onClick = onBackButton,
) { modifier = Modifier.align(Alignment.TopStart)
HeaderLine(title) ) {
content() Icon(Icons.Filled.ArrowBack, i18n("back"))
}
}
IconButton(
onClick = onShowAbout,
modifier = Modifier.align(Alignment.BottomStart)
) {
Icon(Icons.Filled.Info, i18n("access.about_briar_desktop"))
}
} }
} }
......
...@@ -126,9 +126,9 @@ constructor( ...@@ -126,9 +126,9 @@ constructor(
Column(Modifier.fillMaxSize()) { Column(Modifier.fillMaxSize()) {
ExpirationBanner { screenState = EXPIRED; stop() } ExpirationBanner { screenState = EXPIRED; stop() }
when (screenState) { when (screenState) {
STARTUP -> StartupScreen() STARTUP -> StartupScreen(onShowAbout = { showAbout = true })
MAIN -> MainScreen(settingsViewModel, showAbout = { showAbout = true }) MAIN -> MainScreen(settingsViewModel, showAbout = { showAbout = true })
EXPIRED -> ErrorScreen(i18n("startup.failed.expired")) EXPIRED -> ErrorScreen(i18n("startup.failed.expired"), onShowAbout = { showAbout = true })
} }
} }
if (showAbout) { if (showAbout) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment