diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt index f108097..ffd8612 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/service/tunnel/WireGuardTunnel.kt @@ -57,7 +57,13 @@ constructor( when (val backend = backend()) { is Backend -> backend.setState(this, tunnelState.toWgState(), TunnelConfig.configFromWgQuick(tunnelConfig.wgQuick)).let { TunnelState.from(it) } is org.amnezia.awg.backend.Backend -> { - val config = if(tunnelConfig.amQuick.isBlank()) TunnelConfig.configFromAmQuick(tunnelConfig.wgQuick) else TunnelConfig.configFromAmQuick(tunnelConfig.amQuick) + 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) } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt index 4cad622..6ae564a 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt @@ -5,6 +5,9 @@ import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity +import androidx.compose.animation.core.tween +import androidx.compose.animation.fadeIn +import androidx.compose.animation.fadeOut import androidx.compose.foundation.focusable import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -49,6 +52,7 @@ import com.zaneschepke.wireguardautotunnel.ui.screens.settings.SettingsScreen import com.zaneschepke.wireguardautotunnel.ui.screens.support.SupportScreen import com.zaneschepke.wireguardautotunnel.ui.screens.support.logs.LogsScreen import com.zaneschepke.wireguardautotunnel.ui.theme.WireguardAutoTunnelTheme +import com.zaneschepke.wireguardautotunnel.util.Constants import com.zaneschepke.wireguardautotunnel.util.StringValue import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.Dispatchers @@ -129,7 +133,6 @@ class MainActivity : AppCompatActivity() { } }, containerColor = MaterialTheme.colorScheme.background, - // TODO refactor modifier = Modifier .focusable() @@ -150,14 +153,12 @@ class MainActivity : AppCompatActivity() { ) }, ) { padding -> - Surface { + Surface(modifier = Modifier.fillMaxSize().padding(padding)) { NavHost( navController, + enterTransition = { fadeIn(tween(Constants.TRANSITION_ANIMATION_TIME)) }, + exitTransition = { fadeOut(tween(Constants.TRANSITION_ANIMATION_TIME)) }, startDestination = (if (isPinLockEnabled == true) Screen.Lock.route else Screen.Main.route), - modifier = - Modifier - .padding(padding) - .fillMaxSize(), ) { composable( Screen.Main.route, diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/navigation/BottomNavBar.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/navigation/BottomNavBar.kt index df8ee04..ed63db0 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/navigation/BottomNavBar.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/navigation/BottomNavBar.kt @@ -6,42 +6,33 @@ import androidx.compose.material3.NavigationBar import androidx.compose.material3.NavigationBarItem import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue -import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.navigation.NavController import androidx.navigation.NavGraph.Companion.findStartDestination import androidx.navigation.compose.currentBackStackEntryAsState -import com.zaneschepke.wireguardautotunnel.ui.Screen @Composable fun BottomNavBar(navController: NavController, bottomNavItems: List) { - val backStackEntry = navController.currentBackStackEntryAsState() - var showBottomBar by rememberSaveable { mutableStateOf(true) } val navBackStackEntry by navController.currentBackStackEntryAsState() - // TODO find a better way to hide nav bar - showBottomBar = - when (navBackStackEntry?.destination?.route) { - Screen.Lock.route -> false - else -> true - } + showBottomBar = bottomNavItems.firstOrNull { navBackStackEntry?.destination?.route?.contains(it.route) == true } != null - NavigationBar( - containerColor = if (!showBottomBar) Color.Transparent else MaterialTheme.colorScheme.background, - ) { - if (showBottomBar) { + if(showBottomBar) { + NavigationBar( + containerColor = MaterialTheme.colorScheme.surface, + ) { bottomNavItems.forEach { item -> - val selected = item.route == backStackEntry.value?.destination?.route + val selected = navBackStackEntry?.destination?.route?.contains(item.route) == true NavigationBarItem( selected = selected, onClick = { + if(navBackStackEntry?.destination?.route == item.route) return@NavigationBarItem navController.navigate(item.route) { // Pop up to the start destination of the graph to // avoid building up a large stack of destinations diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigScreen.kt index 4e297ae..b1115ad 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/config/ConfigScreen.kt @@ -110,7 +110,12 @@ fun ConfigScreen( LaunchedEffect(uiState.loading) { if (!uiState.loading && context.isRunningOnTv()) { delay(Constants.FOCUS_REQUEST_DELAY) - focusRequester.requestFocus() + kotlin.runCatching { + focusRequester.requestFocus() + }.onFailure { + delay(Constants.FOCUS_REQUEST_DELAY) + focusRequester.requestFocus() + } } } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt index 6a8503b..9b7dbd2 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/main/MainScreen.kt @@ -144,7 +144,12 @@ fun MainScreen( LaunchedEffect(Unit) { if (context.isRunningOnTv()) { delay(Constants.FOCUS_REQUEST_DELAY) - focusRequester.requestFocus() + kotlin.runCatching { + focusRequester.requestFocus() + }.onFailure { + delay(Constants.FOCUS_REQUEST_DELAY) + focusRequester.requestFocus() + } } } @@ -262,7 +267,7 @@ fun MainScreen( reverseLayout = false, flingBehavior = ScrollableDefaults.flingBehavior(), ) { - if(uiState.tunnels.isEmpty()) { + if (uiState.tunnels.isEmpty()) { item { GettingStartedLabel(onClick = { context.openWebUrl(it) }) } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/options/OptionsScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/options/OptionsScreen.kt index 4f5861e..0bb1a39 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/options/OptionsScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/options/OptionsScreen.kt @@ -88,7 +88,12 @@ fun OptionsScreen( optionsViewModel.init(tunnelId) if (context.isRunningOnTv()) { delay(Constants.FOCUS_REQUEST_DELAY) - focusRequester.requestFocus() + kotlin.runCatching { + focusRequester.requestFocus() + }.onFailure { + delay(Constants.FOCUS_REQUEST_DELAY) + focusRequester.requestFocus() + } } } diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt index 02db929..2853f5c 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/SettingsScreen.kt @@ -269,7 +269,7 @@ fun SettingsScreen( if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) { checkFineLocationGranted() } - if(!uiState.isLocationDisclosureShown) { + if (!uiState.isLocationDisclosureShown) { BackgroundLocationDisclosure( onDismiss = { viewModel.setLocationDisclosureShown() }, onAttest = { @@ -282,7 +282,6 @@ fun SettingsScreen( return } - BackgroundLocationDialog( showLocationDialog, onDismiss = { showLocationDialog = false }, diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/components/BackgroundLocationDisclosure.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/components/BackgroundLocationDisclosure.kt index 6f52ec8..107c56c 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/components/BackgroundLocationDisclosure.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/components/BackgroundLocationDisclosure.kt @@ -28,12 +28,7 @@ import com.zaneschepke.wireguardautotunnel.R import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv @Composable -fun BackgroundLocationDisclosure( - onDismiss: () -> Unit, - onAttest: () -> Unit, - scrollState: ScrollState, - focusRequester: FocusRequester, -) { +fun BackgroundLocationDisclosure(onDismiss: () -> Unit, onAttest: () -> Unit, scrollState: ScrollState, focusRequester: FocusRequester) { val context = LocalContext.current Column( horizontalAlignment = Alignment.CenterHorizontally, diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Theme.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Theme.kt index 40c6e0e..a71aa12 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Theme.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Theme.kt @@ -20,9 +20,10 @@ private val DarkColorScheme = darkColorScheme( // primary = Purple80, primary = virdigris, - secondary = virdigris, + secondary = PurpleGrey40, // secondary = PurpleGrey80, - tertiary = virdigris, + tertiary = Pink40, + surfaceTint = Pink80, // tertiary = Pink80 ) @@ -31,6 +32,7 @@ private val LightColorScheme = primary = Purple40, secondary = PurpleGrey40, tertiary = Pink40, + surfaceTint = Pink80, /* Other default colors to override background = Color(0xFFFFFBFE), surface = Color(0xFFFFFBFE), diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/util/Constants.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/util/Constants.kt index 65b9ddb..1983ac9 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/util/Constants.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/util/Constants.kt @@ -24,6 +24,8 @@ object Constants { const val SUBSCRIPTION_TIMEOUT = 5_000L const val FOCUS_REQUEST_DELAY = 500L + const val TRANSITION_ANIMATION_TIME = 200 + const val DEFAULT_PING_IP = "1.1.1.1" const val PING_TIMEOUT = 5_000L const val VPN_RESTART_DELAY = 1_000L