diff --git a/app/src/main/java/org/openedx/app/AppAnalytics.kt b/app/src/main/java/org/openedx/app/AppAnalytics.kt index 0fe3ed4be..71a99490b 100644 --- a/app/src/main/java/org/openedx/app/AppAnalytics.kt +++ b/app/src/main/java/org/openedx/app/AppAnalytics.kt @@ -24,8 +24,19 @@ enum class AppAnalyticsEvent(val eventName: String, val biValue: String) { "MainDashboard:Profile", "edx.bi.app.main_dashboard.profile" ), + NOTIFICATION_PERMISSION( + "Notification:Setting Permission Status", + "edx.bi.app.notification.permission_settings.status" + ) } enum class AppAnalyticsKey(val key: String) { NAME("name"), + STATUS("status"), +} + +enum class PermissionStatus(val status: String) { + DENIED("denied"), + AUTHORIZED("authorized"), + NOT_DETERMINED("not_determined"), } diff --git a/app/src/main/java/org/openedx/app/MainViewModel.kt b/app/src/main/java/org/openedx/app/MainViewModel.kt index f7fe32c42..00b88a1bd 100644 --- a/app/src/main/java/org/openedx/app/MainViewModel.kt +++ b/app/src/main/java/org/openedx/app/MainViewModel.kt @@ -1,5 +1,8 @@ package org.openedx.app +import android.annotation.SuppressLint +import android.content.Context +import androidx.core.app.NotificationManagerCompat import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData @@ -16,7 +19,9 @@ import org.openedx.core.system.notifier.DiscoveryNotifier import org.openedx.core.system.notifier.NavigationToDiscovery import org.openedx.discovery.presentation.DiscoveryNavigator +@SuppressLint("StaticFieldLeak") class MainViewModel( + private val context: Context, private val config: Config, private val notifier: DiscoveryNotifier, private val analytics: AppAnalytics, @@ -43,6 +48,7 @@ class MainViewModel( } .distinctUntilChanged() .launchIn(viewModelScope) + logSettingPermissionStatusEvent() } fun enableBottomBar(enable: Boolean) { @@ -52,7 +58,7 @@ class MainViewModel( fun logLearnTabClickedEvent() { logScreenEvent(AppAnalyticsEvent.LEARN) } - + fun logDiscoveryTabClickedEvent() { logScreenEvent(AppAnalyticsEvent.DISCOVER) } @@ -69,4 +75,18 @@ class MainViewModel( } ) } + + private fun logSettingPermissionStatusEvent() { + val event = AppAnalyticsEvent.NOTIFICATION_PERMISSION + val permissionStatus = + if (NotificationManagerCompat.from(context).areNotificationsEnabled()) { + PermissionStatus.AUTHORIZED + } else { + PermissionStatus.DENIED + } + analytics.logEvent(event.eventName, buildMap { + put(AppAnalyticsKey.NAME.key, event.biValue) + put(AppAnalyticsKey.STATUS.key, permissionStatus.status) + }) + } } diff --git a/app/src/main/java/org/openedx/app/di/ScreenModule.kt b/app/src/main/java/org/openedx/app/di/ScreenModule.kt index e6d25fba6..516856208 100644 --- a/app/src/main/java/org/openedx/app/di/ScreenModule.kt +++ b/app/src/main/java/org/openedx/app/di/ScreenModule.kt @@ -86,7 +86,7 @@ val screenModule = module { get() ) } - viewModel { MainViewModel(get(), get(), get()) } + viewModel { MainViewModel(get(), get(), get(), get()) } factory { AuthRepository(get(), get(), get()) } factory { AuthInteractor(get()) }