Skip to content

Commit 6d14d06

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 6d14d06

File tree

5 files changed

+114
-11
lines changed

5 files changed

+114
-11
lines changed

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

Lines changed: 47 additions & 9 deletions
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, autoCancel: Boolean?, channelId: String, color: Long?, contentIntent: PendingIntent?, contentText: String?, contentTitle: String?, extras: Map<String?, String?>?, groupKey: String?, inboxStyle: InboxStyle?, isGroupSummary: Boolean?, smallIconResourceName: String?)
129163

130164
companion object {
131165
/** The codec used by AndroidNotificationHostApi. */
@@ -143,15 +177,19 @@ interface AndroidNotificationHostApi {
143177
val args = message as List<Any?>
144178
val tagArg = args[0] as String?
145179
val idArg = args[1].let { num -> if (num is Int) num.toLong() else num as Long }
146-
val channelIdArg = args[2] as String
147-
val colorArg = args[3].let { num -> if (num is Int) num.toLong() else num as Long? }
148-
val contentIntentArg = args[4] as PendingIntent?
149-
val contentTextArg = args[5] as String?
150-
val contentTitleArg = args[6] as String?
151-
val extrasArg = args[7] as Map<String?, String?>?
152-
val smallIconResourceNameArg = args[8] as String?
180+
val autoCancelArg = args[2] as Boolean?
181+
val channelIdArg = args[3] as String
182+
val colorArg = args[4].let { num -> if (num is Int) num.toLong() else num as Long? }
183+
val contentIntentArg = args[5] as PendingIntent?
184+
val contentTextArg = args[6] as String?
185+
val contentTitleArg = args[7] as String?
186+
val extrasArg = args[8] as Map<String?, String?>?
187+
val groupKeyArg = args[9] as String?
188+
val inboxStyleArg = args[10] as InboxStyle?
189+
val isGroupSummaryArg = args[11] as Boolean?
190+
val smallIconResourceNameArg = args[12] as String?
153191
val wrapped: List<Any?> = try {
154-
api.notify(tagArg, idArg, channelIdArg, colorArg, contentIntentArg, contentTextArg, contentTitleArg, extrasArg, smallIconResourceNameArg)
192+
api.notify(tagArg, idArg, autoCancelArg, channelIdArg, colorArg, contentIntentArg, contentTextArg, contentTitleArg, extrasArg, groupKeyArg, inboxStyleArg, isGroupSummaryArg, smallIconResourceNameArg)
155193
listOf(null)
156194
} catch (exception: Throwable) {
157195
wrapError(exception)

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,20 @@ private class AndroidNotificationHost(val context: Context)
2323
override fun notify(
2424
tag: String?,
2525
id: Long,
26+
autoCancel: Boolean?,
2627
channelId: String,
2728
color: Long?,
2829
contentIntent: PendingIntent?,
2930
contentText: String?,
3031
contentTitle: String?,
3132
extras: Map<String?, String?>?,
33+
groupKey: String?,
34+
inboxStyle: InboxStyle?,
35+
isGroupSummary: Boolean?,
3236
smallIconResourceName: String?
3337
) {
3438
val notification = NotificationCompat.Builder(context, channelId).apply {
39+
autoCancel?.let { setAutoCancel(it) }
3540
color?.let { setColor(it.toInt()) }
3641
contentIntent?.let { setContentIntent(
3742
android.app.PendingIntent.getActivity(context,
@@ -49,6 +54,12 @@ private class AndroidNotificationHost(val context: Context)
4954
contentTitle?.let { setContentTitle(it) }
5055
extras?.let { setExtras(
5156
Bundle().apply { it.forEach { (k, v) -> putString(k, v) } } ) }
57+
groupKey?.let { setGroup(it) }
58+
inboxStyle?.let { setStyle(
59+
NotificationCompat.InboxStyle()
60+
.setSummaryText(it.summaryText)
61+
) }
62+
isGroupSummary?.let { setGroupSummary(it) }
5263
smallIconResourceName?.let { setSmallIcon(context.resources.getIdentifier(
5364
it, "drawable", context.packageName)) }
5465
}.build()

lib/host/android_notifications.g.dart

Lines changed: 31 additions & 2 deletions
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, bool? autoCancel, required String channelId, int? color, PendingIntent? contentIntent, String? contentText, String? contentTitle, Map<String?, String?>? extras, String? groupKey, InboxStyle? inboxStyle, bool? isGroupSummary, String? smallIconResourceName,}) 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, autoCancel, channelId, color, contentIntent, contentText, contentTitle, extras, groupKey, inboxStyle, isGroupSummary, smallIconResourceName]) as List<Object?>?;
119148
if (__pigeon_replyList == null) {
120149
throw _createConnectionError(__pigeon_channelName);
121150
} else if (__pigeon_replyList.length > 1) {

pigeon/notifications.dart

Lines changed: 13 additions & 0 deletions
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`,
@@ -54,12 +63,16 @@ abstract class AndroidNotificationHostApi {
5463
required int id,
5564

5665
// The remaining arguments go to method calls on NotificationCompat.Builder.
66+
bool? autoCancel,
5767
required String channelId,
5868
int? color,
5969
PendingIntent? contentIntent,
6070
String? contentText,
6171
String? contentTitle,
6272
Map<String?, String?>? extras,
73+
String? groupKey,
74+
InboxStyle? inboxStyle,
75+
bool? isGroupSummary,
6376
String? smallIconResourceName,
6477
// NotificationCompat.Builder has lots more methods; add as needed.
6578
// Keep them alphabetized, for easy comparison with that class's docs.

test/model/binding.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,23 +496,31 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
496496
Future<void> notify({
497497
String? tag,
498498
required int id,
499+
bool? autoCancel,
499500
required String channelId,
500501
int? color,
501502
PendingIntent? contentIntent,
502503
String? contentText,
503504
String? contentTitle,
504505
Map<String?, String?>? extras,
506+
String? groupKey,
507+
InboxStyle? inboxStyle,
508+
bool? isGroupSummary,
505509
String? smallIconResourceName,
506510
}) async {
507511
_notifyCalls.add((
508512
tag: tag,
509513
id: id,
514+
autoCancel: autoCancel,
510515
channelId: channelId,
511516
color: color,
512517
contentIntent: contentIntent,
513518
contentText: contentText,
514519
contentTitle: contentTitle,
515520
extras: extras,
521+
groupKey: groupKey,
522+
inboxStyle: inboxStyle,
523+
isGroupSummary: isGroupSummary,
516524
smallIconResourceName: smallIconResourceName,
517525
));
518526
}
@@ -521,11 +529,15 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
521529
typedef AndroidNotificationHostApiNotifyCall = ({
522530
String? tag,
523531
int id,
532+
bool? autoCancel,
524533
String channelId,
525534
int? color,
526535
PendingIntent? contentIntent,
527536
String? contentText,
528537
String? contentTitle,
529538
Map<String?, String?>? extras,
539+
String? groupKey,
540+
InboxStyle? inboxStyle,
541+
bool? isGroupSummary,
530542
String? smallIconResourceName,
531543
});

0 commit comments

Comments
 (0)