Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: log custom event for notification permission status #71

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No usage found.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the Android not_determined not applicable, cuz NotificationManagerCompat.from(context).areNotificationsEnabled() returns boolean. so removed.

}
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() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, logNotificationPermissionStatusEvent is more appropriate.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed.

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
Loading