mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
Add dialog to backpress on create account flow
This commit is contained in:
parent
4660905c09
commit
39f9b959ce
@ -0,0 +1,31 @@
|
||||
package org.thoughtcrime.securesms.onboarding
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.ui.AlertDialog
|
||||
import org.thoughtcrime.securesms.ui.DialogButtonModel
|
||||
import org.thoughtcrime.securesms.ui.GetString
|
||||
import org.thoughtcrime.securesms.ui.color.LocalColors
|
||||
|
||||
@Composable
|
||||
fun OnboardingBackPressAlertDialog(
|
||||
dismissDialog: () -> Unit,
|
||||
quit: () -> Unit
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = dismissDialog,
|
||||
title = stringResource(R.string.warning),
|
||||
text = stringResource(R.string.you_cannot_go_back_further_in_order_to_stop_loading_your_account_session_needs_to_quit),
|
||||
buttons = listOf(
|
||||
DialogButtonModel(
|
||||
GetString(stringResource(R.string.quit)),
|
||||
color = LocalColors.current.danger,
|
||||
onClick = quit
|
||||
),
|
||||
DialogButtonModel(
|
||||
GetString(stringResource(R.string.cancel))
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
@ -19,6 +19,7 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.tooling.preview.PreviewParameter
|
||||
import androidx.compose.ui.unit.dp
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.onboarding.OnboardingBackPressAlertDialog
|
||||
import org.thoughtcrime.securesms.onboarding.messagenotifications.MessageNotificationsViewModel.UiState
|
||||
import org.thoughtcrime.securesms.onboarding.ui.ContinuePrimaryOutlineButton
|
||||
import org.thoughtcrime.securesms.ui.AlertDialog
|
||||
@ -57,21 +58,7 @@ internal fun MessageNotificationsScreen(
|
||||
return
|
||||
}
|
||||
|
||||
if (state.showDialog) AlertDialog(
|
||||
onDismissRequest = dismissDialog,
|
||||
title = stringResource(R.string.warning),
|
||||
text = stringResource(R.string.you_cannot_go_back_further_in_order_to_stop_loading_your_account_session_needs_to_quit),
|
||||
buttons = listOf(
|
||||
DialogButtonModel(
|
||||
GetString(stringResource(R.string.quit)),
|
||||
color = LocalColors.current.danger,
|
||||
onClick = quit
|
||||
),
|
||||
DialogButtonModel(
|
||||
GetString(stringResource(R.string.cancel))
|
||||
)
|
||||
)
|
||||
)
|
||||
if (state.showDialog) OnboardingBackPressAlertDialog(dismissDialog, quit)
|
||||
|
||||
Column {
|
||||
Spacer(Modifier.weight(1f))
|
||||
|
@ -15,6 +15,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import network.loki.messenger.R
|
||||
import org.thoughtcrime.securesms.onboarding.OnboardingBackPressAlertDialog
|
||||
import org.thoughtcrime.securesms.onboarding.ui.ContinuePrimaryOutlineButton
|
||||
import org.thoughtcrime.securesms.ui.LocalDimensions
|
||||
import org.thoughtcrime.securesms.ui.PreviewTheme
|
||||
@ -24,14 +25,23 @@ import org.thoughtcrime.securesms.ui.h4
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
private fun PreviewDisplayName() {
|
||||
private fun PreviewPickDisplayName() {
|
||||
PreviewTheme {
|
||||
DisplayName(State())
|
||||
PickDisplayName(State())
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun DisplayName(state: State, onChange: (String) -> Unit = {}, onContinue: () -> Unit = {}) {
|
||||
internal fun PickDisplayName(
|
||||
state: State,
|
||||
onChange: (String) -> Unit = {},
|
||||
onContinue: () -> Unit = {},
|
||||
dismissDialog: () -> Unit = {},
|
||||
quit: () -> Unit = {}
|
||||
) {
|
||||
|
||||
if (state.showDialog) OnboardingBackPressAlertDialog(dismissDialog, quit)
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
|
@ -53,8 +53,19 @@ class PickDisplayNameActivity : BaseActionBarActivity() {
|
||||
|
||||
@Composable
|
||||
private fun DisplayNameScreen(viewModel: PickDisplayNameViewModel) {
|
||||
val state = viewModel.states.collectAsState()
|
||||
DisplayName(state.value, viewModel::onChange) { viewModel.onContinue() }
|
||||
PickDisplayName(
|
||||
viewModel.states.collectAsState().value,
|
||||
viewModel::onChange,
|
||||
viewModel::onContinue,
|
||||
viewModel::dismissDialog
|
||||
) { viewModel.dismissDialog(); finish() }
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (viewModel.onBackPressed()) return
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,17 @@ import kotlinx.coroutines.launch
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.utilities.SSKEnvironment.ProfileManagerProtocol.Companion.NAME_PADDED_LENGTH
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.dependencies.ConfigFactory
|
||||
import org.thoughtcrime.securesms.onboarding.messagenotifications.MessageNotificationsViewModel
|
||||
|
||||
internal class PickDisplayNameViewModel(
|
||||
private val loadFailed: Boolean,
|
||||
private val prefs: TextSecurePreferences,
|
||||
private val configFactory: ConfigFactory
|
||||
): ViewModel() {
|
||||
private val isCreateAccount = !loadFailed
|
||||
|
||||
private val _states = MutableStateFlow(if (loadFailed) pickNewNameState() else State())
|
||||
val states = _states.asStateFlow()
|
||||
|
||||
@ -63,6 +67,17 @@ internal class PickDisplayNameViewModel(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return [true] if the back press was handled.
|
||||
*/
|
||||
fun onBackPressed(): Boolean = isCreateAccount.also {
|
||||
if (it) _states.update { it.copy(showDialog = true) }
|
||||
}
|
||||
|
||||
fun dismissDialog() {
|
||||
_states.update { it.copy(showDialog = false) }
|
||||
}
|
||||
|
||||
@dagger.assisted.AssistedFactory
|
||||
interface AssistedFactory {
|
||||
fun create(loadFailed: Boolean): Factory
|
||||
@ -84,6 +99,7 @@ internal class PickDisplayNameViewModel(
|
||||
data class State(
|
||||
@StringRes val title: Int = R.string.displayNamePick,
|
||||
@StringRes val description: Int = R.string.displayNameDescription,
|
||||
val showDialog: Boolean = false,
|
||||
val isTextErrorColor: Boolean = false,
|
||||
@StringRes val error: Int? = null,
|
||||
val displayName: String = ""
|
||||
|
Loading…
Reference in New Issue
Block a user