add configuration screen when enabling tor in the drawer

pull/357/head
greenart7c3 2023-05-05 08:25:48 -03:00
rodzic 9c30547bd7
commit 28521c1a60
3 zmienionych plików z 135 dodań i 7 usunięć

Wyświetl plik

@ -27,7 +27,6 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
@ -48,6 +47,7 @@ import androidx.navigation.NavController
import androidx.navigation.NavHostController
import coil.compose.AsyncImage
import com.vitorpamplona.amethyst.BuildConfig
import com.vitorpamplona.amethyst.LocalPreferences
import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ServiceManager
import com.vitorpamplona.amethyst.model.Account
@ -57,6 +57,7 @@ import com.vitorpamplona.amethyst.ui.components.ResizeImage
import com.vitorpamplona.amethyst.ui.components.RobohashAsyncImageProxy
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountBackupDialog
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.ConnectOrbotDialog
import kotlinx.coroutines.launch
@OptIn(ExperimentalMaterialApi::class)
@ -239,6 +240,7 @@ fun ListContent(
var backupDialogOpen by remember { mutableStateOf(false) }
var checked by remember { mutableStateOf(account.proxy != null) }
val openDialog = remember { mutableStateOf(false) }
var conectOrbotDialogOpen by remember { mutableStateOf(false) }
Column(modifier = modifier.fillMaxHeight()) {
if (accountUser != null) {
@ -287,8 +289,7 @@ fun ListContent(
if (checked) {
openDialog.value = true
} else {
checked = true
enableTor(account, true, openDialog)
conectOrbotDialogOpen = true
}
}
)
@ -307,6 +308,19 @@ fun ListContent(
AccountBackupDialog(account, onClose = { backupDialogOpen = false })
}
if (conectOrbotDialogOpen) {
ConnectOrbotDialog(
account = account,
onClose = { conectOrbotDialogOpen = false },
onPost = {
conectOrbotDialogOpen = false
openDialog.value = false
checked = true
enableTor(account, true)
}
)
}
if (openDialog.value) {
AlertDialog(
text = { Text(text = stringResource(R.string.do_you_really_want_to_disable_tor)) },
@ -316,7 +330,7 @@ fun ListContent(
onClick = {
openDialog.value = false
checked = false
enableTor(account, false, openDialog)
enableTor(account, false)
}
) {
Text(text = stringResource(R.string.yes))
@ -337,13 +351,12 @@ fun ListContent(
private fun enableTor(
account: Account,
checked: Boolean,
openDialog: MutableState<Boolean>
checked: Boolean
) {
account.proxy = HttpClient.initProxy(checked, "127.0.0.1", 9050)
LocalPreferences.saveToEncryptedStorage(account)
ServiceManager.pause()
ServiceManager.start()
openDialog.value = false
}
@Composable

Wyświetl plik

@ -0,0 +1,105 @@
package com.vitorpamplona.amethyst.ui.screen.loggedIn
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.text.KeyboardOptions
import androidx.compose.material.MaterialTheme
import androidx.compose.material.OutlinedTextField
import androidx.compose.material.Surface
import androidx.compose.material.Text
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.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.KeyboardCapitalization
import androidx.compose.ui.text.input.KeyboardType
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.model.Account
import com.vitorpamplona.amethyst.ui.actions.CloseButton
import com.vitorpamplona.amethyst.ui.actions.PostButton
@Composable
fun ConnectOrbotDialog(account: Account, onClose: () -> Unit, onPost: () -> Unit) {
var portNumber by remember { mutableStateOf("9050") }
Dialog(
onDismissRequest = onClose,
properties = DialogProperties(usePlatformDefaultWidth = false)
) {
Surface(modifier = Modifier.fillMaxSize()) {
Column(
modifier = Modifier
.padding(10.dp)
.background(MaterialTheme.colors.background)
.fillMaxSize()
) {
Row(
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth()
) {
CloseButton(onCancel = {
onClose()
})
PostButton(
onPost = {
onPost()
},
isActive = true
)
}
Column(
modifier = Modifier
.fillMaxSize()
.padding(horizontal = 30.dp)
) {
MaterialRichText(
style = RichTextStyle().resolveDefaults()
) {
Markdown(
content = stringResource(R.string.connect_through_your_orbot_setup_markdown)
)
}
Spacer(modifier = Modifier.height(10.dp))
OutlinedTextField(
value = portNumber,
onValueChange = { portNumber = 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)
)
}
)
}
}
}
}
}

Wyświetl plik

@ -358,5 +358,15 @@
<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
\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
\n5. Configure the Socks port in this screen
\n6. Press the post button to use Orbot as a proxy
</string>
<string name="orbot_socks_port">Orbot Socks Port</string>
</resources>