mirror of
https://github.com/wgtunnel/android.git
synced 2026-07-03 14:07:49 +02:00
+9
-18
@@ -17,7 +17,6 @@ import androidx.navigation.toRoute
|
|||||||
import com.zaneschepke.wireguardautotunnel.R
|
import com.zaneschepke.wireguardautotunnel.R
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.common.button.ActionIconButton
|
import com.zaneschepke.wireguardautotunnel.ui.common.button.ActionIconButton
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.navigation.Route.Config
|
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.sideeffect.LocalSideEffect
|
import com.zaneschepke.wireguardautotunnel.ui.sideeffect.LocalSideEffect
|
||||||
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
import com.zaneschepke.wireguardautotunnel.ui.state.NavbarState
|
||||||
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
import com.zaneschepke.wireguardautotunnel.viewmodel.SharedAppViewModel
|
||||||
@@ -74,17 +73,12 @@ fun NavHostController.currentBackStackEntryAsNavbarState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val disableDelete by
|
|
||||||
rememberSaveable(sharedState.selectedTunnels) {
|
|
||||||
mutableStateOf(sharedState.selectedTunnels.any { it.isActive })
|
|
||||||
}
|
|
||||||
|
|
||||||
val selectedCount by
|
val selectedCount by
|
||||||
rememberSaveable(sharedState.selectedTunnels) {
|
rememberSaveable(sharedState.selectedTunnels) {
|
||||||
mutableIntStateOf(sharedState.selectedTunnels.size)
|
mutableIntStateOf(sharedState.selectedTunnels.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
return produceState(initialValue = NavbarState(), route, selectedCount, disableDelete) {
|
return produceState(initialValue = NavbarState(), route, selectedCount) {
|
||||||
value =
|
value =
|
||||||
when (route) {
|
when (route) {
|
||||||
Route.AdvancedAutoTunnel ->
|
Route.AdvancedAutoTunnel ->
|
||||||
@@ -232,7 +226,7 @@ fun NavHostController.currentBackStackEntryAsNavbarState(
|
|||||||
sharedViewModel.postSideEffect(LocalSideEffect.Modal.QR)
|
sharedViewModel.postSideEffect(LocalSideEffect.Modal.QR)
|
||||||
}
|
}
|
||||||
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
ActionIconButton(Icons.Rounded.Edit, R.string.edit_tunnel) {
|
||||||
navigate(Config(route.id))
|
navigate(Route.Config(route.id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -271,16 +265,13 @@ fun NavHostController.currentBackStackEntryAsNavbarState(
|
|||||||
sharedViewModel.copySelectedTunnel()
|
sharedViewModel.copySelectedTunnel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
ActionIconButton(
|
||||||
if (!disableDelete) {
|
Icons.Rounded.Delete,
|
||||||
ActionIconButton(
|
R.string.delete_tunnel,
|
||||||
Icons.Rounded.Delete,
|
) {
|
||||||
R.string.delete_tunnel,
|
sharedViewModel.postSideEffect(
|
||||||
) {
|
LocalSideEffect.Modal.DeleteTunnels
|
||||||
sharedViewModel.postSideEffect(
|
)
|
||||||
LocalSideEffect.Modal.DeleteTunnels
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-4
@@ -27,18 +27,19 @@ import com.zaneschepke.wireguardautotunnel.util.LocaleUtil
|
|||||||
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
import com.zaneschepke.wireguardautotunnel.util.StringValue
|
||||||
import com.zaneschepke.wireguardautotunnel.util.extensions.saveTunnelsUniquely
|
import com.zaneschepke.wireguardautotunnel.util.extensions.saveTunnelsUniquely
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
|
import java.io.File
|
||||||
|
import java.time.Instant
|
||||||
|
import javax.inject.Inject
|
||||||
|
import javax.inject.Provider
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
import kotlinx.coroutines.flow.combine
|
import kotlinx.coroutines.flow.combine
|
||||||
|
import kotlinx.coroutines.flow.firstOrNull
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import org.orbitmvi.orbit.ContainerHost
|
import org.orbitmvi.orbit.ContainerHost
|
||||||
import org.orbitmvi.orbit.viewmodel.container
|
import org.orbitmvi.orbit.viewmodel.container
|
||||||
import rikka.shizuku.Shizuku
|
import rikka.shizuku.Shizuku
|
||||||
import xyz.teamgravity.pin_lock_compose.PinManager
|
import xyz.teamgravity.pin_lock_compose.PinManager
|
||||||
import java.io.File
|
|
||||||
import java.time.Instant
|
|
||||||
import javax.inject.Inject
|
|
||||||
import javax.inject.Provider
|
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class SharedAppViewModel
|
class SharedAppViewModel
|
||||||
@@ -227,6 +228,13 @@ constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun deleteSelectedTunnels() = intent {
|
fun deleteSelectedTunnels() = intent {
|
||||||
|
val activeTunIds = tunnelManager.activeTunnels.firstOrNull()?.map { it.key }
|
||||||
|
if (state.selectedTunnels.any { activeTunIds?.contains(it.id) == true })
|
||||||
|
return@intent postSideEffect(
|
||||||
|
GlobalSideEffect.Snackbar(
|
||||||
|
StringValue.StringResource(R.string.delete_active_message)
|
||||||
|
)
|
||||||
|
)
|
||||||
tunnelRepository.delete(state.selectedTunnels.toList())
|
tunnelRepository.delete(state.selectedTunnels.toList())
|
||||||
clearSelectedTunnels()
|
clearSelectedTunnels()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@
|
|||||||
<string name="location_services_missing_message">The app is not detecting any location services enabled on your device. Depending on the device, this could cause the untrusted wifi feature to fail to read the wifi name. Would you like to continue anyways?</string>
|
<string name="location_services_missing_message">The app is not detecting any location services enabled on your device. Depending on the device, this could cause the untrusted wifi feature to fail to read the wifi name. Would you like to continue anyways?</string>
|
||||||
<string name="auto_tunnel_title">Auto-tunnel service</string>
|
<string name="auto_tunnel_title">Auto-tunnel service</string>
|
||||||
<string name="delete_tunnel">Delete tunnel</string>
|
<string name="delete_tunnel">Delete tunnel</string>
|
||||||
<string name="delete_tunnel_message">Are you sure you would like to delete this tunnel?</string>
|
<string name="delete_tunnel_message">Are you sure you would like to delete the selected tunnels?</string>
|
||||||
<string name="yes">Yes</string>
|
<string name="yes">Yes</string>
|
||||||
<string name="all">All</string>
|
<string name="all">All</string>
|
||||||
<string name="no_email_detected">No email app detected</string>
|
<string name="no_email_detected">No email app detected</string>
|
||||||
@@ -432,4 +432,5 @@
|
|||||||
<string name="google_donation_message">Unfortunately, due to Google\'s policies, donation links are not allowed in
|
<string name="google_donation_message">Unfortunately, due to Google\'s policies, donation links are not allowed in
|
||||||
the Play Store version of this app. Please browse the project\'s webpages to find where to donate.
|
the Play Store version of this app. Please browse the project\'s webpages to find where to donate.
|
||||||
</string>
|
</string>
|
||||||
|
<string name="delete_active_message">Cannot delete active tunnel.</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user