Skip to content

Commit 3905949

Browse files
committed
save state of hide ip & network name.
1 parent c1ac15f commit 3905949

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

mobile/src/main/java/com/windscribe/mobile/ui/common/NetworkNameSheet.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ private fun isLocationEnabled(context: Context): Boolean {
5252
true
5353
}
5454
}
55+
5556
@Composable
5657
fun NetworkNameSheet(connectionViewmodel: ConnectionViewmodel, homeViewmodel: HomeViewmodel) {
5758
val activity = LocalContext.current as AppStartActivity
5859
val networkInfo by connectionViewmodel.networkInfoState.collectAsState()
59-
val hapticEnabled by homeViewmodel.hapticFeedbackEnabled.collectAsState()
6060
var showPermissionRequest by remember { mutableStateOf(false) }
6161
val navController = LocalNavController.current
6262
if (showPermissionRequest) {
@@ -68,7 +68,11 @@ fun NetworkNameSheet(connectionViewmodel: ConnectionViewmodel, homeViewmodel: Ho
6868
)
6969
if (networkInfo is NetworkInfoState.Unknown) {
7070
if (!isLocationEnabled(activity)) {
71-
Toast.makeText(activity, "Enable location services to access network name & restart app.", Toast.LENGTH_SHORT).show()
71+
Toast.makeText(
72+
activity,
73+
"Enable location services to access network name & restart app.",
74+
Toast.LENGTH_SHORT
75+
).show()
7276
return@RequestLocationPermissions
7377
}
7478
Toast.makeText(activity, "Unable to get network name.", Toast.LENGTH_SHORT).show()
@@ -89,7 +93,7 @@ fun NetworkNameSheet(connectionViewmodel: ConnectionViewmodel, homeViewmodel: Ho
8993
modifier = Modifier.padding(start = 12.dp)
9094
)
9195

92-
val hideIp = remember { mutableStateOf(false) }
96+
val hideNetworkName by homeViewmodel.hideNetworkName.collectAsState()
9397

9498
Text(
9599
text = networkInfo.name ?: stringResource(com.windscribe.vpn.R.string.unknown),
@@ -99,9 +103,9 @@ fun NetworkNameSheet(connectionViewmodel: ConnectionViewmodel, homeViewmodel: Ho
99103
.alpha(0.7f)
100104
.padding(start = 4.dp)
101105
.graphicsLayer {
102-
renderEffect = if (hideIp.value) BlurEffect(15f, 15f) else null
106+
renderEffect = if (hideNetworkName) BlurEffect(15f, 15f) else null
103107
}
104-
.clickable { hideIp.value = !hideIp.value }
108+
.clickable { homeViewmodel.onHideNetworkNameClick() }
105109
)
106110

107111
Image(

mobile/src/main/java/com/windscribe/mobile/ui/home/HomeScreen.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,7 @@ internal fun BoxScope.NetworkInfoSheet(
389389
) {
390390
val ip by connectionViewmodel.ipState.collectAsState()
391391
val showContextMenu by connectionViewmodel.ipContextMenuState.collectAsState()
392-
val isHapticEnabled by homeViewmodel.hapticFeedbackEnabled.collectAsState()
393-
val hideIp = remember { mutableStateOf(false) }
392+
val hideIp by homeViewmodel.hideIp.collectAsState()
394393
Row(
395394
verticalAlignment = Alignment.CenterVertically,
396395
modifier = Modifier
@@ -414,10 +413,10 @@ internal fun BoxScope.NetworkInfoSheet(
414413
style = font16.copy(fontWeight = FontWeight.Medium),
415414
color = AppColors.white.copy(alpha = 0.70f), modifier = Modifier
416415
.clickable {
417-
hideIp.value = !hideIp.value
416+
homeViewmodel.onHideIpClick()
418417
}
419418
.graphicsLayer {
420-
renderEffect = if (hideIp.value) {
419+
renderEffect = if (hideIp) {
421420
BlurEffect(15f, 15f)
422421
} else {
423422
null

mobile/src/main/java/com/windscribe/mobile/ui/home/HomeViewmodel.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ sealed class HomeGoto {
3030
object ShareAppLink : HomeGoto()
3131
object LocationMaintenance : HomeGoto()
3232
data class EditCustomConfig(val id: Int, val connect: Boolean) : HomeGoto()
33-
object MainMenu: HomeGoto()
34-
object None: HomeGoto()
33+
object MainMenu : HomeGoto()
34+
object None : HomeGoto()
3535
}
3636

3737
sealed class UserState() {
@@ -51,8 +51,14 @@ abstract class HomeViewmodel : ViewModel() {
5151
abstract val userState: StateFlow<UserState>
5252
abstract val hapticFeedbackEnabled: StateFlow<Boolean>
5353
abstract val showLocationLoad: StateFlow<Boolean>
54+
abstract val hideIp: StateFlow<Boolean>
55+
abstract val hideNetworkName: StateFlow<Boolean>
5456
abstract fun onMainMenuClick()
5557
abstract fun onGoToHandled()
58+
59+
abstract fun onHideIpClick()
60+
61+
abstract fun onHideNetworkNameClick()
5662
}
5763

5864
class HomeViewmodelImpl(
@@ -69,6 +75,10 @@ class HomeViewmodelImpl(
6975
override val hapticFeedbackEnabled: StateFlow<Boolean> = _hapticFeedbackEnabled
7076
private val _showLocationLoad = MutableStateFlow(preferences.isShowLocationHealthEnabled)
7177
override val showLocationLoad: StateFlow<Boolean> = _showLocationLoad
78+
private val _hideIp = MutableStateFlow(false)
79+
override val hideIp: StateFlow<Boolean> = _hideIp
80+
private val _hideNetworkName = MutableStateFlow(false)
81+
override val hideNetworkName: StateFlow<Boolean> = _hideNetworkName
7282

7383
private val trayPreferenceChangeListener = OnTrayPreferenceChangeListener {
7484
_hapticFeedbackEnabled.value = preferences.isHapticFeedbackEnabled
@@ -165,6 +175,14 @@ class HomeViewmodelImpl(
165175
}
166176
}
167177

178+
override fun onHideIpClick() {
179+
_hideIp.value = !_hideIp.value
180+
}
181+
182+
override fun onHideNetworkNameClick() {
183+
_hideNetworkName.value = !_hideNetworkName.value
184+
}
185+
168186
override fun onCleared() {
169187
preferences.removeObserver(trayPreferenceChangeListener)
170188
viewModelScope.launch {

0 commit comments

Comments
 (0)