mirror of
https://github.com/wgtunnel/android.git
synced 2026-06-02 00:29:08 +02:00
fix: nav backstack bug
This commit is contained in:
@@ -357,7 +357,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
BackHandler {
|
BackHandler {
|
||||||
if (navController.previousBackStackEntry == null || !navController.popBackStack()) {
|
if (navController.currentDestination?.route != Route.Main::class.qualifiedName) {
|
||||||
|
if (!navController.popBackStack(Route.Main, false)) {
|
||||||
|
navController.goFromRoot(Route.Main)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
this@MainActivity.finish()
|
this@MainActivity.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ abstract class BaseTunnel(
|
|||||||
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
Timber.d("Skipping redundant state update for ${tunnelConf.id}: $newState")
|
||||||
current
|
current
|
||||||
} else {
|
} else {
|
||||||
Timber.d("Updating tunnel ${tunnelConf.id} in activeTunnels as state is $newState, with stats")
|
|
||||||
val updated = existingState.copy(
|
val updated = existingState.copy(
|
||||||
status = newState,
|
status = newState,
|
||||||
statistics = stats ?: existingState.statistics,
|
statistics = stats ?: existingState.statistics,
|
||||||
|
|||||||
+8
-7
@@ -60,20 +60,21 @@ fun TunnelRowItem(
|
|||||||
val isTv = context.isRunningOnTv()
|
val isTv = context.isRunningOnTv()
|
||||||
|
|
||||||
val leadingIconColor = if (!isActive) Color.Gray else tunnelState.statistics.asColor()
|
val leadingIconColor = if (!isActive) Color.Gray else tunnelState.statistics.asColor()
|
||||||
val leadingIcon = when {
|
|
||||||
tunnel.isPrimaryTunnel -> Icons.Rounded.Star
|
val (leadingIcon, size) = when {
|
||||||
tunnel.isMobileDataTunnel -> Icons.Rounded.Smartphone
|
tunnel.isPrimaryTunnel -> Pair(Icons.Rounded.Star, 16.dp)
|
||||||
tunnel.isEthernetTunnel -> Icons.Rounded.SettingsEthernet
|
tunnel.isMobileDataTunnel -> Pair(Icons.Rounded.Smartphone, 16.dp)
|
||||||
else -> Icons.Rounded.Circle
|
tunnel.isEthernetTunnel -> Pair(Icons.Rounded.SettingsEthernet, 16.dp)
|
||||||
|
else -> Pair(Icons.Rounded.Circle, 14.dp)
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpandingRowListItem(
|
ExpandingRowListItem(
|
||||||
leading = {
|
leading = {
|
||||||
Icon(
|
Icon(
|
||||||
leadingIcon,
|
leadingIcon,
|
||||||
leadingIcon.name,
|
stringResource(R.string.status),
|
||||||
tint = leadingIconColor,
|
tint = leadingIconColor,
|
||||||
modifier = Modifier.size(16.dp),
|
modifier = Modifier.size(size),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
text = tunnel.tunName,
|
text = tunnel.tunName,
|
||||||
|
|||||||
+1
-7
@@ -1,21 +1,15 @@
|
|||||||
package com.zaneschepke.wireguardautotunnel.util.extensions
|
package com.zaneschepke.wireguardautotunnel.util.extensions
|
||||||
|
|
||||||
import androidx.navigation.NavController
|
import androidx.navigation.NavController
|
||||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.Route
|
import com.zaneschepke.wireguardautotunnel.ui.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.isCurrentRoute
|
import com.zaneschepke.wireguardautotunnel.ui.common.navigation.isCurrentRoute
|
||||||
|
|
||||||
fun NavController.goFromRoot(route: Route) {
|
fun NavController.goFromRoot(route: Route) {
|
||||||
if (currentBackStackEntry?.isCurrentRoute(route::class) == true) return
|
if (currentBackStackEntry?.isCurrentRoute(route::class) == true) return
|
||||||
this.navigate(route) {
|
this.navigate(route) {
|
||||||
// Pop up to the start destination of the graph to
|
popUpTo(Route.Main) {
|
||||||
// avoid building up a large stack of destinations
|
|
||||||
// on the back stack as users select items
|
|
||||||
popUpTo(graph.findStartDestination().id) {
|
|
||||||
saveState = true
|
saveState = true
|
||||||
}
|
}
|
||||||
// Avoid multiple copies of the same destination when
|
|
||||||
// reselecting the same item
|
|
||||||
launchSingleTop = true
|
launchSingleTop = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -246,4 +246,5 @@
|
|||||||
<string name="service_running_error">service not running error</string>
|
<string name="service_running_error">service not running error</string>
|
||||||
<string name="inactive">Inactive</string>
|
<string name="inactive">Inactive</string>
|
||||||
<string name="active">Active</string>
|
<string name="active">Active</string>
|
||||||
|
<string name="status">Status</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -131,10 +131,6 @@ class AndroidNetworkMonitor(
|
|||||||
wifiConnected = false
|
wifiConnected = false
|
||||||
trySend(WifiState(connected = false, ssid = null))
|
trySend(WifiState(connected = false, ssid = null))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities) {
|
|
||||||
Timber.d("Wi-Fi onCapabilitiesChanged: network=$network, networkCapabilities=$networkCapabilities")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val request = NetworkRequest.Builder()
|
val request = NetworkRequest.Builder()
|
||||||
|
|||||||
Reference in New Issue
Block a user