From 306b02137d0eda0ab31dd0c217c42b36d9f33edf Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 21 Apr 2025 17:05:43 -0300 Subject: [PATCH] Only show the orbot/tor option in the signup page once --- .../nostrsigner/ui/AccountStateViewModel.kt | 32 +- .../greenart7c3/nostrsigner/ui/LoginScreen.kt | 294 +++++++++--------- 2 files changed, 168 insertions(+), 158 deletions(-) diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/AccountStateViewModel.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/AccountStateViewModel.kt index 8045bf45..f10309d8 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/AccountStateViewModel.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/AccountStateViewModel.kt @@ -232,13 +232,15 @@ class AccountStateViewModel(npub: String?) : ViewModel() { didBackup = true, ) } - NostrSigner.instance.settings = NostrSigner.instance.settings.copy( - useProxy = useProxy, - proxyPort = proxyPort, - ) - LocalPreferences.saveSettingsToEncryptedStorage( - NostrSigner.instance.settings, - ) + if (LocalPreferences.allSavedAccounts(NostrSigner.instance).isEmpty()) { + NostrSigner.instance.settings = NostrSigner.instance.settings.copy( + useProxy = useProxy, + proxyPort = proxyPort, + ) + LocalPreferences.saveSettingsToEncryptedStorage( + NostrSigner.instance.settings, + ) + } LocalPreferences.updatePrefsForLogin(NostrSigner.instance, account) startUI(account, route) } @@ -261,14 +263,16 @@ class AccountStateViewModel(npub: String?) : ViewModel() { seedWords = seedWords, didBackup = false, ) + if (LocalPreferences.allSavedAccounts(NostrSigner.instance).isEmpty()) { + NostrSigner.instance.settings = NostrSigner.instance.settings.copy( + useProxy = useProxy, + proxyPort = proxyPort, + ) + LocalPreferences.saveSettingsToEncryptedStorage( + NostrSigner.instance.settings, + ) + } LocalPreferences.updatePrefsForLogin(NostrSigner.instance, account) - NostrSigner.instance.settings = NostrSigner.instance.settings.copy( - useProxy = useProxy, - proxyPort = proxyPort, - ) - LocalPreferences.saveSettingsToEncryptedStorage( - NostrSigner.instance.settings, - ) startUI(account, null) } diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/ui/LoginScreen.kt b/app/src/main/java/com/greenart7c3/nostrsigner/ui/LoginScreen.kt index 63265b88..11bb412d 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/ui/LoginScreen.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/ui/LoginScreen.kt @@ -92,6 +92,7 @@ import androidx.navigation.NavController import androidx.navigation.NavHostController import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable +import com.greenart7c3.nostrsigner.LocalPreferences import com.greenart7c3.nostrsigner.R import com.greenart7c3.nostrsigner.ui.components.AmberButton import com.greenart7c3.nostrsigner.ui.components.AmberElevatedButton @@ -496,83 +497,86 @@ fun SignUpPage( } } } - Row( - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .padding(vertical = 20.dp) - .clickable { - useProxy = !useProxy - }, - ) { - Switch( - modifier = Modifier.scale(0.85f), - checked = useProxy, - onCheckedChange = { - useProxy = it - }, - ) - Text( + + if (LocalPreferences.allSavedAccounts(context).isEmpty()) { + Row( + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, modifier = Modifier - .weight(1f) - .padding(start = 8.dp), - text = stringResource(R.string.connect_through_your_orbot_setup), - ) - } - - if (useProxy) { - val myMarkDownStyle = - RichTextDefaults.copy( - stringStyle = RichTextDefaults.stringStyle?.copy( - linkStyle = - SpanStyle( - textDecoration = TextDecoration.Underline, - color = MaterialTheme.colorScheme.primary, - ), - ), - ) - val content1 = stringResource(R.string.connect_through_your_orbot_setup_markdown2) - - val astNode1 = - remember { - CommonmarkAstNodeParser(MarkdownParseOptions.MarkdownWithLinks).parse(content1) - } - - RichText( - modifier = Modifier.padding(vertical = 8.dp), - style = myMarkDownStyle, - renderer = null, + .padding(vertical = 20.dp) + .clickable { + useProxy = !useProxy + }, ) { - BasicMarkdown(astNode1) + Switch( + modifier = Modifier.scale(0.85f), + checked = useProxy, + onCheckedChange = { + useProxy = it + }, + ) + Text( + modifier = Modifier + .weight(1f) + .padding(start = 8.dp), + text = stringResource(R.string.connect_through_your_orbot_setup), + ) } - OutlinedTextField( - value = proxyPort, - onValueChange = { value -> - proxyPort = value - }, - label = { - Text( - text = stringResource(R.string.orbot_socks_port), - color = TextFieldDefaults.colors().unfocusedPlaceholderColor, + if (useProxy) { + val myMarkDownStyle = + RichTextDefaults.copy( + stringStyle = RichTextDefaults.stringStyle?.copy( + linkStyle = + SpanStyle( + textDecoration = TextDecoration.Underline, + color = MaterialTheme.colorScheme.primary, + ), + ), ) - }, - placeholder = { - Text( - stringResource(R.string.orbot_socks_port), - color = TextFieldDefaults.colors().unfocusedPlaceholderColor, - ) - }, - keyboardOptions = KeyboardOptions( - capitalization = KeyboardCapitalization.None, - autoCorrectEnabled = false, - imeAction = ImeAction.Next, - keyboardType = KeyboardType.Number, - ), - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 20.dp), - ) + val content1 = stringResource(R.string.connect_through_your_orbot_setup_markdown2) + + val astNode1 = + remember { + CommonmarkAstNodeParser(MarkdownParseOptions.MarkdownWithLinks).parse(content1) + } + + RichText( + modifier = Modifier.padding(vertical = 8.dp), + style = myMarkDownStyle, + renderer = null, + ) { + BasicMarkdown(astNode1) + } + + OutlinedTextField( + value = proxyPort, + onValueChange = { value -> + proxyPort = value + }, + label = { + Text( + text = stringResource(R.string.orbot_socks_port), + color = TextFieldDefaults.colors().unfocusedPlaceholderColor, + ) + }, + placeholder = { + Text( + stringResource(R.string.orbot_socks_port), + color = TextFieldDefaults.colors().unfocusedPlaceholderColor, + ) + }, + keyboardOptions = KeyboardOptions( + capitalization = KeyboardCapitalization.None, + autoCorrectEnabled = false, + imeAction = ImeAction.Next, + keyboardType = KeyboardType.Number, + ), + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 20.dp), + ) + } } AmberButton( modifier = Modifier @@ -988,83 +992,85 @@ fun LoginPage( } } } - Row( - horizontalArrangement = Arrangement.SpaceBetween, - verticalAlignment = Alignment.CenterVertically, - modifier = Modifier - .padding(vertical = 20.dp) - .clickable { - useProxy = !useProxy - }, - ) { - Switch( - modifier = Modifier.scale(0.85f), - checked = useProxy, - onCheckedChange = { - useProxy = it - }, - ) - Text( + if (LocalPreferences.allSavedAccounts(context).isEmpty()) { + Row( + horizontalArrangement = Arrangement.SpaceBetween, + verticalAlignment = Alignment.CenterVertically, modifier = Modifier - .weight(1f) - .padding(start = 8.dp), - text = stringResource(R.string.connect_through_your_orbot_setup), - ) - } - - if (useProxy) { - val myMarkDownStyle = - RichTextDefaults.copy( - stringStyle = RichTextDefaults.stringStyle?.copy( - linkStyle = - SpanStyle( - textDecoration = TextDecoration.Underline, - color = MaterialTheme.colorScheme.primary, - ), - ), - ) - val content1 = stringResource(R.string.connect_through_your_orbot_setup_markdown2) - - val astNode1 = - remember { - CommonmarkAstNodeParser(MarkdownParseOptions.MarkdownWithLinks).parse(content1) - } - - RichText( - modifier = Modifier.padding(vertical = 8.dp), - style = myMarkDownStyle, - renderer = null, + .padding(vertical = 20.dp) + .clickable { + useProxy = !useProxy + }, ) { - BasicMarkdown(astNode1) + Switch( + modifier = Modifier.scale(0.85f), + checked = useProxy, + onCheckedChange = { + useProxy = it + }, + ) + Text( + modifier = Modifier + .weight(1f) + .padding(start = 8.dp), + text = stringResource(R.string.connect_through_your_orbot_setup), + ) } - OutlinedTextField( - value = proxyPort, - onValueChange = { value -> - proxyPort = value - }, - label = { - Text( - text = stringResource(R.string.orbot_socks_port), - color = TextFieldDefaults.colors().unfocusedPlaceholderColor, + if (useProxy) { + val myMarkDownStyle = + RichTextDefaults.copy( + stringStyle = RichTextDefaults.stringStyle?.copy( + linkStyle = + SpanStyle( + textDecoration = TextDecoration.Underline, + color = MaterialTheme.colorScheme.primary, + ), + ), ) - }, - placeholder = { - Text( - stringResource(R.string.orbot_socks_port), - color = TextFieldDefaults.colors().unfocusedPlaceholderColor, - ) - }, - keyboardOptions = KeyboardOptions( - capitalization = KeyboardCapitalization.None, - autoCorrectEnabled = false, - imeAction = ImeAction.Next, - keyboardType = KeyboardType.Number, - ), - modifier = Modifier - .fillMaxWidth() - .padding(bottom = 20.dp), - ) + val content1 = stringResource(R.string.connect_through_your_orbot_setup_markdown2) + + val astNode1 = + remember { + CommonmarkAstNodeParser(MarkdownParseOptions.MarkdownWithLinks).parse(content1) + } + + RichText( + modifier = Modifier.padding(vertical = 8.dp), + style = myMarkDownStyle, + renderer = null, + ) { + BasicMarkdown(astNode1) + } + + OutlinedTextField( + value = proxyPort, + onValueChange = { value -> + proxyPort = value + }, + label = { + Text( + text = stringResource(R.string.orbot_socks_port), + color = TextFieldDefaults.colors().unfocusedPlaceholderColor, + ) + }, + placeholder = { + Text( + stringResource(R.string.orbot_socks_port), + color = TextFieldDefaults.colors().unfocusedPlaceholderColor, + ) + }, + keyboardOptions = KeyboardOptions( + capitalization = KeyboardCapitalization.None, + autoCorrectEnabled = false, + imeAction = ImeAction.Next, + keyboardType = KeyboardType.Number, + ), + modifier = Modifier + .fillMaxWidth() + .padding(bottom = 20.dp), + ) + } } AmberButton( modifier = Modifier