Updated on 2026-08-14

This commit is contained in:
Tangem 2024-06-20 12:30:53 +05:00
parent 76c5fd4032
commit 9b665a76b3
9 changed files with 33 additions and 23 deletions

View file

@ -4,8 +4,8 @@ import com.tangem.core.ui.components.bottomsheets.TangemBottomSheetConfigContent
data class PushNotificationsBottomSheetConfig(
val isFirstTimeAsking: Boolean,
val onRequest: () -> Unit,
val onAllow: () -> Unit,
val onAllowed: () -> Unit,
val onDeny: () -> Unit,
val openSettings: () -> Unit,
) : TangemBottomSheetConfigContent

View file

@ -24,6 +24,7 @@ import com.tangem.core.ui.res.TangemThemePreview
import com.tangem.core.ui.utils.requestPushPermission
import com.tangem.feature.wallet.impl.R
import com.tangem.feature.wallet.presentation.wallet.state.model.PushNotificationsBottomSheetConfig
import com.tangem.features.pushnotifications.api.utils.getPushPermissionOrNull
import kotlinx.collections.immutable.persistentListOf
@Composable
@ -37,10 +38,11 @@ internal fun PushNotificationsBottomSheet(config: TangemBottomSheetConfig) {
private fun PushNotificationsSheetContent(content: PushNotificationsBottomSheetConfig, onDismiss: () -> Unit) {
val isClicked = remember { mutableStateOf(false) }
val requestPushPermission = requestPushPermission(
pushPermission = getPushPermissionOrNull(),
isFirstTimeAsking = content.isFirstTimeAsking,
isClicked = isClicked,
onAllow = {
content.onAllowed()
content.onAllow()
onDismiss()
},
onDeny = {
@ -87,7 +89,7 @@ private fun PushNotificationsSheetContent(content: PushNotificationsBottomSheetC
text = stringResource(R.string.common_allow),
onClick = {
isClicked.value = true
content.onAllow()
content.onRequest()
requestPushPermission()
},
modifier = Modifier.weight(1f),
@ -105,8 +107,8 @@ private fun PushNotificationsSheetContent_Preview() {
PushNotificationsSheetContent(
PushNotificationsBottomSheetConfig(
isFirstTimeAsking = false,
onRequest = {},
onAllow = {},
onAllowed = {},
onDeny = {},
openSettings = {},
),

View file

@ -155,7 +155,8 @@ internal class WalletViewModel @Inject constructor(
private fun subscribeOnPushNotificationsPermission() {
viewModelScope.launch {
if (!shouldAskPermissionUseCase(PUSH_PERMISSION)) return@launch
withContext(dispatchers.io) { delay(timeMillis = 1_800) }
delay(timeMillis = 1_800)
val isFirstTimeAsking = isFirstTimeAskingPermissionUseCase(PUSH_PERMISSION).getOrElse { true }
val wasInitiallyAsk = shouldInitiallyAskPermissionUseCase(PUSH_PERMISSION).getOrElse { true }
@ -167,8 +168,8 @@ internal class WalletViewModel @Inject constructor(
stateHolder.showBottomSheet(
PushNotificationsBottomSheetConfig(
isFirstTimeAsking = isFirstTimeAsking,
onAllow = clickIntents::onAllowPushPermission,
onAllowed = clickIntents::onNeverAskPushPermission,
onRequest = clickIntents::onRequestPushPermission,
onAllow = clickIntents::onNeverAskPushPermission,
onDeny = onDenyClick,
openSettings = settingsManager::openSettings,
),

View file

@ -10,7 +10,7 @@ import javax.inject.Inject
internal interface WalletPushPermissionClickIntents {
fun onAllowPushPermission()
fun onRequestPushPermission()
fun onDelayAskPushPermission()
@ -24,7 +24,7 @@ internal class WalletPushPermissionClickIntentsImplementor @Inject constructor(
private val delayPermissionRequestUseCase: DelayPermissionRequestUseCase,
) : BaseWalletClickIntents(), WalletPushPermissionClickIntents {
override fun onAllowPushPermission() {
override fun onRequestPushPermission() {
viewModelScope.launch {
setFirstTimeAskingPermissionUseCase(PUSH_PERMISSION)
}