Skip to content

Instantly share code, notes, and snippets.

@chetdeva
Last active November 2, 2017 13:02
Show Gist options
  • Select an option

  • Save chetdeva/b7706141b2d6514eabf1b7aac1ca2fb5 to your computer and use it in GitHub Desktop.

Select an option

Save chetdeva/b7706141b2d6514eabf1b7aac1ca2fb5 to your computer and use it in GitHub Desktop.
@Reusable
class CollapsingNotificationManager @Inject
constructor(private val collapsingNotificationStore: CollapsingNotificationStore) {
private val collapsingNotifications = getCollapsingNotifications()
/**
* get notifications to collapse
*/
fun getNotificationsToCollapse(data: Map<String, String>): List<Int>? {
if (PushNotification.hasNotificationIdAndCollapseKey(data)) {
val type = data[PushNotification.NOTIFICATION_COLLAPSE_KEY] ?: ""
val id = data[PushNotification.NOTIFICATION_ID]?.toInt() ?: 0
collapsingNotifications.put(type, id)
putCollapsingNotifications(collapsingNotifications)
return collapsingNotifications.getValues(type)
}
return null
}
/**
* clear notifications to collapse
* @return true if notifications were cleared
*/
fun clearNotificationsToCollapse(data: Bundle): Boolean {
if (PushNotification.hasNotificationKeyAndIds(data)) {
val notificationKey = data.getString(PushNotification.NOTIFICATION_KEY) ?: ""
val notificationIds = data.getIntegerArrayList(PushNotification.NOTIFICATION_IDS) ?: ArrayList()
collapsingNotifications.removeValues(notificationKey, notificationIds)
putCollapsingNotifications(collapsingNotifications)
return true
}
return false
}
private fun getCollapsingNotifications() = collapsingNotificationStore.collapsingNotifications
private fun putCollapsingNotifications(collapsingNotifications: MultiValuedMap<String, Int>) {
collapsingNotificationStore.collapsingNotifications = collapsingNotifications
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment