Skip to content

Commit 60f0178

Browse files
committed
added ghost account state.
1 parent 12922cf commit 60f0178

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

mobile/src/main/java/com/windscribe/mobile/ui/preferences/account/AccountScreen.kt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import android.widget.Toast
66
import androidx.compose.foundation.background
77
import androidx.compose.foundation.clickable
88
import androidx.compose.foundation.gestures.scrollable
9+
import androidx.compose.foundation.layout.Arrangement
910
import androidx.compose.foundation.layout.Column
1011
import androidx.compose.foundation.layout.Row
1112
import androidx.compose.foundation.layout.RowScope
1213
import androidx.compose.foundation.layout.Spacer
14+
import androidx.compose.foundation.layout.fillMaxSize
1315
import androidx.compose.foundation.layout.fillMaxWidth
1416
import androidx.compose.foundation.layout.height
1517
import androidx.compose.foundation.layout.navigationBarsPadding
@@ -54,6 +56,7 @@ import androidx.compose.ui.unit.dp
5456
import androidx.compose.ui.unit.max
5557
import androidx.compose.ui.window.Dialog
5658
import com.windscribe.mobile.ui.AppStartActivity
59+
import com.windscribe.mobile.ui.common.NextButton
5760
import com.windscribe.mobile.ui.common.PreferenceBackground
5861
import com.windscribe.mobile.ui.common.PreferenceProgressBar
5962
import com.windscribe.mobile.ui.common.openUrl
@@ -81,12 +84,21 @@ fun AccountScreen(viewModel: AccountViewModel? = null) {
8184
val navController = LocalNavController.current
8285
val showProgress by viewModel?.showProgress?.collectAsState()
8386
?: remember { mutableStateOf(false) }
87+
val isGhostAccount by viewModel?.isGhostAccount?.collectAsState() ?: remember {
88+
mutableStateOf(
89+
false
90+
)
91+
}
8492
val scrollState = rememberScrollState()
8593
PreferenceBackground {
8694
Column(modifier = Modifier.padding(vertical = 16.dp, horizontal = 16.dp)) {
8795
PreferencesNavBar(stringResource(R.string.my_account)) {
8896
navController.popBackStack()
8997
}
98+
if (isGhostAccount) {
99+
GhostAccountState()
100+
return@Column
101+
}
90102
Column(Modifier
91103
.navigationBarsPadding()
92104
.verticalScroll(scrollState)) {
@@ -118,6 +130,35 @@ fun AccountScreen(viewModel: AccountViewModel? = null) {
118130
}
119131
}
120132

133+
@Composable
134+
private fun GhostAccountState() {
135+
val navController = LocalNavController.current
136+
Column(
137+
verticalArrangement = Arrangement.Center,
138+
horizontalAlignment = Alignment.CenterHorizontally,
139+
modifier = Modifier.fillMaxSize()
140+
) {
141+
Spacer(modifier = Modifier.weight(1.0f))
142+
NextButton(
143+
modifier = Modifier,
144+
text = stringResource(R.string.login),
145+
enabled = true
146+
) {
147+
navController.navigate(Screen.Login.route)
148+
}
149+
Spacer(modifier = Modifier.height(16.dp))
150+
NextButton(
151+
modifier = Modifier,
152+
text = stringResource(R.string.account_set_up),
153+
enabled = true
154+
) {
155+
navController.currentBackStackEntry?.savedStateHandle?.set("isAccountClaim", true)
156+
navController.navigate(Screen.Signup.route)
157+
}
158+
Spacer(modifier = Modifier.weight(1.0f))
159+
}
160+
}
161+
121162
@Composable
122163
private fun HandleAlertState(viewModel: AccountViewModel?) {
123164
val activity = LocalContext.current as? AppStartActivity
@@ -758,6 +799,7 @@ private fun AccountScreenPreview(accountState: AccountState) {
758799
override val showProgress: StateFlow<Boolean> = MutableStateFlow(false)
759800
override val accountState: StateFlow<AccountState> = MutableStateFlow(accountState)
760801
override val alertState: StateFlow<AlertState> = MutableStateFlow(AlertState.None)
802+
override val isGhostAccount: StateFlow<Boolean> = MutableStateFlow(false)
761803
}
762804
AccountScreen(viewModel)
763805
}

mobile/src/main/java/com/windscribe/mobile/ui/preferences/account/AccountViewModel.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ abstract class AccountViewModel : ViewModel() {
8080
abstract val showProgress: StateFlow<Boolean>
8181
abstract val accountState: StateFlow<AccountState>
8282
abstract val alertState: StateFlow<AlertState>
83+
abstract val isGhostAccount: StateFlow<Boolean>
8384
open val goTo: SharedFlow<AccountGoTo> = MutableSharedFlow(replay = 0)
8485
open fun onManageAccountClicked() {}
8586
open fun onLazyLoginClicked() {}
@@ -102,6 +103,8 @@ class AccountViewModelImpl(
102103
private val _goTo: MutableSharedFlow<AccountGoTo> = MutableSharedFlow(replay = 0)
103104
override val goTo: SharedFlow<AccountGoTo> = _goTo
104105
private val logger = LoggerFactory.getLogger("basic")
106+
private val _isGhostAccount = MutableStateFlow(false)
107+
override val isGhostAccount: StateFlow<Boolean> = _isGhostAccount
105108

106109

107110
init {
@@ -111,6 +114,7 @@ class AccountViewModelImpl(
111114
private fun loadAccountInfo() {
112115
viewModelScope.launch(Dispatchers.IO) {
113116
userRepository.userInfo.collect {
117+
_isGhostAccount.value = it.isGhost
114118
val emailState = when (it.emailStatus) {
115119
User.EmailStatus.NoEmail -> NoEmail
116120
User.EmailStatus.EmailProvided -> UnconfirmedEmail(it.email ?: "")

0 commit comments

Comments
 (0)