fix: minor ui changes

This commit is contained in:
Zane Schepke 2024-08-16 22:13:31 -04:00
parent 1af474c449
commit 528a1f84e4
9 changed files with 93 additions and 92 deletions

View File

@ -56,8 +56,11 @@ constructor(
return runCatching { return runCatching {
when (val backend = backend()) { when (val backend = backend()) {
is Backend -> backend.setState(this, tunnelState.toWgState(), TunnelConfig.configFromWgQuick(tunnelConfig.wgQuick)).let { TunnelState.from(it) } is Backend -> backend.setState(this, tunnelState.toWgState(), TunnelConfig.configFromWgQuick(tunnelConfig.wgQuick)).let { TunnelState.from(it) }
is org.amnezia.awg.backend.Backend -> backend.setState(this, tunnelState.toAmState(), TunnelConfig.configFromAmQuick(tunnelConfig.amQuick)).let { is org.amnezia.awg.backend.Backend -> {
TunnelState.from(it) val config = if(tunnelConfig.amQuick.isBlank()) TunnelConfig.configFromAmQuick(tunnelConfig.wgQuick) else TunnelConfig.configFromAmQuick(tunnelConfig.amQuick)
backend.setState(this, tunnelState.toAmState(), config).let {
TunnelState.from(it)
}
} }
else -> throw NotImplementedError() else -> throw NotImplementedError()
} }

View File

@ -15,6 +15,7 @@ import androidx.compose.material3.SnackbarDuration
import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.SnackbarResult import androidx.compose.material3.SnackbarResult
import androidx.compose.material3.Surface
import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -127,6 +128,7 @@ class MainActivity : AppCompatActivity() {
) )
} }
}, },
containerColor = MaterialTheme.colorScheme.background,
// TODO refactor // TODO refactor
modifier = modifier =
Modifier Modifier
@ -148,88 +150,90 @@ class MainActivity : AppCompatActivity() {
) )
}, },
) { padding -> ) { padding ->
NavHost( Surface {
navController, NavHost(
startDestination = (if (isPinLockEnabled == true) Screen.Lock.route else Screen.Main.route), navController,
modifier = startDestination = (if (isPinLockEnabled == true) Screen.Lock.route else Screen.Main.route),
Modifier modifier =
.padding(padding) Modifier
.fillMaxSize(), .padding(padding)
) { .fillMaxSize(),
composable(
Screen.Main.route,
) { ) {
MainScreen( composable(
focusRequester = focusRequester, Screen.Main.route,
appViewModel = appViewModel, ) {
navController = navController, MainScreen(
)
}
composable(
Screen.Settings.route,
) {
SettingsScreen(
appViewModel = appViewModel,
navController = navController,
focusRequester = focusRequester,
)
}
composable(
Screen.Support.route,
) {
SupportScreen(
focusRequester = focusRequester,
navController = navController,
)
}
composable(Screen.Support.Logs.route) {
LogsScreen()
}
composable(
"${Screen.Config.route}/{id}?configType={configType}",
arguments =
listOf(
navArgument("id") {
type = NavType.StringType
defaultValue = "0"
},
navArgument("configType") {
type = NavType.StringType
defaultValue = ConfigType.WIREGUARD.name
},
),
) {
val id = it.arguments?.getString("id")
val configType =
ConfigType.valueOf(
it.arguments?.getString("configType") ?: ConfigType.WIREGUARD.name,
)
if (!id.isNullOrBlank()) {
ConfigScreen(
navController = navController,
tunnelId = id,
appViewModel = appViewModel,
focusRequester = focusRequester, focusRequester = focusRequester,
configType = configType, appViewModel = appViewModel,
navController = navController,
) )
} }
} composable(
composable("${Screen.Option.route}/{id}") { Screen.Settings.route,
val id = it.arguments?.getString("id") ) {
if (!id.isNullOrBlank()) { SettingsScreen(
OptionsScreen(
navController = navController,
tunnelId = id,
appViewModel = appViewModel, appViewModel = appViewModel,
navController = navController,
focusRequester = focusRequester, focusRequester = focusRequester,
) )
} }
} composable(
composable(Screen.Lock.route) { Screen.Support.route,
PinLockScreen( ) {
navController = navController, SupportScreen(
appViewModel = appViewModel, focusRequester = focusRequester,
) navController = navController,
)
}
composable(Screen.Support.Logs.route) {
LogsScreen()
}
composable(
"${Screen.Config.route}/{id}?configType={configType}",
arguments =
listOf(
navArgument("id") {
type = NavType.StringType
defaultValue = "0"
},
navArgument("configType") {
type = NavType.StringType
defaultValue = ConfigType.WIREGUARD.name
},
),
) {
val id = it.arguments?.getString("id")
val configType =
ConfigType.valueOf(
it.arguments?.getString("configType") ?: ConfigType.WIREGUARD.name,
)
if (!id.isNullOrBlank()) {
ConfigScreen(
navController = navController,
tunnelId = id,
appViewModel = appViewModel,
focusRequester = focusRequester,
configType = configType,
)
}
}
composable("${Screen.Option.route}/{id}") {
val id = it.arguments?.getString("id")
if (!id.isNullOrBlank()) {
OptionsScreen(
navController = navController,
tunnelId = id,
appViewModel = appViewModel,
focusRequester = focusRequester,
)
}
}
composable(Screen.Lock.route) {
PinLockScreen(
navController = navController,
appViewModel = appViewModel,
)
}
} }
} }
} }

View File

@ -6,6 +6,7 @@ import androidx.compose.material3.NavigationBar
import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.NavigationBarItem
import androidx.compose.material3.Text import androidx.compose.material3.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.saveable.rememberSaveable

View File

@ -296,7 +296,7 @@ constructor(
val wgQuick = buildConfig().toWgQuickString(true) val wgQuick = buildConfig().toWgQuickString(true)
val amQuick = val amQuick =
if (configType == ConfigType.AMNEZIA) { if (configType == ConfigType.AMNEZIA) {
buildAmConfig().toAwgQuickString() buildAmConfig().toAwgQuickString(true)
} else { } else {
TunnelConfig.AM_QUICK_DEFAULT TunnelConfig.AM_QUICK_DEFAULT
} }

View File

@ -4,9 +4,6 @@ import android.annotation.SuppressLint
import androidx.activity.compose.rememberLauncherForActivityResult import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity.RESULT_OK import androidx.appcompat.app.AppCompatActivity.RESULT_OK
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.focusable import androidx.compose.foundation.focusable
import androidx.compose.foundation.gestures.ScrollableDefaults import androidx.compose.foundation.gestures.ScrollableDefaults
@ -265,12 +262,8 @@ fun MainScreen(
reverseLayout = false, reverseLayout = false,
flingBehavior = ScrollableDefaults.flingBehavior(), flingBehavior = ScrollableDefaults.flingBehavior(),
) { ) {
item { if(uiState.tunnels.isEmpty()) {
AnimatedVisibility( item {
uiState.tunnels.isEmpty(),
exit = fadeOut(),
enter = fadeIn(),
) {
GettingStartedLabel(onClick = { context.openWebUrl(it) }) GettingStartedLabel(onClick = { context.openWebUrl(it) })
} }
} }

View File

@ -179,7 +179,7 @@ constructor(
when (type) { when (type) {
ConfigType.AMNEZIA -> { ConfigType.AMNEZIA -> {
val config = org.amnezia.awg.config.Config.parse(it) val config = org.amnezia.awg.config.Config.parse(it)
amQuick = config.toAwgQuickString() amQuick = config.toAwgQuickString(true)
config.toWgQuickString() config.toWgQuickString()
} }
@ -252,7 +252,7 @@ constructor(
org.amnezia.awg.config.Config.parse( org.amnezia.awg.config.Config.parse(
zip, zip,
) )
amQuick = config.toAwgQuickString() amQuick = config.toAwgQuickString(true)
config.toWgQuickString() config.toWgQuickString()
} }

View File

@ -630,7 +630,7 @@ fun SettingsScreen(
Modifier Modifier
.fillMaxWidth(fillMaxWidth) .fillMaxWidth(fillMaxWidth)
.padding(vertical = 10.dp) .padding(vertical = 10.dp)
.padding(bottom = 140.dp), .padding(bottom = 10.dp),
) { ) {
Column( Column(
horizontalAlignment = Alignment.Start, horizontalAlignment = Alignment.Start,

View File

@ -29,7 +29,7 @@ fun TunnelStatistics.PeerStats.handshakeStatus(): HandshakeStatus {
} }
fun Config.toWgQuickString(): String { fun Config.toWgQuickString(): String {
val amQuick = toAwgQuickString() val amQuick = toAwgQuickString(true)
val lines = amQuick.lines().toMutableList() val lines = amQuick.lines().toMutableList()
val linesIterator = lines.iterator() val linesIterator = lines.iterator()
while (linesIterator.hasNext()) { while (linesIterator.hasNext()) {

View File

@ -1,7 +1,7 @@
[versions] [versions]
accompanist = "0.34.0" accompanist = "0.34.0"
activityCompose = "1.9.1" activityCompose = "1.9.1"
amneziawgAndroid = "1.2.1" amneziawgAndroid = "1.2.2"
androidx-junit = "1.2.1" androidx-junit = "1.2.1"
appcompat = "1.7.0" appcompat = "1.7.0"
biometricKtx = "1.2.0-alpha05" biometricKtx = "1.2.0-alpha05"
@ -16,7 +16,7 @@ junit = "4.13.2"
kotlinx-serialization-json = "1.7.1" kotlinx-serialization-json = "1.7.1"
lifecycle-runtime-compose = "2.8.4" lifecycle-runtime-compose = "2.8.4"
material3 = "1.2.1" material3 = "1.2.1"
multifabVersion = "1.1.0" multifabVersion = "1.1.1"
navigationCompose = "2.7.7" navigationCompose = "2.7.7"
pinLockCompose = "1.0.3" pinLockCompose = "1.0.3"
roomVersion = "2.6.1" roomVersion = "2.6.1"