Skip to content
Snippets Groups Projects
Verified Commit 7c17054f authored by Torsten Grote's avatar Torsten Grote Committed by Sebastian
Browse files

Rename pairingState to pairingUiState

parent ec25bb0d
Branches
Tags
1 merge request!304Initial working Mailbox implementation
/* /*
* Briar Desktop * Briar Desktop
* Copyright (C) 2021-2022 The Briar Project * Copyright (C) 2021-2023 The Briar Project
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -36,7 +36,7 @@ import org.briarproject.briar.desktop.viewmodel.viewModel ...@@ -36,7 +36,7 @@ import org.briarproject.briar.desktop.viewmodel.viewModel
@Composable @Composable
fun MailboxScreen(viewModel: MailboxViewModel = viewModel()) { fun MailboxScreen(viewModel: MailboxViewModel = viewModel()) {
when (val state = viewModel.pairingState.value) { when (val state = viewModel.pairingUiState.value) {
Unknown -> Loader() Unknown -> Loader()
NotSetup -> MailboxSetupScreen(viewModel, false) NotSetup -> MailboxSetupScreen(viewModel, false)
is Pairing -> when (state.pairingState) { is Pairing -> when (state.pairingState) {
......
...@@ -48,7 +48,7 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n ...@@ -48,7 +48,7 @@ import org.briarproject.briar.desktop.utils.InternationalizationUtils.i18n
@Composable @Composable
fun MailboxSetupScreen(viewModel: MailboxViewModel, showError: Boolean) { fun MailboxSetupScreen(viewModel: MailboxViewModel, showError: Boolean) {
MailboxErrorDialog( MailboxErrorDialog(
state = viewModel.pairingState.value, state = viewModel.pairingUiState.value,
visible = showError, visible = showError,
) { ) {
viewModel.onPairingErrorSeen() viewModel.onPairingErrorSeen()
...@@ -99,7 +99,7 @@ fun MailboxSetupScreen(viewModel: MailboxViewModel, showError: Boolean) { ...@@ -99,7 +99,7 @@ fun MailboxSetupScreen(viewModel: MailboxViewModel, showError: Boolean) {
.fillMaxWidth() .fillMaxWidth()
.description(i18n("mailbox.setup.hint")), .description(i18n("mailbox.setup.hint")),
) )
if (viewModel.pairingState.value is NotSetup) Button( if (viewModel.pairingUiState.value is NotSetup) Button(
onClick = onOkButtonClicked, onClick = onOkButtonClicked,
modifier = Modifier.align(End) modifier = Modifier.align(End)
) { ) {
......
/* /*
* Briar Desktop * Briar Desktop
* Copyright (C) 2021-2022 The Briar Project * Copyright (C) 2021-2023 The Briar Project
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as * it under the terms of the GNU Affero General Public License as
...@@ -72,8 +72,8 @@ class MailboxViewModel @Inject constructor( ...@@ -72,8 +72,8 @@ class MailboxViewModel @Inject constructor(
private val LOG = KotlinLogging.logger {} private val LOG = KotlinLogging.logger {}
} }
private val _pairingState = mutableStateOf<MailboxPairingUiState>(Unknown) private val _pairingUiState = mutableStateOf<MailboxPairingUiState>(Unknown)
val pairingState = _pairingState.asState() val pairingUiState = _pairingUiState.asState()
private val _pairingLink = mutableStateOf("") private val _pairingLink = mutableStateOf("")
val pairingLink = _pairingLink.asState() val pairingLink = _pairingLink.asState()
private val _status = mutableStateOf<MailboxStatus?>(null) private val _status = mutableStateOf<MailboxStatus?>(null)
...@@ -94,11 +94,11 @@ class MailboxViewModel @Inject constructor( ...@@ -94,11 +94,11 @@ class MailboxViewModel @Inject constructor(
if (isPaired) { if (isPaired) {
val mailboxStatus = mailboxManager.getMailboxStatus(txn) val mailboxStatus = mailboxManager.getMailboxStatus(txn)
briarExecutors.onUiThread { briarExecutors.onUiThread {
_pairingState.value = IsPaired(connectionCheckRunning = false, isWiping = false) _pairingUiState.value = IsPaired(connectionCheckRunning = false, isWiping = false)
_status.value = mailboxStatus _status.value = mailboxStatus
} }
} else briarExecutors.onUiThread { } else briarExecutors.onUiThread {
_pairingState.value = NotSetup _pairingUiState.value = NotSetup
} }
} else { } else {
task.addObserver(this) task.addObserver(this)
...@@ -117,10 +117,10 @@ class MailboxViewModel @Inject constructor( ...@@ -117,10 +117,10 @@ class MailboxViewModel @Inject constructor(
@UiExecutor @UiExecutor
private fun onTorInactive() { private fun onTorInactive() {
val lastState = _pairingState.value val lastState = _pairingUiState.value
if (lastState is Pairing) { if (lastState is Pairing) {
// check that we not just finished pairing (showing success screen) // check that we not just finished pairing (showing success screen)
if (lastState.pairingState !is Paired) _pairingState.value = OfflineWhenPairing if (lastState.pairingState !is Paired) _pairingUiState.value = OfflineWhenPairing
// else ignore offline event as user will be leaving UI flow anyway // else ignore offline event as user will be leaving UI flow anyway
} }
} }
...@@ -128,7 +128,7 @@ class MailboxViewModel @Inject constructor( ...@@ -128,7 +128,7 @@ class MailboxViewModel @Inject constructor(
@UiExecutor @UiExecutor
override fun accept(t: MailboxPairingState) { override fun accept(t: MailboxPairingState) {
LOG.i { "New pairing state: ${t::class.simpleName}" } LOG.i { "New pairing state: ${t::class.simpleName}" }
_pairingState.value = Pairing(t) _pairingUiState.value = Pairing(t)
} }
private fun isTorActive(): Boolean { private fun isTorActive(): Boolean {
...@@ -149,26 +149,26 @@ class MailboxViewModel @Inject constructor( ...@@ -149,26 +149,26 @@ class MailboxViewModel @Inject constructor(
it.addObserver(this) it.addObserver(this)
} }
} else { } else {
_pairingState.value = OfflineWhenPairing _pairingUiState.value = OfflineWhenPairing
} }
} }
@UiExecutor @UiExecutor
fun onPairingErrorSeen() { fun onPairingErrorSeen() {
_pairingState.value = NotSetup _pairingUiState.value = NotSetup
} }
@UiExecutor @UiExecutor
fun checkConnection() { fun checkConnection() {
// we can only check the connection when we are already paired (or just finished pairing) // we can only check the connection when we are already paired (or just finished pairing)
_pairingState.value = IsPaired(connectionCheckRunning = true, isWiping = false) _pairingUiState.value = IsPaired(connectionCheckRunning = true, isWiping = false)
briarExecutors.onIoThread { briarExecutors.onIoThread {
// this check updates _status state via an Event // this check updates _status state via an Event
val success = mailboxManager.checkConnection() val success = mailboxManager.checkConnection()
LOG.i { "Got result from connection check: $success" } LOG.i { "Got result from connection check: $success" }
briarExecutors.onUiThread { briarExecutors.onUiThread {
val s = pairingState.value val s = pairingUiState.value
if (s is IsPaired) _pairingState.value = IsPaired(connectionCheckRunning = false, isWiping = false) if (s is IsPaired) _pairingUiState.value = IsPaired(connectionCheckRunning = false, isWiping = false)
else LOG.w { "Unexpected state: ${s::class.simpleName}" } else LOG.w { "Unexpected state: ${s::class.simpleName}" }
} }
} }
...@@ -176,11 +176,11 @@ class MailboxViewModel @Inject constructor( ...@@ -176,11 +176,11 @@ class MailboxViewModel @Inject constructor(
@UiExecutor @UiExecutor
fun unlink() { fun unlink() {
_pairingState.value = IsPaired(connectionCheckRunning = false, isWiping = true) _pairingUiState.value = IsPaired(connectionCheckRunning = false, isWiping = true)
briarExecutors.onIoThread { briarExecutors.onIoThread {
val wasWiped = mailboxManager.unPair() val wasWiped = mailboxManager.unPair()
briarExecutors.onUiThread { briarExecutors.onUiThread {
_pairingState.value = WasUnpaired(!wasWiped) _pairingUiState.value = WasUnpaired(!wasWiped)
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment