Notification list screen

TerraCore v0

Introduction#

NotificationUI provides a built-in screen for showing received notifications of users.

Usage#

For showing notification list, NotificationUI use a fragment, called NotificationListFragment. To integrate NotificationListFragment with Navigation component, follow the steps below:

Add NotificationListFragment to the app's navigation graph#

Suppose we use a global action to navigate to NotificationListFragment.

<action
android:id="@+id/action_to_notificationListFragment"
app:destination="@id/notificationListFragment" />
<fragment
android:id="@+id/notificationListFragment"
android:name="vn.teko.notification.ui.screen.list.NotificationListFragment"
android:label="NotificationListFragment" />

Navigate to NotificationListFragment#

val deviceToken = callFunctionToGetFcmToken() // required for the non-login users
findNavController().navigate(
R.id.action_to_notificationListFragment,
NotificationListFragment.createArguments(deviceToken)
)

Handle events from NotificationListFragment#

val notificationUi = NotificationUiManager.getInstance(TerraApp.getInstance())
notificationUi.callback = object : NotificationUiCallback {
override fun onClickNotification(fragment: Fragment, notification: Notification) {
// This function will be called when user clicks a notification to view more details.
// TODO: navigate to corresponding screen or do something based on your business logic.
}
override fun onMarkReadNotification(notification: Notification) {
// This function will be called when user clicks a unread notification and this notification
// is marked read notification successful.
// Should call `countUnreadNotifications` and update the corresponding UI.
}
}

References#