Adjustments to Tor/Orbot screens

This commit is contained in:
Vitor Pamplona 2023-05-11 09:18:17 -04:00
parent 875eb0df78
commit eb9be2108d
4 changed files with 112 additions and 61 deletions

View File

@ -14,7 +14,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.AlertDialog
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
@ -240,11 +242,11 @@ fun ListContent(
val coroutineScope = rememberCoroutineScope()
var backupDialogOpen by remember { mutableStateOf(false) }
var checked by remember { mutableStateOf(account.proxy != null) }
val openDialog = remember { mutableStateOf(false) }
var disconnectTorDialog by remember { mutableStateOf(false) }
var conectOrbotDialogOpen by remember { mutableStateOf(false) }
var proxyPort = remember { mutableStateOf(account.proxyPort.toString()) }
Column(modifier = modifier.fillMaxHeight()) {
Column(modifier = modifier.fillMaxHeight().verticalScroll(rememberScrollState())) {
if (accountUser != null) {
NavigationRow(
title = stringResource(R.string.profile),
@ -278,10 +280,15 @@ fun ListContent(
title = stringResource(R.string.backup_keys),
icon = R.drawable.ic_key,
tint = MaterialTheme.colors.onBackground,
onClick = { backupDialogOpen = true }
onClick = {
coroutineScope.launch {
scaffoldState.drawerState.close()
}
backupDialogOpen = true
}
)
val textTorProxy = if (checked) stringResource(R.string.disconnect_from_your_orbot_setup) else stringResource(R.string.connect_via_tor)
val textTorProxy = if (checked) stringResource(R.string.disconnect_from_your_orbot_setup) else stringResource(R.string.connect_via_tor_short)
IconRow(
title = textTorProxy,
@ -289,8 +296,11 @@ fun ListContent(
tint = MaterialTheme.colors.onBackground,
onClick = {
if (checked) {
openDialog.value = true
disconnectTorDialog = true
} else {
coroutineScope.launch {
scaffoldState.drawerState.close()
}
conectOrbotDialogOpen = true
}
}
@ -315,7 +325,7 @@ fun ListContent(
onClose = { conectOrbotDialogOpen = false },
onPost = {
conectOrbotDialogOpen = false
openDialog.value = false
disconnectTorDialog = false
checked = true
enableTor(account, true, proxyPort)
},
@ -323,14 +333,21 @@ fun ListContent(
)
}
if (openDialog.value) {
if (disconnectTorDialog) {
AlertDialog(
text = { Text(text = stringResource(R.string.do_you_really_want_to_disable_tor)) },
onDismissRequest = { },
title = {
Text(text = stringResource(R.string.do_you_really_want_to_disable_tor_title))
},
text = {
Text(text = stringResource(R.string.do_you_really_want_to_disable_tor_text))
},
onDismissRequest = {
disconnectTorDialog = false
},
confirmButton = {
TextButton(
onClick = {
openDialog.value = false
disconnectTorDialog = false
checked = false
enableTor(account, false, proxyPort)
}
@ -341,7 +358,7 @@ fun ListContent(
dismissButton = {
TextButton(
onClick = {
openDialog.value = false
disconnectTorDialog = false
}
) {
Text(text = stringResource(R.string.no))

View File

@ -354,9 +354,7 @@ private fun QuickActionAlertDialog(
},
buttons = {
Row(
modifier = Modifier
.padding(all = 8.dp)
.fillMaxWidth(),
modifier = Modifier.padding(all = 8.dp).fillMaxWidth(),
horizontalArrangement = Arrangement.SpaceBetween
) {
TextButton(onClick = onClickDontShowAgain) {

View File

@ -1,16 +1,17 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Surface
@ -20,20 +21,21 @@ import androidx.compose.runtime.MutableState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import androidx.compose.ui.window.DialogProperties
import com.halilibo.richtext.markdown.Markdown
import com.halilibo.richtext.ui.RichTextStyle
import com.halilibo.richtext.ui.material.MaterialRichText
import com.halilibo.richtext.ui.resolveDefaults
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.actions.CloseButton
import com.vitorpamplona.amethyst.ui.actions.PostButton
import com.vitorpamplona.amethyst.ui.components.richTextDefaults
import kotlinx.coroutines.launch
@Composable
@ -42,14 +44,11 @@ fun ConnectOrbotDialog(onClose: () -> Unit, onPost: () -> Unit, portNumber: Muta
val scope = rememberCoroutineScope()
Dialog(
onDismissRequest = onClose,
properties = DialogProperties(usePlatformDefaultWidth = false)
properties = DialogProperties(usePlatformDefaultWidth = false, decorFitsSystemWindows = false)
) {
Surface(modifier = Modifier.fillMaxSize()) {
Surface() {
Column(
modifier = Modifier
.padding(10.dp)
.background(MaterialTheme.colors.background)
.fillMaxSize()
modifier = Modifier.padding(10.dp)
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
@ -62,7 +61,7 @@ fun ConnectOrbotDialog(onClose: () -> Unit, onPost: () -> Unit, portNumber: Muta
val toastMessage = stringResource(R.string.invalid_port_number)
PostButton(
UseOrbotButton(
onPost = {
try {
Integer.parseInt(portNumber.value)
@ -74,7 +73,7 @@ fun ConnectOrbotDialog(onClose: () -> Unit, onPost: () -> Unit, portNumber: Muta
Toast.LENGTH_LONG
).show()
}
return@PostButton
return@UseOrbotButton
}
onPost()
@ -84,37 +83,70 @@ fun ConnectOrbotDialog(onClose: () -> Unit, onPost: () -> Unit, portNumber: Muta
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 30.dp)
modifier = Modifier.padding(30.dp)
) {
MaterialRichText(
style = RichTextStyle().resolveDefaults()
) {
Markdown(
content = stringResource(R.string.connect_through_your_orbot_setup_markdown)
val myMarkDownStyle = richTextDefaults.copy(
stringStyle = richTextDefaults.stringStyle?.copy(
linkStyle = SpanStyle(
textDecoration = TextDecoration.Underline,
color = MaterialTheme.colors.primary
)
)
}
)
Spacer(modifier = Modifier.height(10.dp))
OutlinedTextField(
value = portNumber.value,
onValueChange = { portNumber.value = it },
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.None,
keyboardType = KeyboardType.Number
),
label = { Text(text = stringResource(R.string.orbot_socks_port)) },
placeholder = {
Text(
text = "9050",
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
Row() {
MaterialRichText(
style = myMarkDownStyle
) {
Markdown(
content = stringResource(R.string.connect_through_your_orbot_setup_markdown)
)
}
)
}
Spacer(modifier = Modifier.height(15.dp))
Row(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center
) {
OutlinedTextField(
value = portNumber.value,
onValueChange = { portNumber.value = it },
keyboardOptions = KeyboardOptions.Default.copy(
capitalization = KeyboardCapitalization.None,
keyboardType = KeyboardType.Number
),
label = { Text(text = stringResource(R.string.orbot_socks_port)) },
placeholder = {
Text(
text = "9050",
color = MaterialTheme.colors.onSurface.copy(alpha = 0.32f)
)
}
)
}
}
}
}
}
}
@Composable
fun UseOrbotButton(onPost: () -> Unit = {}, isActive: Boolean, modifier: Modifier = Modifier) {
Button(
modifier = modifier,
onClick = {
if (isActive) {
onPost()
}
},
shape = RoundedCornerShape(20.dp),
colors = ButtonDefaults
.buttonColors(
backgroundColor = if (isActive) MaterialTheme.colors.primary else Color.Gray
)
) {
Text(text = stringResource(R.string.use_orbot), color = Color.White)
}
}

View File

@ -296,12 +296,6 @@
<string name="poll_author_no_vote">Poll authors can\'t vote in their own polls.</string>
<string name="poll_hashtag" translatable="false">#zappoll</string>
<string name="connect_via_tor">Connect through your Orbot setup</string>
<string name="do_you_really_want_to_disable_tor">Do you really want to disconnect from your Orbot setup?</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="disconnect_from_your_orbot_setup">Disconnect from your Orbot setup</string>
<string name="hash_verification_passed">Image is the same since the post</string>
<string name="hash_verification_failed">Image has changed. The author might not have seen the change</string>
@ -361,21 +355,31 @@
<string name="upload_server_relays_nip95">Your relays (NIP-95)</string>
<string name="upload_server_relays_nip95_explainer">Files are hosted by your relays. New NIP: check if they support</string>
<string name="connect_via_tor_short">Tor/Orbot setup</string>
<string name="connect_via_tor">Connect through your Orbot setup</string>
<string name="do_you_really_want_to_disable_tor_title">Disconnect from your Orbot/Tor?</string>
<string name="do_you_really_want_to_disable_tor_text">Your data will be immediately transferred in the regular network</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="follow_list_selection">Follow List</string>
<string name="follow_list_kind3follows">All Follows</string>
<string name="follow_list_global">Global</string>
<string name="connect_through_your_orbot_setup_markdown">
## Connect through your Orbot setup
## Connect through Tor with Orbot
\n\n1. Install [Orbot](https://play.google.com/store/apps/details?id=org.torproject.android)
\n2. Start Orbot
\n3. In Orbot check the Socks port. By default it uses the port 9050
\n4. If necessary change the port
\n3. In Orbot, check the Socks port. The default uses 9050
\n4. If necessary change the port in Orbot
\n5. Configure the Socks port in this screen
\n6. Press the post button to use Orbot as a proxy
\n6. Press the Activate button to use Orbot as a proxy
</string>
<string name="orbot_socks_port">Orbot Socks Port</string>
<string name="invalid_port_number">Invalid port number</string>
<string name="use_orbot">Use Orbot</string>
<string name="disconnect_from_your_orbot_setup">Disconnect Tor/Orbot</string>
<string name="app_notification_channel_id" translatable="false">DefaultChannelID</string>
<string name="app_notification_private_message" translatable="false">New notification arrived</string>