Skip to content

Commit

Permalink
Change notification popup logic (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaiatsartem authored Dec 13, 2024
1 parent f584461 commit 298bd42
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.concordium.wallet.ui.base.BaseActivity
import com.concordium.wallet.ui.base.BaseFragment
import com.concordium.wallet.ui.cis2.SendTokenActivity
import com.concordium.wallet.ui.more.export.ExportActivity
import com.concordium.wallet.ui.more.notifications.NotificationsPermissionDialog
import com.concordium.wallet.ui.onboarding.OnboardingFragment
import com.concordium.wallet.ui.onboarding.OnboardingSharedViewModel
import com.concordium.wallet.ui.onboarding.OnboardingState
Expand Down Expand Up @@ -181,13 +180,6 @@ class AccountsOverviewFragment : BaseFragment() {
)
}

AccountsOverviewViewModel.DialogToShow.NOTIFICATIONS_PERMISSION -> {
NotificationsPermissionDialog().showSingle(
childFragmentManager,
NotificationsPermissionDialog.TAG,
)
}

null -> {}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app

enum class DialogToShow {
UNSHIELDING,
NOTIFICATIONS_PERMISSION,
;
}

Expand Down Expand Up @@ -294,11 +293,6 @@ class AccountsOverviewViewModel(application: Application) : AndroidViewModel(app
dialogsToShow += DialogToShow.UNSHIELDING
}

// Show notifications permission if never shown.
if (!notificationsPreferences.hasEverShownPermissionDialog) {
dialogsToShow += DialogToShow.NOTIFICATIONS_PERMISSION
}

// Show a single dialog if needed.
if (dialogsToShow.isNotEmpty()) {
_showDialogLiveData.postValue(Event(dialogsToShow.first()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import com.concordium.wallet.R
import com.concordium.wallet.core.authentication.Session
import com.concordium.wallet.data.preferences.TrackingPreferences
import com.concordium.wallet.databinding.ActivityWelcomeBinding
import com.concordium.wallet.extension.collectWhenStarted
import com.concordium.wallet.extension.showSingle
import com.concordium.wallet.ui.MainActivity
import com.concordium.wallet.ui.auth.passcode.PasscodeSetupActivity
import com.concordium.wallet.ui.base.BaseActivity
import com.concordium.wallet.ui.more.notifications.NotificationsPermissionDialog
import com.concordium.wallet.uicore.handleUrlClicks

class WelcomeActivity :
Expand Down Expand Up @@ -60,6 +63,15 @@ class WelcomeActivity :
App.appCore.tracker.welcomeScreen()
}

viewModel.isNotificationDialogEverShowed.collectWhenStarted(this) {
if (it.not()) {
NotificationsPermissionDialog().showSingle(
supportFragmentManager,
NotificationsPermissionDialog.TAG,
)
}
}

// Subscribe to activation bottom sheet chosen action.
supportFragmentManager.setFragmentResultListener(
WelcomeActivateAccountBottomSheet.ACTION_REQUEST,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ package com.concordium.wallet.ui.welcome

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import com.concordium.wallet.App
import com.concordium.wallet.data.preferences.NotificationsPreferences
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.launch

class WelcomeViewModel(application: Application) : AndroidViewModel(application) {

private val notificationsPreferences: NotificationsPreferences
private val _isNotificationDialogEverShowed = MutableStateFlow(true)
val isNotificationDialogEverShowed = _isNotificationDialogEverShowed.asStateFlow()

val shouldSetUpPassword: Boolean
get() = !App.appCore.session.hasSetupPassword

init {
App.appCore.session.startedInitialSetup()

notificationsPreferences = NotificationsPreferences(application)
viewModelScope.launch {
// Show notifications permission if never shown
_isNotificationDialogEverShowed.emit(notificationsPreferences.hasEverShownPermissionDialog)
}
}
}

0 comments on commit 298bd42

Please sign in to comment.