Skip to content

Commit d71162e

Browse files
committed
chore(fc): add delete account action to balance tab
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent 6c4812a commit d71162e

File tree

8 files changed

+87
-44
lines changed

8 files changed

+87
-44
lines changed

flipchatApp/src/main/kotlin/xyz/flipchat/app/auth/AuthManager.kt

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -252,35 +252,9 @@ class AuthManager @Inject constructor(
252252
}.map { it.first }
253253
}
254254

255-
suspend fun deleteAndLogout(context: Context, onComplete: () -> Unit = {}) {
255+
suspend fun deleteAndLogout(context: Context): Result<Unit> {
256256
//todo: add account deletion
257-
logout(context, onComplete)
258-
}
259-
260-
suspend fun logout(context: Context, onComplete: () -> Unit = {}) {
261-
coroutineScope {
262-
val token = AccountUtils.getToken(context)
263-
when (token) {
264-
is TokenResult.Account -> {
265-
AccountUtils.removeAccounts(context)
266-
.doOnSuccess { res: Boolean ->
267-
if (res) {
268-
launch {
269-
clearToken()
270-
}
271-
onComplete()
272-
}
273-
}
274-
.subscribe()
275-
}
276-
277-
is TokenResult.Code -> {
278-
onComplete()
279-
}
280-
281-
null -> Unit
282-
}
283-
}
257+
return logout(context)
284258
}
285259

286260
suspend fun logout(context: Context): Result<Unit> {

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/balance/BalanceScreen.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import kotlinx.parcelize.Parcelize
4949
import xyz.flipchat.services.user.AuthState
5050

5151
@Parcelize
52-
data object BalanceScreen : Screen, Parcelable {
52+
class BalanceScreen : Screen, Parcelable {
5353

5454
@IgnoredOnParcel
5555
override val key: ScreenKey = uniqueScreenKey
@@ -97,8 +97,6 @@ fun BalanceContent(
9797

9898
val canClickBalance = false
9999

100-
val context = LocalContext.current
101-
102100
LazyColumn(
103101
modifier = Modifier
104102
.fillMaxWidth(),

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/home/tabs/CashTab.kt

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,40 @@
11
package xyz.flipchat.app.features.home.tabs
22

3+
import androidx.compose.foundation.layout.Box
34
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.fillMaxWidth
6+
import androidx.compose.foundation.layout.navigationBarsPadding
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.material.Scaffold
49
import androidx.compose.runtime.Composable
10+
import androidx.compose.runtime.rememberCoroutineScope
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.platform.LocalContext
513
import androidx.compose.ui.res.painterResource
614
import androidx.compose.ui.res.stringResource
715
import cafe.adriel.voyager.core.registry.ScreenRegistry
816
import cafe.adriel.voyager.core.screen.ScreenKey
917
import cafe.adriel.voyager.core.screen.uniqueScreenKey
18+
import cafe.adriel.voyager.hilt.getViewModel
1019
import cafe.adriel.voyager.navigator.Navigator
1120
import cafe.adriel.voyager.navigator.tab.TabOptions
21+
import com.getcode.manager.BottomBarManager
1222
import com.getcode.navigation.NavScreenProvider
23+
import com.getcode.navigation.core.LocalCodeNavigator
1324
import com.getcode.navigation.screens.ChildNavTab
25+
import com.getcode.theme.CodeTheme
1426
import com.getcode.ui.components.AppBarWithTitle
27+
import com.getcode.ui.theme.ButtonState
28+
import com.getcode.ui.theme.CodeButton
29+
import com.getcode.ui.theme.CodeScaffold
30+
import com.getcode.ui.utils.addIf
31+
import com.getcode.ui.utils.getActivity
32+
import kotlinx.coroutines.delay
33+
import kotlinx.coroutines.launch
1534
import xyz.flipchat.app.R
35+
import xyz.flipchat.app.features.chat.openChatDirectiveBottomModal
36+
import xyz.flipchat.app.features.home.HomeViewModel
37+
import xyz.flipchat.app.features.settings.SettingsViewModel
1638

1739
internal object CashTab : ChildNavTab {
1840
override val key: ScreenKey = uniqueScreenKey
@@ -28,11 +50,50 @@ internal object CashTab : ChildNavTab {
2850

2951
@Composable
3052
override fun Content() {
53+
val viewModel = getViewModel<SettingsViewModel>()
54+
val context = LocalContext.current
55+
val composeScope = rememberCoroutineScope()
56+
val navigator = LocalCodeNavigator.current
3157
Column {
3258
AppBarWithTitle(
3359
title = options.title,
3460
)
35-
Navigator(ScreenRegistry.get(NavScreenProvider.Balance))
61+
CodeScaffold(
62+
bottomBar = {
63+
CodeButton(
64+
modifier = Modifier
65+
.fillMaxWidth()
66+
.padding(horizontal = CodeTheme.dimens.inset)
67+
.padding(bottom = CodeTheme.dimens.grid.x3),
68+
buttonState = ButtonState.Subtle,
69+
text = stringResource(R.string.action_deleteMyAccount)
70+
) {
71+
BottomBarManager.showMessage(
72+
BottomBarManager.BottomBarMessage(
73+
title = context.getString(R.string.prompt_title_deleteAccount),
74+
subtitle = context
75+
.getString(R.string.prompt_description_deleteAccount),
76+
positiveText = context.getString(R.string.action_permanentlyDeleteAccount),
77+
tertiaryText = context.getString(R.string.action_cancel),
78+
onPositive = {
79+
composeScope.launch {
80+
delay(150)
81+
context.getActivity()?.let {
82+
viewModel.deleteAccount(it) {
83+
navigator.replaceAll(ScreenRegistry.get(NavScreenProvider.Login.Home()))
84+
}
85+
}
86+
}
87+
}
88+
)
89+
)
90+
}
91+
},
92+
) { padding ->
93+
Box(modifier = Modifier.padding(padding)) {
94+
Navigator(ScreenRegistry.get(NavScreenProvider.Balance))
95+
}
96+
}
3697
}
3798
}
3899
}

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/login/accesskey/SeedInputViewModel.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ class SeedInputViewModel @Inject constructor(
9696
}
9797
}
9898

99-
suspend fun logout(activity: Activity, onComplete: () -> Unit = {}) =
100-
authManager.logout(activity, onComplete)
101-
10299
@SuppressLint("CheckResult")
103100
fun performLogin(navigator: CodeNavigator, entropyB64: String, deeplink: Boolean = false) {
104101
viewModelScope.launch {

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/settings/SettingsScreen.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,14 @@ class SettingsScreen : Screen, Parcelable {
6262
),
6363
bottomBar = {
6464
LogoutButton {
65-
composeScope.launch {
66-
delay(150) // wait for dismiss
67-
context.getActivity()?.let {
68-
viewModel.logout(it) {
69-
navigator.replaceAll(ScreenRegistry.get(NavScreenProvider.Login.Home()))
70-
}
71-
}
72-
}
65+
// composeScope.launch {
66+
// delay(150) // wait for dismiss
67+
// context.getActivity()?.let {
68+
// viewModel.logout(it) {
69+
// navigator.replaceAll(ScreenRegistry.get(NavScreenProvider.Login.Home()))
70+
// }
71+
// }
72+
// }
7373
}
7474
}
7575
) { padding ->

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/settings/SettingsViewModel.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class SettingsViewModel @Inject constructor(
4747
}
4848
}
4949

50+
fun deleteAccount(activity: Activity, onComplete: () -> Unit) = viewModelScope.launch {
51+
authManager.deleteAndLogout(activity)
52+
.onSuccess {
53+
chatsController.closeEventStream()
54+
onComplete()
55+
}
56+
}
57+
5058
internal companion object {
5159
val updateStateForEvent: (Event) -> ((State) -> State) = { event ->
5260
when (event) {

flipchatApp/src/main/kotlin/xyz/flipchat/app/ui/navigation/AppScreenContent.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fun AppScreenContent(content: @Composable () -> Unit) {
6363
}
6464

6565
register<NavScreenProvider.Balance> {
66-
BalanceScreen
66+
BalanceScreen()
6767
}
6868

6969
register<NavScreenProvider.AppHomeScreen> {

flipchatApp/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,9 @@
170170
<string name="subtitle_finalizeAccountCreation">Accounts on Flipchat must be purchased for %1$s to reduce spam</string>
171171
<string name="action_changeCoverCharge">Change Cover Charge</string>
172172
<string name="action_leaveRoom">Leave Room</string>
173+
174+
<string name="action_deleteMyAccount">Delete My Account</string>
175+
<string name="prompt_title_deleteAccount">Permanently Delete Account?</string>
176+
<string name="prompt_description_deleteAccount">This will permanently delete your Flipchat account</string>
177+
<string name="action_permanentlyDeleteAccount">Permanently Delete My Account</string>
173178
</resources>

0 commit comments

Comments
 (0)