Skip to content

Commit

Permalink
chore: log custom event for notification permission status
Browse files Browse the repository at this point in the history
fixes: LEARNER-10338
  • Loading branch information
farhan-arshad-dev authored and omerhabib26 committed Dec 6, 2024
1 parent 9a199f6 commit 87fbd22
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
11 changes: 11 additions & 0 deletions app/src/main/java/org/openedx/app/AppAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
22 changes: 21 additions & 1 deletion app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand All @@ -43,6 +48,7 @@ class MainViewModel(
}
.distinctUntilChanged()
.launchIn(viewModelScope)
logSettingPermissionStatusEvent()
}

fun enableBottomBar(enable: Boolean) {
Expand All @@ -52,7 +58,7 @@ class MainViewModel(
fun logLearnTabClickedEvent() {
logScreenEvent(AppAnalyticsEvent.LEARN)
}

fun logDiscoveryTabClickedEvent() {
logScreenEvent(AppAnalyticsEvent.DISCOVER)
}
Expand All @@ -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)
})
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Expand Down

0 comments on commit 87fbd22

Please sign in to comment.