Skip to content

Commit 841565f

Browse files
committed
chore: consolidate BottomBar messages into only using convenience methods (show{Alert/Info/Error/Success/Message})
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 6cd23de commit 841565f

18 files changed

Lines changed: 370 additions & 318 deletions

File tree

apps/flipcash/app/src/main/kotlin/com/flipcash/app/internal/ui/HomeViewModel.kt

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -75,40 +75,35 @@ internal class HomeViewModel @Inject constructor(
7575
entropy: String,
7676
onSwitchAccount: () -> Unit,
7777
onDismissed: () -> Unit) {
78-
BottomBarManager.showMessage(
79-
BottomBarManager.BottomBarMessage(
80-
title = resources.getString(R.string.title_logoutAndLoginConfirmation),
81-
subtitle = resources.getString(R.string.subtitle_logoutAndLoginConfirmation),
82-
isDismissible = false,
83-
showCancel = true,
84-
showScrim = true,
85-
actions = buildList {
86-
add(
87-
BottomBarAction(
88-
text = resources.getString(R.string.action_logIn),
89-
onClick = {
90-
viewModelScope.launch {
91-
delay(150) // wait for dismiss
92-
authManager.logoutAndSwitchAccount(entropy)
93-
.onSuccess {
94-
onSwitchAccount()
95-
}
96-
.onFailure {
97-
BottomBarManager.showError(
98-
title = resources.getString(R.string.error_title_failedToLogOut),
99-
message = resources.getString(R.string.error_description_failedToLogOut),
100-
)
101-
}
102-
}
78+
BottomBarManager.showAlert(
79+
title = resources.getString(R.string.title_logoutAndLoginConfirmation),
80+
message = resources.getString(R.string.subtitle_logoutAndLoginConfirmation),
81+
actions = buildList {
82+
add(
83+
BottomBarAction(
84+
text = resources.getString(R.string.action_logIn),
85+
onClick = {
86+
viewModelScope.launch {
87+
delay(150) // wait for dismiss
88+
authManager.logoutAndSwitchAccount(entropy)
89+
.onSuccess {
90+
onSwitchAccount()
91+
}
92+
.onFailure {
93+
BottomBarManager.showError(
94+
title = resources.getString(R.string.error_title_failedToLogOut),
95+
message = resources.getString(R.string.error_description_failedToLogOut),
96+
)
97+
}
10398
}
104-
)
99+
}
105100
)
106-
},
107-
onClose = {
108-
loginRequest = null
109-
onDismissed()
110-
}
111-
)
101+
)
102+
},
103+
onDismiss = {
104+
loginRequest = null
105+
onDismissed()
106+
}
112107
)
113108
}
114109

apps/flipcash/features/cash/src/main/kotlin/com/flipcash/app/cash/internal/CashScreenViewModel.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,9 @@ internal class CashScreenViewModel @Inject constructor(
136136

137137
val isOverBalance = enteredAmount.valueGreaterThan(tokenBalance)
138138
if (isOverBalance) {
139-
BottomBarManager.showMessage(
139+
BottomBarManager.showAlert(
140140
resources.getString(R.string.error_title_youNeedMoreCash),
141141
resources.getString(R.string.error_description_youNeedMoreCash),
142-
type = BottomBarManager.BottomBarMessageType.ERROR,
143-
showScrim = true,
144142
showCancel = false,
145143
actions = listOf(
146144
BottomBarAction(

apps/flipcash/features/contact-verification/src/main/kotlin/com/flipcash/app/contact/verification/VerificationFlowScreen.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.compose.runtime.LaunchedEffect
1010
import androidx.compose.runtime.mutableStateListOf
1111
import androidx.compose.runtime.remember
1212
import androidx.compose.ui.platform.LocalContext
13+
import androidx.compose.ui.platform.LocalResources
1314
import com.flipcash.app.contact.verification.email.EmailMagicLinkContent
1415
import com.flipcash.app.contact.verification.email.EmailVerificationContent
1516
import com.flipcash.app.contact.verification.internal.VerificationFlowIntroContent
@@ -69,27 +70,19 @@ fun VerificationFlowScreen(
6970
) {
7071
val codeNavigator = LocalCodeNavigator.current
7172
val context = LocalContext.current
72-
73+
val resources = LocalResources.current
7374
fun showSuccess() {
7475
if (includePhone) {
75-
BottomBarManager.showMessage(
76-
title = context.getString(R.string.prompt_title_phoneVerifiedSuccessfully),
77-
subtitle = context.getString(R.string.prompt_description_phoneVerifiedSuccessfully),
78-
actions = listOf(
79-
BottomBarAction(text = context.getString(android.R.string.ok))
80-
),
81-
type = BottomBarManager.BottomBarMessageType.SUCCESS,
76+
BottomBarManager.showSuccess(
77+
title = resources.getString(R.string.prompt_title_phoneVerifiedSuccessfully),
78+
message = resources.getString(R.string.prompt_description_phoneVerifiedSuccessfully),
8279
) {
8380
codeNavigator.pop()
8481
}
8582
} else {
86-
BottomBarManager.showMessage(
87-
title = context.getString(R.string.prompt_title_emailVerifiedSuccessfully),
88-
subtitle = context.getString(R.string.prompt_description_emailVerifiedSuccessfully),
89-
actions = listOf(
90-
BottomBarAction(text = context.getString(android.R.string.ok))
91-
),
92-
type = BottomBarManager.BottomBarMessageType.SUCCESS,
83+
BottomBarManager.showSuccess(
84+
title = resources.getString(R.string.prompt_title_emailVerifiedSuccessfully),
85+
message = resources.getString(R.string.prompt_description_emailVerifiedSuccessfully),
9386
) {
9487
codeNavigator.pop()
9588
}

apps/flipcash/features/discovery/src/main/kotlin/com/flipcash/app/discovery/internal/TokenDiscoveryScreenContent.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,9 @@ private fun TokenDiscoveryScreenContent(
110110
),
111111
text = stringResource(R.string.action_createYourOwnCurrency),
112112
) {
113-
BottomBarManager.showMessage(
113+
BottomBarManager.showInfo(
114114
title = resources.getString(R.string.prompt_title_notYetAvailable),
115-
subtitle = resources.getString(R.string.prompt_message_currencyCreateNotYetAvailable),
116-
type = BottomBarManager.BottomBarMessageType.INFO,
117-
actions = listOf(BottomBarAction.Ok)
115+
message = resources.getString(R.string.prompt_message_currencyCreateNotYetAvailable),
118116
)
119117
}
120118
}

apps/flipcash/features/lab/src/main/kotlin/com/flipcash/app/lab/internal/LabsScreenViewModel.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import androidx.lifecycle.viewModelScope
55
import com.flipcash.features.lab.R
66
import com.flipcash.services.controllers.ContactVerificationController
77
import com.flipcash.services.models.ContactMethod
8+
import com.flipcash.services.models.EmailVerificationError
9+
import com.flipcash.services.models.PhoneVerificationError
810
import com.flipcash.services.user.AuthState
911
import com.flipcash.services.user.UserManager
1012
import com.getcode.manager.BottomBarAction
@@ -34,7 +36,7 @@ class LabsScreenViewModel @Inject constructor(
3436
fun unlinkEmail() = viewModelScope.launch {
3537
val email = userManager.profile?.verifiedEmailAddress
3638
if (email == null) {
37-
BottomBarManager.showError(
39+
BottomBarManager.showAlert(
3840
title = resources.getString(R.string.error_title_failedToUnlinkEmail),
3941
message = resources.getString(R.string.error_description_failedToUnlinkEmailNonePresent)
4042
)
@@ -48,21 +50,17 @@ class LabsScreenViewModel @Inject constructor(
4850
message = resources.getString(R.string.error_description_failedToUnlinkEmail)
4951
)
5052
}.onSuccess {
51-
BottomBarManager.showMessage(
53+
BottomBarManager.showSuccess(
5254
title = resources.getString(R.string.prompt_title_emailUnlinked),
53-
subtitle = resources.getString(R.string.prompt_description_emailUnlinked),
54-
actions = listOf(
55-
BottomBarAction(text = resources.getString(android.R.string.ok))
56-
),
57-
type = BottomBarManager.BottomBarMessageType.SUCCESS,
55+
message = resources.getString(R.string.prompt_description_emailUnlinked),
5856
)
5957
}
6058
}
6159

6260
fun unlinkPhone() = viewModelScope.launch {
6361
val phone = userManager.profile?.verifiedPhoneNumber
6462
if (phone == null) {
65-
BottomBarManager.showError(
63+
BottomBarManager.showAlert(
6664
title = resources.getString(R.string.error_title_failedToUnlinkPhone),
6765
message = resources.getString(R.string.error_description_failedToUnlinkPhoneNonePresent)
6866
)
@@ -76,13 +74,9 @@ class LabsScreenViewModel @Inject constructor(
7674
message = resources.getString(R.string.error_description_failedToUnlinkPhone)
7775
)
7876
}.onSuccess {
79-
BottomBarManager.showMessage(
77+
BottomBarManager.showSuccess(
8078
title = resources.getString(R.string.prompt_title_phoneUnlinked),
81-
subtitle = resources.getString(R.string.prompt_description_phoneUnlinked),
82-
actions = listOf(
83-
BottomBarAction(text = resources.getString(android.R.string.ok))
84-
),
85-
type = BottomBarManager.BottomBarMessageType.SUCCESS,
79+
message = resources.getString(R.string.prompt_description_phoneUnlinked),
8680
)
8781
}
8882
}

apps/flipcash/features/login/src/main/kotlin/com/flipcash/app/login/internal/AccessKeyScreenContent.kt

Lines changed: 28 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import androidx.compose.ui.draw.scale
3737
import androidx.compose.ui.graphics.asImageBitmap
3838
import androidx.compose.ui.layout.ContentScale
3939
import androidx.compose.ui.platform.LocalContext
40+
import androidx.compose.ui.platform.LocalResources
4041
import androidx.compose.ui.res.stringResource
4142
import androidx.compose.ui.text.style.TextAlign
4243
import androidx.compose.ui.tooling.preview.Preview
@@ -69,6 +70,7 @@ import kotlinx.coroutines.launch
6970
internal fun AccessKeyScreen(viewModel: LoginAccessKeyViewModel, onCompleted: (requiresIap: Boolean) -> Unit) {
7071
val navigator = LocalCodeNavigator.current
7172
val context = LocalContext.current
73+
val resources = LocalResources.current
7274
val dataState by viewModel.uiFlow.collectAsState()
7375

7476
val composeScope = rememberCoroutineScope()
@@ -81,12 +83,12 @@ internal fun AccessKeyScreen(viewModel: LoginAccessKeyViewModel, onCompleted: (r
8183

8284
if (!isStoragePermissionGranted) {
8385
BottomBarManager.showError(
84-
title = context.getString(R.string.error_title_failedToSave),
85-
message = context.getString(R.string.error_description_failedToSave),
86+
title = resources.getString(R.string.error_title_failedToSave),
87+
message = resources.getString(R.string.error_description_failedToSave),
8688
actions = listOf(
8789
BottomBarAction.Ok,
8890
BottomBarAction(
89-
text = context.getString(R.string.action_openSettings),
91+
text = resources.getString(R.string.action_openSettings),
9092
style = BottomBarManager.BottomBarButtonStyle.Filled50,
9193
onClick = { context.launchAppSettings() }
9294
)
@@ -149,6 +151,7 @@ private fun AccessKeyScreenContent(
149151
onExit: () -> Unit,
150152
) {
151153
val context = LocalContext.current
154+
val resources = LocalResources.current
152155

153156
var buttonHeight by remember {
154157
mutableStateOf(0.dp)
@@ -196,19 +199,16 @@ private fun AccessKeyScreenContent(
196199
CodeButton(
197200
modifier = Modifier.fillMaxWidth(),
198201
onClick = {
199-
BottomBarManager.showMessage(
200-
BottomBarManager.BottomBarMessage(
201-
title = context.getString(R.string.prompt_title_wroteThemDown),
202-
subtitle = context
203-
.getString(R.string.prompt_description_wroteThemDown),
204-
showScrim = true,
205-
showCancel = true,
206-
actions = listOf(
207-
BottomBarAction(
208-
text = context
209-
.getString(R.string.action_wroteThemDownInstead),
210-
onClick = onSkip
211-
)
202+
BottomBarManager.showAlert(
203+
title = resources.getString(R.string.prompt_title_wroteThemDown),
204+
message = resources
205+
.getString(R.string.prompt_description_wroteThemDown),
206+
showCancel = true,
207+
actions = listOf(
208+
BottomBarAction(
209+
text = resources
210+
.getString(R.string.action_wroteThemDownInstead),
211+
onClick = onSkip
212212
)
213213
)
214214
)
@@ -280,22 +280,18 @@ private fun AccessKeyScreenContent(
280280

281281

282282
BackHandler {
283-
BottomBarManager.showMessage(
284-
BottomBarManager.BottomBarMessage(
285-
title = context.getString(R.string.prompt_title_exitAccountCreation),
286-
subtitle = context
287-
.getString(R.string.prompt_description_exitAccountCreation),
288-
showScrim = true,
289-
showCancel = true,
290-
actions = listOf(
291-
BottomBarAction(
292-
text = context
293-
.getString(R.string.action_exit),
294-
onClick = onExit
295-
)
296-
),
297-
type = BottomBarManager.BottomBarMessageType.DESTRUCTIVE,
298-
)
283+
BottomBarManager.showAlert(
284+
title = resources.getString(R.string.prompt_title_exitAccountCreation),
285+
message = resources
286+
.getString(R.string.prompt_description_exitAccountCreation),
287+
showCancel = true,
288+
actions = listOf(
289+
BottomBarAction(
290+
text = resources
291+
.getString(R.string.action_exit),
292+
onClick = onExit
293+
)
294+
),
299295
)
300296
}
301297

apps/flipcash/features/login/src/main/kotlin/com/flipcash/app/login/seed/SeedInputViewModel.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import com.flipcash.services.controllers.AccountController
1010
import com.flipcash.services.internal.model.account.UserFlags
1111
import com.flipcash.services.user.UserManager
1212
import com.getcode.crypt.MnemonicPhrase
13+
import com.getcode.manager.BottomBarAction
1314
import com.getcode.manager.BottomBarManager
1415
import com.getcode.navigation.core.CodeNavigator
1516
import com.getcode.opencode.managers.MnemonicManager
@@ -183,16 +184,20 @@ class SeedInputViewModel @Inject constructor(
183184
}
184185

185186
private fun showError(navigator: CodeNavigator) {
186-
BottomBarManager.showMessage(
187-
BottomBarManager.BottomBarMessage(
188-
title = resources.getString(R.string.prompt_title_notFlipcashAccount),
189-
subtitle = resources.getString(R.string.prompt_description_notFlipcashAccount),
190-
positiveText = resources.getString(R.string.action_createNewFlipcashAccount),
191-
tertiaryText = resources.getString(R.string.action_tryDifferentFlipcashAccount),
192-
onPositive = {
187+
BottomBarManager.showAlert(
188+
title = resources.getString(R.string.prompt_title_notFlipcashAccount),
189+
message = resources.getString(R.string.prompt_description_notFlipcashAccount),
190+
actions = listOf(
191+
BottomBarAction(
192+
resources.getString(R.string.action_createNewFlipcashAccount)
193+
) {
193194
navigator.replaceAll(AppRoute.Onboarding.Login())
194-
}
195-
)
195+
},
196+
BottomBarAction(
197+
resources.getString(R.string.action_tryDifferentFlipcashAccount),
198+
style = BottomBarManager.BottomBarButtonStyle.Text
199+
)
200+
),
196201
)
197202
}
198203
}

apps/flipcash/features/menu/src/main/kotlin/com/flipcash/app/menu/internal/MenuScreenViewModel.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import com.getcode.manager.BottomBarManager
2323
import com.getcode.opencode.managers.MnemonicManager
2424
import com.getcode.util.resources.ResourceHelper
2525
import com.flipcash.libs.coroutines.DispatcherProvider
26+
import com.getcode.manager.BottomBarAction
2627
import com.getcode.view.BaseViewModel2
2728
import dagger.hilt.android.lifecycle.HiltViewModel
2829
import kotlinx.coroutines.delay
@@ -189,14 +190,11 @@ internal class MenuScreenViewModel @Inject constructor(
189190
eventFlow
190191
.filterIsInstance<Event.OnLogOutClicked>()
191192
.onEach {
192-
BottomBarManager.showMessage(
193-
BottomBarManager.BottomBarMessage(
194-
title = resources.getString(R.string.prompt_title_logout),
195-
subtitle = resources.getString(R.string.prompt_description_logout),
196-
showScrim = true,
197-
positiveText = resources.getString(R.string.action_logout),
198-
tertiaryText = resources.getString(R.string.action_cancel),
199-
onPositive = {
193+
BottomBarManager.showAlert(
194+
title = resources.getString(R.string.prompt_title_logout),
195+
message = resources.getString(R.string.prompt_description_logout),
196+
actions = listOf(
197+
BottomBarAction(resources.getString(R.string.action_logout)) {
200198
viewModelScope.launch {
201199
delay(150) // wait for dismiss
202200
authManager.logout()
@@ -210,8 +208,9 @@ internal class MenuScreenViewModel @Inject constructor(
210208
)
211209
}
212210
}
213-
}
214-
)
211+
},
212+
),
213+
showCancel = true,
215214
)
216215
}.launchIn(viewModelScope)
217216
}

0 commit comments

Comments
 (0)