Skip to content

Commit f50889f

Browse files
ovitrifclaude
andcommitted
refactor: prettify Toast and Toaster APIs
- Add ToastText() factory constructors (invoke operators) - Remove redundant @stable from ToastType enum and value classes - Rename titleRes/bodyRes → title/body in @stringres overloads - Rename warning() → warn() across all overloads - Update all call sites for the API changes Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 84c5eee commit f50889f

23 files changed

Lines changed: 109 additions & 107 deletions

app/src/main/java/to/bitkit/models/Toast.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ data class Toast(
1818
}
1919
}
2020

21-
@Stable
2221
enum class ToastType { SUCCESS, INFO, LIGHTNING, WARNING, ERROR }

app/src/main/java/to/bitkit/models/ToastText.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@ import androidx.compose.ui.res.stringResource
99
@Stable
1010
sealed interface ToastText {
1111
@JvmInline
12-
@Stable
1312
value class Resource(@StringRes val resId: Int) : ToastText
1413

1514
@JvmInline
16-
@Stable
1715
value class Literal(val value: String) : ToastText
16+
17+
companion object {
18+
operator fun invoke(value: String): ToastText = Literal(value)
19+
operator fun invoke(@StringRes resId: Int): ToastText = Resource(resId)
20+
}
1821
}
1922

2023
@Composable

app/src/main/java/to/bitkit/ui/components/IsOnlineTracker.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ fun IsOnlineTracker(
3030
when (connectivityState) {
3131
ConnectivityState.CONNECTED -> {
3232
toaster.success(
33-
titleRes = R.string.other__connection_back_title,
34-
bodyRes = R.string.other__connection_back_msg,
33+
title = R.string.other__connection_back_title,
34+
body = R.string.other__connection_back_msg,
3535
)
3636
}
3737

3838
ConnectivityState.DISCONNECTED -> {
39-
toaster.warning(
40-
titleRes = R.string.other__connection_issue,
41-
bodyRes = R.string.other__connection_issue_explain,
39+
toaster.warn(
40+
title = R.string.other__connection_issue,
41+
body = R.string.other__connection_issue_explain,
4242
)
4343
}
4444

app/src/main/java/to/bitkit/ui/screens/recovery/RecoveryMnemonicViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class RecoveryMnemonicViewModel @Inject constructor(
4242
isLoading = false,
4343
)
4444
}
45-
toaster.error(titleRes = R.string.security__mnemonic_load_error)
45+
toaster.error(title = R.string.security__mnemonic_load_error)
4646
return@launch
4747
}
4848

app/src/main/java/to/bitkit/ui/screens/recovery/RecoveryViewModel.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class RecoveryViewModel @Inject constructor(
7474
)
7575
}
7676
toaster.error(
77-
titleRes = R.string.common__error,
78-
bodyRes = R.string.other__logs_export_error,
77+
title = R.string.common__error,
78+
body = R.string.other__logs_export_error,
7979
)
8080
}
8181
)
@@ -98,8 +98,8 @@ class RecoveryViewModel @Inject constructor(
9898
Logger.error("Failed to open support links", fallbackError, context = TAG)
9999
viewModelScope.launch {
100100
toaster.error(
101-
titleRes = R.string.common__error,
102-
bodyRes = R.string.settings__support__link_error,
101+
title = R.string.common__error,
102+
body = R.string.settings__support__link_error,
103103
)
104104
}
105105
}
@@ -120,8 +120,8 @@ class RecoveryViewModel @Inject constructor(
120120
toaster.error(error)
121121
}.onSuccess {
122122
toaster.success(
123-
titleRes = R.string.security__wiped_title,
124-
bodyRes = R.string.security__wiped_message,
123+
title = R.string.security__wiped_title,
124+
body = R.string.security__wiped_message,
125125
)
126126
}
127127
}

app/src/main/java/to/bitkit/ui/screens/scanner/QrScanningScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ fun QrScanningScreen(
151151
Logger.error("Failed to scan QR code", error)
152152
app.toast(
153153
type = ToastType.ERROR,
154-
titleRes = R.string.other__qr_error_header,
155-
bodyRes = R.string.other__qr_error_text,
154+
title = R.string.other__qr_error_header,
155+
body = R.string.other__qr_error_text,
156156
)
157157
}
158158
}
@@ -257,8 +257,8 @@ private fun handlePaste(
257257
if (clipboard.isNullOrBlank()) {
258258
app.toast(
259259
type = ToastType.WARNING,
260-
titleRes = R.string.wallet__send_clipboard_empty_title,
261-
bodyRes = R.string.wallet__send_clipboard_empty_text,
260+
title = R.string.wallet__send_clipboard_empty_title,
261+
body = R.string.wallet__send_clipboard_empty_text,
262262
)
263263
}
264264
setScanResult(clipboard)

app/src/main/java/to/bitkit/ui/screens/transfer/SavingsProgressScreen.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ fun SavingsProgressScreen(
7070
// All channels are trusted peers - show error and navigate back immediately
7171
app.toast(
7272
type = ToastType.ERROR,
73-
titleRes = R.string.lightning__close_error,
74-
bodyRes = R.string.lightning__close_error_msg,
73+
title = R.string.lightning__close_error,
74+
body = R.string.lightning__close_error_msg,
7575
)
7676
onTransferUnavailable()
7777
} else {
@@ -81,8 +81,8 @@ fun SavingsProgressScreen(
8181
onTransferUnavailable = {
8282
app.toast(
8383
type = ToastType.ERROR,
84-
titleRes = R.string.lightning__close_error,
85-
bodyRes = R.string.lightning__close_error_msg,
84+
title = R.string.lightning__close_error,
85+
body = R.string.lightning__close_error_msg,
8686
)
8787
onTransferUnavailable()
8888
},

app/src/main/java/to/bitkit/ui/screens/transfer/external/ExternalNodeViewModel.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class ExternalNodeViewModel @Inject constructor(
7575
setEffect(SideEffect.ConnectionSuccess)
7676
} else {
7777
toaster.error(
78-
titleRes = R.string.lightning__error_add_title,
79-
bodyRes = R.string.lightning__error_add,
78+
title = R.string.lightning__error_add_title,
79+
body = R.string.lightning__error_add,
8080
)
8181
}
8282
}
@@ -89,7 +89,7 @@ class ExternalNodeViewModel @Inject constructor(
8989
if (result.isSuccess) {
9090
_uiState.update { it.copy(peer = result.getOrNull()) }
9191
} else {
92-
toaster.error(titleRes = R.string.lightning__error_add_uri)
92+
toaster.error(title = R.string.lightning__error_add_uri)
9393
}
9494
}
9595
}
@@ -136,8 +136,8 @@ class ExternalNodeViewModel @Inject constructor(
136136
val feeRate = _uiState.value.customFeeRate ?: 0u
137137
if (feeRate == 0u) {
138138
toaster.info(
139-
titleRes = R.string.wallet__min_possible_fee_rate,
140-
bodyRes = R.string.wallet__min_possible_fee_rate_msg,
139+
title = R.string.wallet__min_possible_fee_rate,
140+
body = R.string.wallet__min_possible_fee_rate_msg,
141141
)
142142
return false
143143
}

app/src/main/java/to/bitkit/ui/screens/transfer/external/LnurlChannelViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ class LnurlChannelViewModel @Inject constructor(
7070
lightningRepo.requestLnurlChannel(callback = params.callback, k1 = params.k1, nodeId = nodeId)
7171
.onSuccess {
7272
toaster.success(
73-
titleRes = R.string.other__lnurl_channel_success_title,
74-
bodyRes = R.string.other__lnurl_channel_success_msg_no_peer,
73+
title = R.string.other__lnurl_channel_success_title,
74+
body = R.string.other__lnurl_channel_success_msg_no_peer,
7575
)
7676
_uiState.update { it.copy(isConnected = true) }
7777
}.onFailure { error ->

app/src/main/java/to/bitkit/ui/screens/wallets/activity/ActivityDetailScreen.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@ fun ActivityDetailScreen(
251251
onSuccess = {
252252
app.toast(
253253
type = ToastType.SUCCESS,
254-
titleRes = R.string.wallet__boost_success_title,
255-
bodyRes = R.string.wallet__boost_success_msg,
254+
title = R.string.wallet__boost_success_title,
255+
body = R.string.wallet__boost_success_msg,
256256
testTag = "BoostSuccessToast"
257257
)
258258
listViewModel.resync()
@@ -261,24 +261,24 @@ fun ActivityDetailScreen(
261261
onFailure = {
262262
app.toast(
263263
type = ToastType.ERROR,
264-
titleRes = R.string.wallet__boost_error_title,
265-
bodyRes = R.string.wallet__boost_error_msg,
264+
title = R.string.wallet__boost_error_title,
265+
body = R.string.wallet__boost_error_msg,
266266
testTag = "BoostFailureToast"
267267
)
268268
detailViewModel.onDismissBoostSheet()
269269
},
270270
onMaxFee = {
271271
app.toast(
272272
type = ToastType.ERROR,
273-
titleRes = R.string.wallet__send_fee_error,
274-
bodyRes = R.string.wallet__send_fee_error_max,
273+
title = R.string.wallet__send_fee_error,
274+
body = R.string.wallet__send_fee_error_max,
275275
)
276276
},
277277
onMinFee = {
278278
app.toast(
279279
type = ToastType.ERROR,
280-
titleRes = R.string.wallet__send_fee_error,
281-
bodyRes = R.string.wallet__send_fee_error_min,
280+
title = R.string.wallet__send_fee_error,
281+
body = R.string.wallet__send_fee_error_min,
282282
)
283283
}
284284
)

0 commit comments

Comments
 (0)