Announcements
Receive admin announcements
Overview
The DriverSdk provides an API to receive and display messages that were sent from the admin to the driver.
Announcement messages interface on the SDK:
interface AdminMessageRepository {
val messages: LiveData<Collection<Message>>
val unreadMessages: LiveData<Collection<Message>>
fun hasUnreadItems(): Boolean
fun markRead(messageId: Long)
fun delete(messageId: Long)
}
The Message Model:
id Long NOT NULLABLE |
A unique message id |
message String NOT NULLABLE |
The content of the message |
time String NOT NULLABLE |
The creation time of the message in UNIX time format |
author String NOT NULLABLE |
The author of the message |
readAtTimestamp Long NOT NULLABLE |
The timestamp when the message was marked as read |
Observe admin messages updates
Admin messages can be observed using a LiveData object obtained from DriverSdk:
val driverSdk = DriverSdkProvider.driverSdk
driverSdk.adminMessages.messages.observe(viewLifecycleOwner) { it ->
Log.i(TAG, "admin messages updated, messages=$it")
adapter.submitList(it.toList()) {
remeasure(recyclerView)
}
}
Observe only unread admin messages
For convenience,
Unread admin messages can be observed using a LiveData object obtained from DriverSdk::
val driverSdk = DriverSdkProvider.driverSdk
driverSdk.adminMessages.unreadMessages.observe(viewLifecycleOwner) {
Log.i(TAG, "unread admin messages updated, messages=$it")
parentLayout.findViewById<TextView>(R.id.admin_message_unread_count).text = getString(R.string.title_unread_messages, it.size)
}
the SDK user can check if there are any unread messages:
val driverSdk = DriverSdkProvider.driverSdk
boolean hasUnreadAnnouncements = driverSdk.adminMessages.hasUnreadItems();
Mark announcement as read
Mark announcement as read
a driver can mark an announcement as read:
val driverSdk = DriverSdkProvider.driverSdk
driverSdk.adminMessages.markRead(adminMessage.getId());
Delete an announcement
a driver can delete an announcement:
val driverSdk = DriverSdkProvider.driverSdk
driverSdk.adminMessages.markRead(adminMessage.getId());
Updated over 3 years ago