mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
fix: auto tunnel status badge
This commit is contained in:
@@ -138,7 +138,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
val sharedState by viewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||
val snackbar = remember { SnackbarHostState() }
|
||||
var showVpnPermissionDialog by remember { mutableStateOf(false) }
|
||||
var vpnPermissionDenied by remember { mutableStateOf(false) }
|
||||
@@ -255,12 +254,13 @@ class MainActivity : AppCompatActivity() {
|
||||
derivedStateOf { Tab.fromRoute(currentRoute ?: Route.Tunnels) }
|
||||
}
|
||||
val selectedCount by
|
||||
rememberSaveable(sharedState.selectedTunnels) {
|
||||
mutableIntStateOf(sharedState.selectedTunnels.size)
|
||||
rememberSaveable(appState.selectedTunnels) {
|
||||
mutableIntStateOf(appState.selectedTunnels.size)
|
||||
}
|
||||
|
||||
val navState by
|
||||
currentRouteAsNavbarState(
|
||||
appState,
|
||||
viewModel,
|
||||
currentRoute,
|
||||
selectedCount,
|
||||
|
||||
+4
-4
@@ -71,7 +71,7 @@ constructor(
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||
val binder = service as? LocalBinder
|
||||
_tunnelService.value = binder?.service
|
||||
_tunnelService.update { binder?.service }
|
||||
val serviceClass =
|
||||
when {
|
||||
name.className.contains("VpnForegroundService") -> "VpnForegroundService"
|
||||
@@ -83,7 +83,7 @@ constructor(
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName) {
|
||||
_tunnelService.value = null
|
||||
_tunnelService.update { null }
|
||||
val serviceClass =
|
||||
when {
|
||||
name.className.contains("VpnForegroundService") -> "VpnForegroundService"
|
||||
@@ -99,12 +99,12 @@ constructor(
|
||||
object : ServiceConnection {
|
||||
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
||||
val binder = service as? AutoTunnelService.LocalBinder
|
||||
_autoTunnelService.value = binder?.service
|
||||
_autoTunnelService.update { binder?.service }
|
||||
Timber.d("AutoTunnelService connected")
|
||||
}
|
||||
|
||||
override fun onServiceDisconnected(name: ComponentName) {
|
||||
_autoTunnelService.value = null
|
||||
_autoTunnelService.update { null }
|
||||
Timber.d("AutoTunnelService disconnected")
|
||||
}
|
||||
}
|
||||
|
||||
+31
-33
@@ -30,32 +30,24 @@ fun BottomNavbar(isAutoTunnelActive: Boolean, currentTab: Tab, onTabSelected: (T
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val isSelected = currentTab == tab
|
||||
val hasBadge = tab == Tab.AUTOTUNNEL && isAutoTunnelActive
|
||||
|
||||
IconButton(
|
||||
onClick = { onTabSelected(tab) },
|
||||
colors =
|
||||
IconButtonDefaults.iconButtonColors(
|
||||
containerColor = Color.Transparent,
|
||||
contentColor =
|
||||
if (isSelected) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
disabledContainerColor = Color.Transparent,
|
||||
disabledContentColor = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
interactionSource = interactionSource,
|
||||
) {
|
||||
if (hasBadge) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier =
|
||||
Modifier.offset(x = 8.dp, y = (-8).dp).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
val button =
|
||||
@Stable @Composable {
|
||||
IconButton(
|
||||
onClick = { onTabSelected(tab) },
|
||||
colors =
|
||||
IconButtonDefaults.iconButtonColors(
|
||||
containerColor = Color.Transparent,
|
||||
contentColor =
|
||||
if (isSelected) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.onSurfaceVariant
|
||||
},
|
||||
disabledContainerColor = Color.Transparent,
|
||||
disabledContentColor =
|
||||
MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
interactionSource = interactionSource,
|
||||
) {
|
||||
AnimatedFloatIcon(
|
||||
activeIcon = tab.activeIcon,
|
||||
@@ -64,14 +56,20 @@ fun BottomNavbar(isAutoTunnelActive: Boolean, currentTab: Tab, onTabSelected: (T
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
AnimatedFloatIcon(
|
||||
activeIcon = tab.activeIcon,
|
||||
inactiveIcon = tab.inactiveIcon,
|
||||
isSelected = isSelected,
|
||||
modifier = Modifier.size(24.dp),
|
||||
)
|
||||
}
|
||||
if (hasBadge) {
|
||||
BadgedBox(
|
||||
badge = {
|
||||
Badge(
|
||||
modifier = Modifier.offset(x = (-4).dp, y = (4).dp).size(6.dp),
|
||||
containerColor = SilverTree,
|
||||
)
|
||||
}
|
||||
) {
|
||||
button()
|
||||
}
|
||||
} else {
|
||||
button()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -10,23 +10,23 @@ import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.derivedStateOf
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.zaneschepke.wireguardautotunnel.R
|
||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ActionIconButton
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.NavController
|
||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||
import com.zaneschepke.wireguardautotunnel.ui.sideeffect.LocalSideEffect
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||
import com.zaneschepke.wireguardautotunnel.ui.state.SharedAppUiState
|
||||
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
||||
|
||||
@Composable
|
||||
fun currentRouteAsNavbarState(
|
||||
sharedState: SharedAppUiState,
|
||||
sharedViewModel: SharedAppViewModel,
|
||||
route: Route?,
|
||||
selectedCount: Int,
|
||||
navController: NavController,
|
||||
): State<NavbarState> {
|
||||
val sharedState by sharedViewModel.container.stateFlow.collectAsStateWithLifecycle()
|
||||
val keyboardController = LocalSoftwareKeyboardController.current
|
||||
val context = LocalContext.current
|
||||
|
||||
|
||||
@@ -7,5 +7,4 @@ data class NavbarState(
|
||||
val topTrailing: (@Composable () -> Unit)? = null,
|
||||
val topLeading: (@Composable () -> Unit)? = null,
|
||||
val showBottomItems: Boolean = false,
|
||||
val isAutoTunnelActive: Boolean = false,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user