Skip to content

Commit f39004e

Browse files
authored
Merge pull request #427 from synonymdev/feat/notifications-settings
Notifications settings
2 parents 69860bd + 5d8516d commit f39004e

File tree

9 files changed

+241
-67
lines changed

9 files changed

+241
-67
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ enum class Suggestion(
101101
icon = R.drawable.transfer,
102102
dismissible = false,
103103
),
104+
NOTIFICATIONS(
105+
title = R.string.cards__notifications__title,
106+
description = R.string.cards__notifications__description,
107+
color = Colors.Purple24,
108+
icon = R.drawable.bell,
109+
dismissible = true,
110+
),
104111
}
105112

106113
fun String.toSuggestionOrNull() = Suggestion.entries.firstOrNull { it.name == this }

app/src/main/java/to/bitkit/ui/components/settings/SettingsSwitchRow.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import androidx.compose.foundation.layout.height
88
import androidx.compose.foundation.layout.padding
99
import androidx.compose.material3.HorizontalDivider
1010
import androidx.compose.material3.Switch
11+
import androidx.compose.material3.SwitchColors
1112
import androidx.compose.runtime.Composable
1213
import androidx.compose.ui.Alignment
1314
import androidx.compose.ui.Modifier
@@ -25,6 +26,7 @@ fun SettingsSwitchRow(
2526
isChecked: Boolean,
2627
onClick: () -> Unit,
2728
modifier: Modifier = Modifier,
29+
colors: SwitchColors = AppSwitchDefaults.colors,
2830
) {
2931
Column(
3032
modifier = modifier.height(52.dp)
@@ -42,7 +44,7 @@ fun SettingsSwitchRow(
4244
Switch(
4345
checked = isChecked,
4446
onCheckedChange = null, // handled by parent
45-
colors = AppSwitchDefaults.colors,
47+
colors = colors,
4648
)
4749
}
4850
HorizontalDivider(color = Colors.White10)

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ import androidx.compose.runtime.setValue
2121
import androidx.compose.ui.Alignment
2222
import androidx.compose.ui.Modifier
2323
import androidx.compose.ui.layout.ContentScale
24+
import androidx.compose.ui.platform.LocalContext
2425
import androidx.compose.ui.platform.testTag
2526
import androidx.compose.ui.res.painterResource
2627
import androidx.compose.ui.res.stringResource
2728
import androidx.compose.ui.tooling.preview.Preview
2829
import androidx.compose.ui.unit.dp
30+
import androidx.hilt.navigation.compose.hiltViewModel
2931
import androidx.lifecycle.compose.collectAsStateWithLifecycle
3032
import com.synonym.bitkitcore.BtBolt11InvoiceState
3133
import com.synonym.bitkitcore.BtOrderState
@@ -50,12 +52,17 @@ import to.bitkit.ui.components.LightningChannel
5052
import to.bitkit.ui.components.PrimaryButton
5153
import to.bitkit.ui.components.SwipeToConfirm
5254
import to.bitkit.ui.components.VerticalSpacer
55+
import to.bitkit.ui.components.settings.SettingsSwitchRow
5356
import to.bitkit.ui.scaffold.AppTopBar
5457
import to.bitkit.ui.scaffold.CloseNavIcon
5558
import to.bitkit.ui.scaffold.ScreenColumn
59+
import to.bitkit.ui.theme.AppSwitchDefaults
5660
import to.bitkit.ui.theme.AppThemeSurface
5761
import to.bitkit.ui.theme.Colors
62+
import to.bitkit.ui.utils.NotificationUtils
63+
import to.bitkit.ui.utils.RequestNotificationPermissions
5864
import to.bitkit.ui.utils.withAccent
65+
import to.bitkit.viewmodels.SettingsViewModel
5966
import to.bitkit.viewmodels.TransferViewModel
6067

6168
@Composable
@@ -66,11 +73,27 @@ fun SpendingConfirmScreen(
6673
onLearnMoreClick: () -> Unit = {},
6774
onAdvancedClick: () -> Unit = {},
6875
onConfirm: () -> Unit = {},
76+
settingsViewModel: SettingsViewModel = hiltViewModel(),
6977
) {
78+
val context = LocalContext.current
79+
7080
val state by viewModel.spendingUiState.collectAsStateWithLifecycle()
71-
val order = state.order ?: return
81+
82+
val order = state.order ?: run {
83+
onCloseClick()
84+
return
85+
}
7286
val isAdvanced = state.isAdvanced
7387

88+
val notificationsGranted by settingsViewModel.notificationsGranted.collectAsStateWithLifecycle()
89+
90+
RequestNotificationPermissions(
91+
onPermissionChange = { granted ->
92+
settingsViewModel.setNotificationPreference(granted)
93+
},
94+
showPermissionDialog = false
95+
)
96+
7497
Content(
7598
onBackClick = onBackClick,
7699
onCloseClick = onCloseClick,
@@ -80,6 +103,10 @@ fun SpendingConfirmScreen(
80103
onUseDefaultLspBalanceClick = { viewModel.onUseDefaultLspBalanceClick() },
81104
onTransferToSpendingConfirm = { order -> viewModel.onTransferToSpendingConfirm(order) },
82105
order = order,
106+
hasNotificationPermission = notificationsGranted,
107+
onSwitchClick = {
108+
NotificationUtils.openNotificationSettings(context)
109+
},
83110
isAdvanced = isAdvanced
84111
)
85112
}
@@ -92,6 +119,8 @@ private fun Content(
92119
onAdvancedClick: () -> Unit,
93120
onConfirm: () -> Unit,
94121
onUseDefaultLspBalanceClick: () -> Unit,
122+
onSwitchClick: () -> Unit,
123+
hasNotificationPermission: Boolean,
95124
onTransferToSpendingConfirm: (IBtOrder) -> Unit,
96125
order: IBtOrder,
97126
isAdvanced: Boolean,
@@ -174,9 +203,20 @@ private fun Content(
174203
showLabels = true,
175204
modifier = Modifier.testTag("SpendingConfirmChannel")
176205
)
206+
207+
VerticalSpacer(16.dp)
177208
}
178209

179-
VerticalSpacer(16.dp)
210+
SettingsSwitchRow(
211+
title = "Set up in background",
212+
isChecked = hasNotificationPermission,
213+
colors = AppSwitchDefaults.colorsPurple,
214+
onClick = onSwitchClick,
215+
modifier = Modifier.fillMaxWidth()
216+
)
217+
218+
VerticalSpacer(31.dp)
219+
180220
Row(horizontalArrangement = Arrangement.spacedBy(16.dp)) {
181221
PrimaryButton(
182222
text = stringResource(R.string.common__learn_more),
@@ -298,6 +338,8 @@ private fun Preview() {
298338
updatedAt = "2025-07-28T08:29:03Z",
299339
createdAt = "2025-07-28T08:29:03Z"
300340
),
341+
onSwitchClick = {},
342+
hasNotificationPermission = true,
301343
isAdvanced = false
302344
)
303345
}
@@ -374,6 +416,8 @@ private fun Preview2() {
374416
updatedAt = "2025-07-28T08:29:03Z",
375417
createdAt = "2025-07-28T08:29:03Z"
376418
),
419+
onSwitchClick = {},
420+
hasNotificationPermission = true,
377421
isAdvanced = true
378422
)
379423
}
@@ -450,6 +494,8 @@ private fun Preview3() {
450494
updatedAt = "2025-07-28T08:29:03Z",
451495
createdAt = "2025-07-28T08:29:03Z"
452496
),
497+
onSwitchClick = {},
498+
hasNotificationPermission = false,
453499
isAdvanced = false
454500
)
455501
}
@@ -526,6 +572,8 @@ private fun Preview4() {
526572
updatedAt = "2025-07-28T08:29:03Z",
527573
createdAt = "2025-07-28T08:29:03Z"
528574
),
575+
onSwitchClick = {},
576+
hasNotificationPermission = true,
529577
isAdvanced = true
530578
)
531579
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,17 +128,17 @@ fun HomeScreen(
128128
activityListViewModel: ActivityListViewModel,
129129
homeViewModel: HomeViewModel = hiltViewModel(),
130130
) {
131+
val context = LocalContext.current
131132
val hasSeenTransferIntro by settingsViewModel.hasSeenTransferIntro.collectAsStateWithLifecycle()
132133
val hasSeenShopIntro by settingsViewModel.hasSeenShopIntro.collectAsStateWithLifecycle()
133134
val hasSeenProfileIntro by settingsViewModel.hasSeenProfileIntro.collectAsStateWithLifecycle()
134135
val hasSeenWidgetsIntro: Boolean by settingsViewModel.hasSeenWidgetsIntro.collectAsStateWithLifecycle()
136+
val bgPaymentsIntroSeen: Boolean by settingsViewModel.bgPaymentsIntroSeen.collectAsStateWithLifecycle()
135137
val quickPayIntroSeen by settingsViewModel.quickPayIntroSeen.collectAsStateWithLifecycle()
136138
val latestActivities by activityListViewModel.latestActivities.collectAsStateWithLifecycle()
137139

138140
val homeUiState by homeViewModel.uiState.collectAsStateWithLifecycle()
139141

140-
val context = LocalContext.current
141-
142142
LaunchedEffect(Unit) {
143143
appViewModel.checkTimedSheets()
144144
}
@@ -239,6 +239,13 @@ fun HomeScreen(
239239
Suggestion.TRANSFER_CLOSING_CHANNEL -> Unit
240240
Suggestion.LIGHTNING_SETTING_UP -> rootNavController.navigate(Routes.SettingUp)
241241
Suggestion.LIGHTNING_READY -> Unit
242+
Suggestion.NOTIFICATIONS -> {
243+
if (bgPaymentsIntroSeen) {
244+
rootNavController.navigate(Routes.BackgroundPaymentsSettings)
245+
} else {
246+
rootNavController.navigate(Routes.BackgroundPaymentsIntro)
247+
}
248+
}
242249
}
243250
},
244251
onClickAddWidget = {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ class HomeViewModel @Inject constructor(
233233
Suggestion.SUPPORT,
234234
Suggestion.INVITE,
235235
Suggestion.QUICK_PAY,
236+
Suggestion.NOTIFICATIONS.takeIf { !settings.notificationsGranted },
236237
Suggestion.SHOP,
237238
Suggestion.PROFILE,
238239
)

0 commit comments

Comments
 (0)