Last active
November 2, 2017 13:02
-
-
Save chetdeva/b7706141b2d6514eabf1b7aac1ca2fb5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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