Skip to content

Commit 435bf86

Browse files
notif: Add support group summary notifications to Pigeon bindings
This adds support for creating a group summary notification: https://developer.android.com/develop/ui/views/notifications/group#group-summary
1 parent 5a1ebdb commit 435bf86

File tree

5 files changed

+108
-5
lines changed

5 files changed

+108
-5
lines changed

android/app/src/main/kotlin/com/zulip/flutter/Notifications.g.kt

+40-2
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,31 @@ data class PendingIntent (
8282
)
8383
}
8484
}
85+
86+
/**
87+
* Corresponds to `androidx.core.app.NotificationCompat.InboxStyle`
88+
*
89+
* See: https://developer.android.com/reference/androidx/core/app/NotificationCompat.InboxStyle
90+
*
91+
* Generated class from Pigeon that represents data sent in messages.
92+
*/
93+
data class InboxStyle (
94+
val summaryText: String
95+
96+
) {
97+
companion object {
98+
@Suppress("LocalVariableName")
99+
fun fromList(__pigeon_list: List<Any?>): InboxStyle {
100+
val summaryText = __pigeon_list[0] as String
101+
return InboxStyle(summaryText)
102+
}
103+
}
104+
fun toList(): List<Any?> {
105+
return listOf(
106+
summaryText,
107+
)
108+
}
109+
}
85110
private object NotificationsPigeonCodec : StandardMessageCodec() {
86111
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
87112
return when (type) {
@@ -90,6 +115,11 @@ private object NotificationsPigeonCodec : StandardMessageCodec() {
90115
PendingIntent.fromList(it)
91116
}
92117
}
118+
130.toByte() -> {
119+
return (readValue(buffer) as? List<Any?>)?.let {
120+
InboxStyle.fromList(it)
121+
}
122+
}
93123
else -> super.readValueOfType(type, buffer)
94124
}
95125
}
@@ -99,6 +129,10 @@ private object NotificationsPigeonCodec : StandardMessageCodec() {
99129
stream.write(129)
100130
writeValue(stream, value.toList())
101131
}
132+
is InboxStyle -> {
133+
stream.write(130)
134+
writeValue(stream, value.toList())
135+
}
102136
else -> super.writeValue(stream, value)
103137
}
104138
}
@@ -125,7 +159,7 @@ interface AndroidNotificationHostApi {
125159
* https://developer.android.com/reference/kotlin/android/app/NotificationManager.html#notify
126160
* https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder
127161
*/
128-
fun notify(tag: String?, id: Long, channelId: String, color: Long?, contentIntent: PendingIntent?, contentText: String?, contentTitle: String?, extras: Map<String?, String?>?, smallIconResourceName: String?)
162+
fun notify(tag: String?, id: Long, channelId: String, color: Long?, contentIntent: PendingIntent?, contentText: String?, contentTitle: String?, extras: Map<String?, String?>?, smallIconResourceName: String?, groupKey: String?, isGroupSummary: Boolean?, inboxStyle: InboxStyle?, autoCancel: Boolean?)
129163

130164
companion object {
131165
/** The codec used by AndroidNotificationHostApi. */
@@ -150,8 +184,12 @@ interface AndroidNotificationHostApi {
150184
val contentTitleArg = args[6] as String?
151185
val extrasArg = args[7] as Map<String?, String?>?
152186
val smallIconResourceNameArg = args[8] as String?
187+
val groupKeyArg = args[9] as String?
188+
val isGroupSummaryArg = args[10] as Boolean?
189+
val inboxStyleArg = args[11] as InboxStyle?
190+
val autoCancelArg = args[12] as Boolean?
153191
val wrapped: List<Any?> = try {
154-
api.notify(tagArg, idArg, channelIdArg, colorArg, contentIntentArg, contentTextArg, contentTitleArg, extrasArg, smallIconResourceNameArg)
192+
api.notify(tagArg, idArg, channelIdArg, colorArg, contentIntentArg, contentTextArg, contentTitleArg, extrasArg, smallIconResourceNameArg, groupKeyArg, isGroupSummaryArg, inboxStyleArg, autoCancelArg)
155193
listOf(null)
156194
} catch (exception: Throwable) {
157195
wrapError(exception)

android/app/src/main/kotlin/com/zulip/flutter/ZulipPlugin.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ private class AndroidNotificationHost(val context: Context)
2929
contentText: String?,
3030
contentTitle: String?,
3131
extras: Map<String?, String?>?,
32-
smallIconResourceName: String?
32+
smallIconResourceName: String?,
33+
groupKey: String?,
34+
isGroupSummary: Boolean?,
35+
inboxStyle: InboxStyle?,
36+
autoCancel: Boolean?
3337
) {
3438
val notification = NotificationCompat.Builder(context, channelId).apply {
3539
color?.let { setColor(it.toInt()) }
@@ -51,6 +55,13 @@ private class AndroidNotificationHost(val context: Context)
5155
Bundle().apply { it.forEach { (k, v) -> putString(k, v) } } ) }
5256
smallIconResourceName?.let { setSmallIcon(context.resources.getIdentifier(
5357
it, "drawable", context.packageName)) }
58+
groupKey?.let { setGroup(it) }
59+
isGroupSummary?.let { setGroupSummary(it) }
60+
inboxStyle?.let { setStyle(
61+
NotificationCompat.InboxStyle()
62+
.setSummaryText(it.summaryText)
63+
) }
64+
autoCancel?.let { setAutoCancel(it) }
5465
}.build()
5566
NotificationManagerCompat.from(context).notify(tag, id.toInt(), notification)
5667
}

lib/host/android_notifications.g.dart

+31-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,30 @@ class PendingIntent {
5353
}
5454
}
5555

56+
/// Corresponds to `androidx.core.app.NotificationCompat.InboxStyle`
57+
///
58+
/// See: https://developer.android.com/reference/androidx/core/app/NotificationCompat.InboxStyle
59+
class InboxStyle {
60+
InboxStyle({
61+
required this.summaryText,
62+
});
63+
64+
String summaryText;
65+
66+
Object encode() {
67+
return <Object?>[
68+
summaryText,
69+
];
70+
}
71+
72+
static InboxStyle decode(Object result) {
73+
result as List<Object?>;
74+
return InboxStyle(
75+
summaryText: result[0]! as String,
76+
);
77+
}
78+
}
79+
5680

5781
class _PigeonCodec extends StandardMessageCodec {
5882
const _PigeonCodec();
@@ -61,6 +85,9 @@ class _PigeonCodec extends StandardMessageCodec {
6185
if (value is PendingIntent) {
6286
buffer.putUint8(129);
6387
writeValue(buffer, value.encode());
88+
} else if (value is InboxStyle) {
89+
buffer.putUint8(130);
90+
writeValue(buffer, value.encode());
6491
} else {
6592
super.writeValue(buffer, value);
6693
}
@@ -71,6 +98,8 @@ class _PigeonCodec extends StandardMessageCodec {
7198
switch (type) {
7299
case 129:
73100
return PendingIntent.decode(readValue(buffer)!);
101+
case 130:
102+
return InboxStyle.decode(readValue(buffer)!);
74103
default:
75104
return super.readValueOfType(type, buffer);
76105
}
@@ -107,15 +136,15 @@ class AndroidNotificationHostApi {
107136
/// See:
108137
/// https://developer.android.com/reference/kotlin/android/app/NotificationManager.html#notify
109138
/// https://developer.android.com/reference/androidx/core/app/NotificationCompat.Builder
110-
Future<void> notify({String? tag, required int id, required String channelId, int? color, PendingIntent? contentIntent, String? contentText, String? contentTitle, Map<String?, String?>? extras, String? smallIconResourceName,}) async {
139+
Future<void> notify({String? tag, required int id, required String channelId, int? color, PendingIntent? contentIntent, String? contentText, String? contentTitle, Map<String?, String?>? extras, String? smallIconResourceName, String? groupKey, bool? isGroupSummary, InboxStyle? inboxStyle, bool? autoCancel,}) async {
111140
final String __pigeon_channelName = 'dev.flutter.pigeon.zulip.AndroidNotificationHostApi.notify$__pigeon_messageChannelSuffix';
112141
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
113142
__pigeon_channelName,
114143
pigeonChannelCodec,
115144
binaryMessenger: __pigeon_binaryMessenger,
116145
);
117146
final List<Object?>? __pigeon_replyList =
118-
await __pigeon_channel.send(<Object?>[tag, id, channelId, color, contentIntent, contentText, contentTitle, extras, smallIconResourceName]) as List<Object?>?;
147+
await __pigeon_channel.send(<Object?>[tag, id, channelId, color, contentIntent, contentText, contentTitle, extras, smallIconResourceName, groupKey, isGroupSummary, inboxStyle, autoCancel]) as List<Object?>?;
119148
if (__pigeon_replyList == null) {
120149
throw _createConnectionError(__pigeon_channelName);
121150
} else if (__pigeon_replyList.length > 1) {

pigeon/notifications.dart

+13
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ class PendingIntent {
2727
final int flags;
2828
}
2929

30+
/// Corresponds to `androidx.core.app.NotificationCompat.InboxStyle`
31+
///
32+
/// See: https://developer.android.com/reference/androidx/core/app/NotificationCompat.InboxStyle
33+
class InboxStyle {
34+
InboxStyle({required this.summaryText});
35+
36+
final String summaryText;
37+
}
38+
3039
@HostApi()
3140
abstract class AndroidNotificationHostApi {
3241
/// Corresponds to `android.app.NotificationManager.notify`,
@@ -61,6 +70,10 @@ abstract class AndroidNotificationHostApi {
6170
String? contentTitle,
6271
Map<String?, String?>? extras,
6372
String? smallIconResourceName,
73+
String? groupKey,
74+
bool? isGroupSummary,
75+
InboxStyle? inboxStyle,
76+
bool? autoCancel,
6477
// NotificationCompat.Builder has lots more methods; add as needed.
6578
// Keep them alphabetized, for easy comparison with that class's docs.
6679
});

test/model/binding.dart

+12
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,10 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
503503
String? contentTitle,
504504
Map<String?, String?>? extras,
505505
String? smallIconResourceName,
506+
String? groupKey,
507+
bool? isGroupSummary,
508+
InboxStyle? inboxStyle,
509+
bool? autoCancel,
506510
}) async {
507511
_notifyCalls.add((
508512
tag: tag,
@@ -514,6 +518,10 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
514518
contentTitle: contentTitle,
515519
extras: extras,
516520
smallIconResourceName: smallIconResourceName,
521+
groupKey: groupKey,
522+
isGroupSummary: isGroupSummary,
523+
inboxStyle: inboxStyle,
524+
autoCancel: autoCancel,
517525
));
518526
}
519527
}
@@ -528,4 +536,8 @@ typedef AndroidNotificationHostApiNotifyCall = ({
528536
String? contentTitle,
529537
Map<String?, String?>? extras,
530538
String? smallIconResourceName,
539+
String? groupKey,
540+
bool? isGroupSummary,
541+
InboxStyle? inboxStyle,
542+
bool? autoCancel,
531543
});

0 commit comments

Comments
 (0)