Skip to content

Commit 6bf675b

Browse files
pigeon: Add binding for deleteNotificationChannel
1 parent 84dba03 commit 6bf675b

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

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

+24
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ interface AndroidNotificationHostApi {
408408
* See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#getNotificationChannelsCompat()
409409
*/
410410
fun getNotificationChannels(): List<NotificationChannel>
411+
/**
412+
* Corresponds to `androidx.core.app.NotificationManagerCompat.deleteNotificationChannel`
413+
*
414+
* See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)
415+
*/
416+
fun deleteNotificationChannel(channelId: String)
411417
/**
412418
* Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
413419
*
@@ -490,6 +496,24 @@ interface AndroidNotificationHostApi {
490496
channel.setMessageHandler(null)
491497
}
492498
}
499+
run {
500+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.zulip.AndroidNotificationHostApi.deleteNotificationChannel$separatedMessageChannelSuffix", codec)
501+
if (api != null) {
502+
channel.setMessageHandler { message, reply ->
503+
val args = message as List<Any?>
504+
val channelIdArg = args[0] as String
505+
val wrapped: List<Any?> = try {
506+
api.deleteNotificationChannel(channelIdArg)
507+
listOf(null)
508+
} catch (exception: Throwable) {
509+
wrapError(exception)
510+
}
511+
reply.reply(wrapped)
512+
}
513+
} else {
514+
channel.setMessageHandler(null)
515+
}
516+
}
493517
run {
494518
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.zulip.AndroidNotificationHostApi.createNotificationChannel$separatedMessageChannelSuffix", codec)
495519
if (api != null) {

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

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ private class AndroidNotificationHost(val context: Context)
5454
) }
5555
}
5656

57+
override fun deleteNotificationChannel(channelId: String) {
58+
NotificationManagerCompat.from(context).deleteNotificationChannel(channelId)
59+
}
60+
5761
override fun createNotificationChannel(channel: NotificationChannel) {
5862
val notificationChannel = NotificationChannelCompat
5963
.Builder(channel.id, channel.importance.toInt()).apply {

lib/host/android_notifications.g.dart

+25
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,31 @@ class AndroidNotificationHostApi {
405405
}
406406
}
407407

408+
/// Corresponds to `androidx.core.app.NotificationManagerCompat.deleteNotificationChannel`
409+
///
410+
/// See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)
411+
Future<void> deleteNotificationChannel(String channelId) async {
412+
final String __pigeon_channelName = 'dev.flutter.pigeon.zulip.AndroidNotificationHostApi.deleteNotificationChannel$__pigeon_messageChannelSuffix';
413+
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
414+
__pigeon_channelName,
415+
pigeonChannelCodec,
416+
binaryMessenger: __pigeon_binaryMessenger,
417+
);
418+
final List<Object?>? __pigeon_replyList =
419+
await __pigeon_channel.send(<Object?>[channelId]) as List<Object?>?;
420+
if (__pigeon_replyList == null) {
421+
throw _createConnectionError(__pigeon_channelName);
422+
} else if (__pigeon_replyList.length > 1) {
423+
throw PlatformException(
424+
code: __pigeon_replyList[0]! as String,
425+
message: __pigeon_replyList[1] as String?,
426+
details: __pigeon_replyList[2],
427+
);
428+
} else {
429+
return;
430+
}
431+
}
432+
408433
/// Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
409434
///
410435
/// See: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannel(androidx.core.app.NotificationChannelCompat)

pigeon/notifications.dart

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ abstract class AndroidNotificationHostApi {
160160
/// See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#getNotificationChannelsCompat()
161161
List<NotificationChannel> getNotificationChannels();
162162

163+
/// Corresponds to `androidx.core.app.NotificationManagerCompat.deleteNotificationChannel`
164+
///
165+
/// See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)
166+
void deleteNotificationChannel(String channelId);
167+
163168
/// Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
164169
///
165170
/// See: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannel(androidx.core.app.NotificationChannelCompat)

test/model/binding.dart

+6
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,12 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
560560
throw UnimplementedError();
561561
}
562562

563+
@override
564+
Future<void> deleteNotificationChannel(String channelId) {
565+
// TODO: implement deleteNotificationChannel
566+
throw UnimplementedError();
567+
}
568+
563569
@override
564570
Future<void> createNotificationChannel(NotificationChannel channel) async {
565571
_createdChannels.add(channel);

0 commit comments

Comments
 (0)