From fe45a2fad9fe620976cf02b74972ac034b0684c2 Mon Sep 17 00:00:00 2001 From: Zane Schepke Date: Sat, 21 Dec 2024 02:49:38 -0500 Subject: [PATCH] fix: minor ui improvements --- app/src/main/AndroidManifest.xml | 1 + .../wireguardautotunnel/ui/MainActivity.kt | 15 ++++++++++++++- .../ui/common/config/ConfigurationToggle.kt | 6 +++--- .../ui/screens/main/MainScreen.kt | 4 ++-- .../ui/screens/settings/SettingsScreen.kt | 9 ++++++--- .../disclosure/LocationDisclosureScreen.kt | 5 +++-- .../ui/screens/support/SupportScreen.kt | 4 ++-- .../wireguardautotunnel/ui/theme/Size.kt | 1 - .../wireguardautotunnel/ui/theme/Theme.kt | 8 ++++++-- 9 files changed, 37 insertions(+), 16 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e573b28..f6bd670 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -68,6 +68,7 @@ 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 b0d6a99..376d75f 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/MainActivity.kt @@ -1,14 +1,19 @@ package com.zaneschepke.wireguardautotunnel.ui import android.content.Intent +import android.graphics.Color.TRANSPARENT +import android.os.Build import android.os.Bundle +import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels 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.layout.Box +import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.WindowInsets import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding @@ -73,7 +78,15 @@ class MainActivity : AppCompatActivity() { @Inject lateinit var tunnelService: TunnelService + @OptIn(ExperimentalLayoutApi::class) override fun onCreate(savedInstanceState: Bundle?) { + enableEdgeToEdge( + statusBarStyle = SystemBarStyle.auto(TRANSPARENT, TRANSPARENT), + navigationBarStyle = SystemBarStyle.auto(TRANSPARENT, TRANSPARENT), + ) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + window.isNavigationBarContrastEnforced = false + } super.onCreate(savedInstanceState) val viewModel by viewModels() @@ -112,7 +125,7 @@ class MainActivity : AppCompatActivity() { SnackbarControllerProvider { host -> WireguardAutoTunnelTheme(theme = appUiState.generalState.theme) { Scaffold( - contentWindowInsets = WindowInsets(0.dp), + contentWindowInsets = WindowInsets(0), snackbarHost = { SnackbarHost(host) { snackbarData: SnackbarData -> CustomSnackBar( diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/config/ConfigurationToggle.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/config/ConfigurationToggle.kt index 761ebcc..06df35d 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/config/ConfigurationToggle.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/common/config/ConfigurationToggle.kt @@ -4,12 +4,12 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.material3.MaterialTheme -import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.text.style.TextAlign +import com.zaneschepke.wireguardautotunnel.ui.common.button.ScaledSwitch @Composable fun ConfigurationToggle( @@ -38,11 +38,11 @@ fun ConfigurationToggle( ), softWrap = true, ) - Switch( + ScaledSwitch( modifier = modifier, enabled = enabled, checked = checked, - onCheckedChange = { onCheckChanged(it) }, + onClick = { onCheckChanged(it) }, ) } } 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 40ee66e..441da42 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 @@ -198,10 +198,10 @@ fun MainScreen(viewModel: MainViewModel = hiltViewModel(), uiState: AppUiState) ) LazyColumn( horizontalAlignment = Alignment.Start, - verticalArrangement = Arrangement.spacedBy(5.dp.scaledHeight(), Alignment.Top), + verticalArrangement = Arrangement.spacedBy(5.dp, Alignment.Top), modifier = Modifier - .fillMaxSize().padding(padding) + .fillMaxSize().padding(padding).padding(top = 24.dp.scaledHeight()) .overscroll(ScrollableDefaults.overscrollEffect()) .nestedScroll(nestedScrollConnection), state = rememberLazyListState(0, uiState.tunnels.count()), 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 91f95cb..f3852fb 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 @@ -5,8 +5,11 @@ import androidx.compose.foundation.focusable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.imePadding import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons @@ -46,7 +49,6 @@ import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavControll import com.zaneschepke.wireguardautotunnel.ui.common.prompt.AuthorizationPrompt import com.zaneschepke.wireguardautotunnel.ui.common.snackbar.SnackbarController import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ForwardButton -import com.zaneschepke.wireguardautotunnel.ui.theme.topPadding import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv import com.zaneschepke.wireguardautotunnel.util.extensions.launchNotificationSettings import com.zaneschepke.wireguardautotunnel.util.extensions.scaledHeight @@ -54,6 +56,7 @@ import com.zaneschepke.wireguardautotunnel.util.extensions.scaledWidth import com.zaneschepke.wireguardautotunnel.util.extensions.showToast import xyz.teamgravity.pin_lock_compose.PinManager +@OptIn(ExperimentalLayoutApi::class) @Composable fun SettingsScreen(viewModel: SettingsViewModel = hiltViewModel(), appViewModel: AppViewModel, uiState: AppUiState) { val context = LocalContext.current @@ -92,8 +95,8 @@ fun SettingsScreen(viewModel: SettingsViewModel = hiltViewModel(), appViewModel: modifier = Modifier .verticalScroll(rememberScrollState()) - .fillMaxSize() - .padding(top = topPadding) + .fillMaxSize().systemBarsPadding().imePadding() + .padding(top = 24.dp.scaledHeight()) .padding(bottom = 40.dp.scaledHeight()) .padding(horizontal = 24.dp.scaledWidth()) .then( diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/disclosure/LocationDisclosureScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/disclosure/LocationDisclosureScreen.kt index e21ac68..fc5617a 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/disclosure/LocationDisclosureScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/settings/disclosure/LocationDisclosureScreen.kt @@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.outlined.LocationOn import androidx.compose.material.icons.rounded.PermScanWifi @@ -27,7 +28,6 @@ import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SelectionIte import com.zaneschepke.wireguardautotunnel.ui.common.button.surface.SurfaceSelectionGroupButton import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ForwardButton -import com.zaneschepke.wireguardautotunnel.ui.theme.topPadding import com.zaneschepke.wireguardautotunnel.util.extensions.goFromRoot import com.zaneschepke.wireguardautotunnel.util.extensions.launchAppSettings import com.zaneschepke.wireguardautotunnel.util.extensions.scaledHeight @@ -46,7 +46,8 @@ fun LocationDisclosureScreen(appViewModel: AppViewModel, appUiState: AppUiState) horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(24.dp.scaledHeight(), Alignment.Top), modifier = - Modifier.fillMaxSize().padding(top = topPadding).padding(horizontal = 24.dp.scaledWidth()), + Modifier.fillMaxSize().systemBarsPadding().padding(top = 24.dp.scaledHeight()) + .padding(horizontal = 24.dp.scaledWidth()), ) { val icon = Icons.Rounded.PermScanWifi Icon( diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/support/SupportScreen.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/support/SupportScreen.kt index 3313695..5841e0e 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/support/SupportScreen.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/screens/support/SupportScreen.kt @@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.systemBarsPadding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons @@ -40,7 +41,6 @@ import com.zaneschepke.wireguardautotunnel.ui.common.label.GroupLabel import com.zaneschepke.wireguardautotunnel.ui.common.label.VersionLabel import com.zaneschepke.wireguardautotunnel.ui.common.navigation.LocalNavController import com.zaneschepke.wireguardautotunnel.ui.screens.settings.components.ForwardButton -import com.zaneschepke.wireguardautotunnel.ui.theme.topPadding import com.zaneschepke.wireguardautotunnel.util.extensions.isRunningOnTv import com.zaneschepke.wireguardautotunnel.util.extensions.launchSupportEmail import com.zaneschepke.wireguardautotunnel.util.extensions.openWebUrl @@ -71,7 +71,7 @@ fun SupportScreen(appUiState: AppUiState, appViewModel: AppViewModel) { modifier = Modifier .fillMaxSize() - .padding(top = topPadding) + .systemBarsPadding().padding(top = 24.dp.scaledHeight()) .verticalScroll(rememberScrollState()) .padding(horizontal = 24.dp.scaledWidth()), ) { diff --git a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Size.kt b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Size.kt index 4900c22..21276f5 100644 --- a/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Size.kt +++ b/app/src/main/java/com/zaneschepke/wireguardautotunnel/ui/theme/Size.kt @@ -4,4 +4,3 @@ import androidx.compose.ui.unit.dp import com.zaneschepke.wireguardautotunnel.util.extensions.scaledHeight val iconSize = 24.dp.scaledHeight() -val topPadding = 80.dp.scaledHeight() 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 e49cde7..57bffd4 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 @@ -74,14 +74,18 @@ fun WireguardAutoTunnelTheme(theme: Theme = Theme.AUTOMATIC, content: @Composabl } } } + val view = LocalView.current if (!view.isInEditMode) { SideEffect { val window = (view.context as Activity).window WindowCompat.setDecorFitsSystemWindows(window, false) - window.statusBarColor = Color.Transparent.toArgb() window.navigationBarColor = Color.Transparent.toArgb() - WindowCompat.getInsetsController(window, window.decorView).isAppearanceLightStatusBars = !isDark + window.statusBarColor = Color.Transparent.toArgb() + WindowCompat.getInsetsController(window, window.decorView).apply { + isAppearanceLightStatusBars = !isDark + isAppearanceLightNavigationBars = !isDark + } } }