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 @@
package org.briarproject.briar.desktop.login
import androidx.compose.foundation.layout.Arrangement.spacedBy
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
......@@ -34,11 +35,13 @@ import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Error
import androidx.compose.material.icons.filled.Info
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
......@@ -69,16 +72,19 @@ fun main() = preview {
}
}
ErrorScreen(error) {}
ErrorScreen(error, {}) {}
}
@Composable
fun ErrorScreen(viewHolder: ErrorSubViewModel) =
ErrorScreen(viewHolder.error, viewHolder.onBackButton)
fun ErrorScreen(
onShowAbout: () -> Unit,
viewHolder: ErrorSubViewModel
) = ErrorScreen(viewHolder.error, onShowAbout, viewHolder.onBackButton)
@Composable
fun ErrorScreen(
error: ErrorSubViewModel.Error,
onShowAbout: () -> Unit,
onBackButton: (() -> Unit)?,
) {
val text = when (error) {
......@@ -95,20 +101,16 @@ fun ErrorScreen(
}
}
ErrorScreen(text, onBackButton)
ErrorScreen(text, onShowAbout, onBackButton)
}
@Composable
fun ErrorScreen(
text: String,
onShowAbout: () -> Unit,
onBackButton: (() -> Unit)? = null,
) = Surface {
if (onBackButton != null) {
IconButton(onClick = onBackButton) {
Icon(Icons.Filled.ArrowBack, i18n("back"))
}
}
Box {
Column(
modifier = Modifier.fillMaxSize().padding(32.dp),
horizontalAlignment = CenterHorizontally,
......@@ -128,4 +130,18 @@ fun ErrorScreen(
modifier = Modifier.widthIn(max = STARTUP_FIELDS_WIDTH)
)
}
if (onBackButton != null) {
IconButton(onClick = onBackButton) {
Icon(Icons.Filled.ArrowBack, i18n("back"))
}
}
IconButton(
onClick = onShowAbout,
modifier = Modifier.align(Alignment.BottomStart)
) {
Icon(Icons.Filled.Info, i18n("access.about_briar_desktop"))
}
}
}
......@@ -47,8 +47,12 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
@OptIn(ExperimentalMaterialApi::class)
@Composable
fun LoginScreen(
onShowAbout: () -> Unit,
viewHolder: LoginSubViewModel,
) = StartupScreenScaffold(i18n("startup.title.login")) {
) = StartupScreenScaffold(
title = i18n("startup.title.login"),
onShowAbout = onShowAbout,
) {
when (viewHolder.state.value) {
SIGNED_OUT ->
FormScaffold(
......
......@@ -47,9 +47,11 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
@Composable
fun RegistrationScreen(
onShowAbout: () -> Unit,
viewHolder: RegistrationSubViewModel,
) = StartupScreenScaffold(
title = i18n("startup.title.registration"),
onShowAbout = onShowAbout,
showBackButton = viewHolder.showBackButton.value,
onBackButton = viewHolder::goBack
) {
......
......@@ -19,6 +19,7 @@
package org.briarproject.briar.desktop.login
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
......@@ -31,7 +32,9 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Info
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Alignment.Companion.CenterHorizontally
import androidx.compose.ui.Alignment.Companion.CenterVertically
import androidx.compose.ui.Modifier
......@@ -42,12 +45,13 @@ import org.briarproject.briar.desktop.viewmodel.viewModel
@Composable
fun StartupScreen(
onShowAbout: () -> Unit,
viewModel: StartupViewModel = viewModel(),
) {
when (val holder = viewModel.currentSubViewModel.value) {
is LoginSubViewModel -> LoginScreen(holder)
is RegistrationSubViewModel -> RegistrationScreen(holder)
is ErrorSubViewModel -> ErrorScreen(holder)
is LoginSubViewModel -> LoginScreen(onShowAbout, holder)
is RegistrationSubViewModel -> RegistrationScreen(onShowAbout, holder)
is ErrorSubViewModel -> ErrorScreen(onShowAbout, holder)
}
}
......@@ -56,14 +60,10 @@ fun StartupScreenScaffold(
title: String,
showBackButton: Boolean = false,
onBackButton: () -> Unit = {},
onShowAbout: () -> Unit = {},
content: @Composable () -> Unit
) = Surface {
if (showBackButton) {
IconButton(onClick = onBackButton) {
Icon(Icons.Filled.ArrowBack, i18n("back"))
}
}
Box {
Column(
modifier = Modifier.padding(16.dp).fillMaxSize(),
horizontalAlignment = CenterHorizontally
......@@ -71,6 +71,23 @@ fun StartupScreenScaffold(
HeaderLine(title)
content()
}
if (showBackButton) {
IconButton(
onClick = onBackButton,
modifier = Modifier.align(Alignment.TopStart)
) {
Icon(Icons.Filled.ArrowBack, i18n("back"))
}
}
IconButton(
onClick = onShowAbout,
modifier = Modifier.align(Alignment.BottomStart)
) {
Icon(Icons.Filled.Info, i18n("access.about_briar_desktop"))
}
}
}
@Composable
......
......@@ -126,9 +126,9 @@ constructor(
Column(Modifier.fillMaxSize()) {
ExpirationBanner { screenState = EXPIRED; stop() }
when (screenState) {
STARTUP -> StartupScreen()
STARTUP -> StartupScreen(onShowAbout = { 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) {
......
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