Skip to content

Advanced Notification History

Basic example

With these few lines of code:

startActivity(NearITUIBindings.getInstance(this@NotificationsActivity)
                .notificationHistoryIntentBuilder()
                .build())
startActivity(NearITUIBindings.getInstance(this)
                .notificationHistoryIntentBuilder()
                .build());

you are able to show the user notification history, ordered by recieving date, latest on top.

history list

By default content of type "Custom JSON" is not included in the list.

Advanced examples

Exclude feedback requests

You can exclude feedback requests by chaining this builder method:

startActivity(NearITUIBindings.getInstance(this@NotificationsActivity)
                .notificationHistoryIntentBuilder()
                .noFeedbacks()
                .build())
startActivity(NearITUIBindings.getInstance(this)
                .notificationHistoryIntentBuilder()
                .noFeedbacks()
                .build());

Include coupons

You can include coupons in the notification history by chaining this builder method:

startActivity(NearITUIBindings.getInstance(this@NotificationsActivity)
                .notificationHistoryIntentBuilder()
                .includeCoupons()
                .build())
startActivity(NearITUIBindings.getInstance(this)
                .notificationHistoryIntentBuilder()
                .includeCoupons()
                .build());

Custom behaviour

You can set a custom layout for when the notification history is empty chaining this builder method:

startActivity(NearITUIBindings.getInstance(this@NotificationsActivity)
                .notificationHistoryIntentBuilder()
                .setEmptyListLayout(R.layout.my_empty_layout)
                .build())
startActivity(NearITUIBindings.getInstance(this)
                .notificationHistoryIntentBuilder()
                .setEmptyListLayout(R.layout.my_empty_layout)
                .build());

Fragment mode

If you want to show notification history in your activity, place this fragment in your container:

val historyFragment = NearITUIBindings.getInstance(this@YourActivity)
                .notificationHistoryFragmentBuilder()
                .build()
Fragment historyFragment = NearITUIBindings.getInstance(MainActivity.this)
                .notificationHistoryFragmentBuilder()
                .build();

Manually handle notification history

You can get the notification history directly from the SDK and decide what to do with it:

To get the list, call:

NearItManager.getInstance().getHistory(object : NotificationHistoryManager.OnNotificationHistoryListener {
    override fun onNotifications(historyItemList: MutableList<HistoryItem>) {
        // handle the notification list
    }
    override fun onError(error: String?) {
        Log.d("INBOX", error)
    }
})
NearItManager.getInstance().getHistory(new NotificationHistoryManager.OnNotificationHistoryListener() {
    @Override
    public void onNotifications(@NonNull List<HistoryItem> historyItemList) {
        // handle the notification list
    }
    @Override
    public void onError(String error) {
        Log.d("INBOX", error);
    }
});

An HistoryItem object has these fields:

  • reaction : the ReactionBundle instance of the Near content delivered by that notification.
  • read : a boolean representing whether the notification was ever read or not by the user
  • trackingInfo : the TrackingInfo instance for that notification. Usefull for tracking (see below).
  • timestamp : the epoch timestamp (in seconds) for the notification. You can use the getTimestampDate() method to get a Nullable Date object.
  • isNew : a boolean representing whether the notification is new for the user. Its value is the same as read, unless you use markNotificationHistoryAsOld to mark all previous notifications as old. See the Updates chapter to learn more.

Warning: if you are implementing the list yourself, remember to track the items as opened when the user taps on them. See the trackings section to learn how to track a notification as opened.

Updates

To get notified on updates for history notifications, you can add a NotificationHistoryUpdateListener

NearItManager.getInstance().addNotificationHistoryUpdateListener(this)
// remember to remove with
// NearItManager.getInstance().removeNotificationHistoryUpdateListener(this)
...
override fun onNotificationHistoryUpdated(items: MutableList<HistoryItem>?) {
    // you might want to count new notifications
    val unreadCount = items?.count { it.isNew } ?: 0
}
NearItManager.getInstance().addNotificationHistoryUpdateListener(this);
// remember to remove with
// NearItManager.getInstance().removeNotificationHistoryUpdateListener(this);
...
@Override
public void onNotificationHistoryUpdated(List<HistoryItem> items) {
    // you might want to count new notifications
    int unreadCount = 0;
    for (HistoryItem item : items) {
        if (item.isNew) unreadCount++;
    }
}

If you want to update a badge you should use the isNew field to count new notifications. By default, this field will be the same as read, so any tracking regarding the item can change its value. If you want to manually set all the notification as acknowledged (meaning that isNew will be false), without loosing the read information or tracking every single notification interaction, you can call this method:

NearItManager.getInstance().markNotificationHistoryAsOld()
NearItManager.getInstance().markNotificationHistoryAsOld();

UI Customization

Like any other UI component provided by this library, you can change the look overriding colors, dimensions and strings resources.

For example, if you need to change the the text and card background colors you can place these colors in your res/values/colors.xml:

<color name="nearit_ui_notification_text_color">@color/your_color</color>
<color name="nearit_ui_notification_background_unread">@color/your_color</color>
<color name="nearit_ui_notification_card_background_read">@color/your_color</color>
<color name="nearit_ui_notification_card_text_unread_color">@color/your_color</color>
<color name="nearit_ui_notification_card_text_read_color">@color/your_color</color>
<color name="nearit_ui_notification_background_color">@color/your_color</color>

The same for strings, dimensions and styles. The following file contains the resources you can override to customize the notification list appearance:

Notification History resources

Just keep in mind that changing dimensions can cause unpredictable distorsion problems to our layouts.