-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCollapsingNotificationManager.kt
More file actions
62 lines (48 loc) · 2.09 KB
/
CollapsingNotificationManager.kt
File metadata and controls
62 lines (48 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package com.fueled.collapsingnotifications.notification
import android.os.Bundle
import com.fueled.collapsingnotifications.core.PushNotification
import com.fueled.collapsingnotifications.data.CollapsingNotificationStore
import com.fueled.collapsingnotifications.util.MultiValuedMap
import dagger.Reusable
import javax.inject.Inject
/**
* Copyright (c) 2017 Fueled. All rights reserved.
*
* @author chetansachdeva on 23/09/17
*/
@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
}
}