@ -10,23 +10,21 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.statusBars
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight
import androidx.compose.material.icons.outlined.ArrowDropDown
import androidx.compose.material.icons.outlined.ArrowDropDown
import androidx.compose.material.icons.outlined.Clear
import androidx.compose.material.icons.outlined.Clear
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.Close
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material.icons.outlined.Settings
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.IconButton
import androidx.compose.material3.ListItem
import androidx.compose.material3.ListItem
@ -34,6 +32,7 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SearchBar
import androidx.compose.material3.SearchBar
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.material3.SearchBarDefaults
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.collectAsState
@ -69,23 +68,17 @@ data class MainViewNavigation(
@Composable
@Composable
fun MainView ( navigation : MainViewNavigation , viewModel : MainViewModel = viewModel ( ) ) {
fun MainView ( navigation : MainViewNavigation , viewModel : MainViewModel = viewModel ( ) ) {
Scaffold ( contentWindowInsets = WindowInsets . Companion . statusBars ) { paddingInsets ->
Scaffold { _ ->
Column (
Column ( modifier = Modifier . fillMaxWidth ( ) , verticalArrangement = Arrangement . Center ) {
modifier = Modifier . fillMaxWidth ( ) . padding ( paddingInsets ) ,
verticalArrangement = Arrangement . Center ) {
val state = viewModel . ipnState . collectAsState ( initial = Ipn . State . NoState )
val state = viewModel . ipnState . collectAsState ( initial = Ipn . State . NoState )
val user = viewModel . loggedInUser . collectAsState ( initial = null )
val user = viewModel . loggedInUser . collectAsState ( initial = null )
Row (
Row (
modifier =
modifier = Modifier . fillMaxWidth ( ) . padding ( horizontal = 8. dp ) ,
Modifier . fillMaxWidth ( )
. background ( MaterialTheme . colorScheme . secondaryContainer )
. padding ( horizontal = 8. dp )
. padding ( top = 10. dp ) ,
verticalAlignment = Alignment . CenterVertically ) {
verticalAlignment = Alignment . CenterVertically ) {
val isOn = viewModel . vpnToggleState . collectAsState ( initial = false )
val isOn = viewModel . vpnToggleState . collectAsState ( initial = false )
if ( state . value != Ipn . State . NeedsLogin && state . value != Ipn . State . NoState ) {
if ( state . value != Ipn . State . NeedsLogin && state . value != Ipn . State . NoState ) {
Tinted Switch( onCheckedChange = { viewModel . toggleVpn ( ) } , checked = isOn . value )
Switch ( onCheckedChange = { viewModel . toggleVpn ( ) } , checked = isOn . value )
Spacer ( Modifier . size ( 3. dp ) )
Spacer ( Modifier . size ( 3. dp ) )
}
}
@ -105,13 +98,7 @@ fun MainView(navigation: MainViewNavigation, viewModel: MainViewModel = viewMode
Ipn . State . Running -> {
Ipn . State . Running -> {
val selfPeerId = viewModel . selfPeerId . collectAsState ( initial = " " )
val selfPeerId = viewModel . selfPeerId . collectAsState ( initial = " " )
Row (
ExitNodeStatus ( navAction = navigation . onNavigateToExitNodes , viewModel = viewModel )
modifier =
Modifier . background ( MaterialTheme . colorScheme . secondaryContainer )
. padding ( top = 10. dp , bottom = 20. dp ) ) {
ExitNodeStatus (
navAction = navigation . onNavigateToExitNodes , viewModel = viewModel )
}
PeerList (
PeerList (
searchTerm = viewModel . searchTerm ,
searchTerm = viewModel . searchTerm ,
state = viewModel . ipnState ,
state = viewModel . ipnState ,
@ -148,17 +135,16 @@ fun ExitNodeStatus(navAction: () -> Unit, viewModel: MainViewModel) {
Modifier . clickable { navAction ( ) }
Modifier . clickable { navAction ( ) }
. padding ( horizontal = 8. dp )
. padding ( horizontal = 8. dp )
. clip ( shape = RoundedCornerShape ( 10. dp , 10. dp , 10. dp , 10. dp ) )
. clip ( shape = RoundedCornerShape ( 10. dp , 10. dp , 10. dp , 10. dp ) )
. background ( MaterialTheme . colorScheme . background )
. background ( MaterialTheme . colorScheme . secondaryContainer )
. fillMaxWidth ( ) ) {
. fillMaxWidth ( ) ) {
Column ( modifier = Modifier . padding ( vertical = 15. dp , horizontal = 18 .dp ) ) {
Column ( modifier = Modifier . padding ( 6 .dp ) ) {
Text (
Text (
text = stringResource ( id = R . string . exit _node ) ,
text = stringResource ( id = R . string . exit _node ) ,
color = MaterialTheme . colorScheme . secondary ,
style = MaterialTheme . typography . titleMedium )
style = MaterialTheme . typography . titleSmall )
Row ( verticalAlignment = Alignment . CenterVertically ) {
Row ( verticalAlignment = Alignment . CenterVertically ) {
Text (
Text (
text = exitNode ?: stringResource ( id = R . string . none ) ,
text = exitNode ?: stringResource ( id = R . string . none ) ,
style = MaterialTheme . typography . body Large )
style = MaterialTheme . typography . body Medium )
Icon (
Icon (
Icons . Outlined . ArrowDropDown ,
Icons . Outlined . ArrowDropDown ,
null ,
null ,
@ -222,13 +208,12 @@ fun StartingView() {
fun ConnectView ( user : IpnLocal . LoginProfile ? , connectAction : ( ) -> Unit , loginAction : ( ) -> Unit ) {
fun ConnectView ( user : IpnLocal . LoginProfile ? , connectAction : ( ) -> Unit , loginAction : ( ) -> Unit ) {
Row ( horizontalArrangement = Arrangement . Center , modifier = Modifier . fillMaxWidth ( ) ) {
Row ( horizontalArrangement = Arrangement . Center , modifier = Modifier . fillMaxWidth ( ) ) {
Column (
Column (
horizontalAlignment = Alignment . CenterHorizontally ,
modifier =
modifier =
Modifier . background ( MaterialTheme . colorScheme . secondaryContainer ) . fillMaxWidth ( ) ) {
Modifier . background ( MaterialTheme . colorScheme . secondaryContainer )
Column (
. padding ( 8. dp )
modifier = Modifier . padding ( 8. dp ) . fillMaxWidth ( 0.7f ) . fillMaxHeight ( ) ,
. fillMaxWidth ( 0.7f )
verticalArrangement =
. fillMaxHeight ( ) ,
Arrangement . spacedBy ( 8. dp , alignment = Alignment . CenterVertically ) ,
verticalArrangement = Arrangement . spacedBy ( 8. dp , alignment = Alignment . CenterVertically ) ,
horizontalAlignment = Alignment . CenterHorizontally ,
horizontalAlignment = Alignment . CenterHorizontally ,
) {
) {
if ( user != null && ! user . isEmpty ( ) ) {
if ( user != null && ! user . isEmpty ( ) ) {
@ -280,7 +265,6 @@ fun ConnectView(user: IpnLocal.LoginProfile?, connectAction: () -> Unit, loginAc
}
}
}
}
}
}
}
}
}
@Composable
@Composable
@ -324,11 +308,9 @@ fun PeerList(
trailingIcon = {
trailingIcon = {
if ( searchTermStr . isNotEmpty ( ) ) ClearButton ( { onSearch ( " " ) } ) else CloseButton ( )
if ( searchTermStr . isNotEmpty ( ) ) ClearButton ( { onSearch ( " " ) } ) else CloseButton ( )
} ,
} ,
tonalElevation = 0. dp ,
tonalElevation = 2. dp ,
shadowElevation = 0. dp ,
shadowElevation = 2. dp ,
colors =
colors = SearchBarDefaults . colors ( ) ,
SearchBarDefaults . colors (
containerColor = Color . Transparent , dividerColor = Color . Transparent ) ,
modifier = Modifier . fillMaxWidth ( ) ) {
modifier = Modifier . fillMaxWidth ( ) ) {
LazyColumn (
LazyColumn (
modifier =
modifier =
@ -341,8 +323,7 @@ fun PeerList(
Text (
Text (
text =
text =
peerSet . user ?. DisplayName ?: stringResource ( id = R . string . unknown _user ) ,
peerSet . user ?. DisplayName ?: stringResource ( id = R . string . unknown _user ) ,
style = MaterialTheme . typography . titleLarge ,
style = MaterialTheme . typography . titleLarge )
fontWeight = FontWeight . SemiBold )
} )
} )
}
}
peerSet . peers . forEach { peer ->
peerSet . peers . forEach { peer ->
@ -363,20 +344,19 @@ fun PeerList(
}
}
Box (
Box (
modifier =
modifier =
Modifier . size ( 10 .dp )
Modifier . size ( 8 .dp )
. background (
. background (
color = color , shape = RoundedCornerShape ( percent = 50 ) ) ) { }
color = color , shape = RoundedCornerShape ( percent = 50 ) ) ) { }
Spacer ( modifier = Modifier . size ( 6 .dp ) )
Spacer ( modifier = Modifier . size ( 8 .dp ) )
Text ( text = peer . ComputedName , style = MaterialTheme . typography . titleMedium )
Text ( text = peer . ComputedName , style = MaterialTheme . typography . titleMedium )
}
}
} ,
} ,
supportingContent = {
supportingContent = {
Text (
Text (
text = peer . Addresses ?. first ( ) ?. split ( " / " ) ?. first ( ) ?: " " ,
text = peer . Addresses ?. first ( ) ?. split ( " / " ) ?. first ( ) ?: " " ,
style = MaterialTheme . typography . bodyMedium ,
style = MaterialTheme . typography . bodyMedium )
color = MaterialTheme . colorScheme . secondary )
} ,
} )
trailingContent = { Icon ( Icons . AutoMirrored . Filled . KeyboardArrowRight , null ) } )
HorizontalDivider ( color = MaterialTheme . colorScheme . secondaryContainer )
}
}
}
}
}
}