forked from joreilly/Confetti
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSummaryNotificationBuilder.kt
More file actions
42 lines (36 loc) · 1.6 KB
/
SummaryNotificationBuilder.kt
File metadata and controls
42 lines (36 loc) · 1.6 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
package dev.johnoreilly.confetti.notifications
import android.content.Context
import android.graphics.BitmapFactory
import androidx.core.app.NotificationCompat
import dev.johnoreilly.confetti.fragment.SessionDetails
import dev.johnoreilly.confetti.shared.R
import dev.johnoreilly.confetti.work.SessionNotificationSender.Companion.CHANNEL_ID
import dev.johnoreilly.confetti.work.SessionNotificationSender.Companion.GROUP
class SummaryNotificationBuilder(
private val context: Context,
) {
fun createSummaryNotification(sessions: List<SessionDetails>, notificationId: Int): NotificationCompat.Builder {
val largeIcon = BitmapFactory.decodeResource(
context.resources,
R.mipmap.ic_launcher_round
)
// Apply scope function is failing with an error:
// InboxStyle.apply can only be called from within the same library group prefix.
val style = NotificationCompat.InboxStyle()
.setBigContentTitle("${sessions.count()} upcoming sessions")
// We only show up to a limited number of sessions to avoid pollute the user notifications.
for (session in sessions.take(4)) {
style.addLine(session.title)
}
return NotificationCompat
.Builder(context, CHANNEL_ID)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setLargeIcon(largeIcon)
.setGroup(GROUP)
.setGroupSummary(true)
.setAutoCancel(true)
.setLocalOnly(false)
.setStyle(style)
.extend(NotificationCompat.WearableExtender().setBridgeTag("session:summary"))
}
}