Skip to content

Commit

Permalink
pigeon: Add binding for deleteNotificationChannel
Browse files Browse the repository at this point in the history
  • Loading branch information
rajveermalviya committed Oct 4, 2024
1 parent 84dba03 commit 6bf675b
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
24 changes: 24 additions & 0 deletions android/app/src/main/kotlin/com/zulip/flutter/Notifications.g.kt
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,12 @@ interface AndroidNotificationHostApi {
* See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#getNotificationChannelsCompat()
*/
fun getNotificationChannels(): List<NotificationChannel>
/**
* Corresponds to `androidx.core.app.NotificationManagerCompat.deleteNotificationChannel`
*
* See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)
*/
fun deleteNotificationChannel(channelId: String)
/**
* Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
*
Expand Down Expand Up @@ -490,6 +496,24 @@ interface AndroidNotificationHostApi {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.zulip.AndroidNotificationHostApi.deleteNotificationChannel$separatedMessageChannelSuffix", codec)
if (api != null) {
channel.setMessageHandler { message, reply ->
val args = message as List<Any?>
val channelIdArg = args[0] as String
val wrapped: List<Any?> = try {
api.deleteNotificationChannel(channelIdArg)
listOf(null)
} catch (exception: Throwable) {
wrapError(exception)
}
reply.reply(wrapped)
}
} else {
channel.setMessageHandler(null)
}
}
run {
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.zulip.AndroidNotificationHostApi.createNotificationChannel$separatedMessageChannelSuffix", codec)
if (api != null) {
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/kotlin/com/zulip/flutter/ZulipPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ private class AndroidNotificationHost(val context: Context)
) }
}

override fun deleteNotificationChannel(channelId: String) {
NotificationManagerCompat.from(context).deleteNotificationChannel(channelId)
}

override fun createNotificationChannel(channel: NotificationChannel) {
val notificationChannel = NotificationChannelCompat
.Builder(channel.id, channel.importance.toInt()).apply {
Expand Down
25 changes: 25 additions & 0 deletions lib/host/android_notifications.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,31 @@ class AndroidNotificationHostApi {
}
}

/// Corresponds to `androidx.core.app.NotificationManagerCompat.deleteNotificationChannel`
///
/// See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)
Future<void> deleteNotificationChannel(String channelId) async {
final String __pigeon_channelName = 'dev.flutter.pigeon.zulip.AndroidNotificationHostApi.deleteNotificationChannel$__pigeon_messageChannelSuffix';
final BasicMessageChannel<Object?> __pigeon_channel = BasicMessageChannel<Object?>(
__pigeon_channelName,
pigeonChannelCodec,
binaryMessenger: __pigeon_binaryMessenger,
);
final List<Object?>? __pigeon_replyList =
await __pigeon_channel.send(<Object?>[channelId]) as List<Object?>?;
if (__pigeon_replyList == null) {
throw _createConnectionError(__pigeon_channelName);
} else if (__pigeon_replyList.length > 1) {
throw PlatformException(
code: __pigeon_replyList[0]! as String,
message: __pigeon_replyList[1] as String?,
details: __pigeon_replyList[2],
);
} else {
return;
}
}

/// Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
///
/// See: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannel(androidx.core.app.NotificationChannelCompat)
Expand Down
5 changes: 5 additions & 0 deletions pigeon/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ abstract class AndroidNotificationHostApi {
/// See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#getNotificationChannelsCompat()
List<NotificationChannel> getNotificationChannels();

/// Corresponds to `androidx.core.app.NotificationManagerCompat.deleteNotificationChannel`
///
/// See: https://developer.android.com/reference/kotlin/androidx/core/app/NotificationManagerCompat#deleteNotificationChannel(java.lang.String)
void deleteNotificationChannel(String channelId);

/// Corresponds to `androidx.core.app.NotificationManagerCompat.createNotificationChannel`.
///
/// See: https://developer.android.com/reference/androidx/core/app/NotificationManagerCompat#createNotificationChannel(androidx.core.app.NotificationChannelCompat)
Expand Down
6 changes: 6 additions & 0 deletions test/model/binding.dart
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,12 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
throw UnimplementedError();
}

@override
Future<void> deleteNotificationChannel(String channelId) {
// TODO: implement deleteNotificationChannel
throw UnimplementedError();
}

@override
Future<void> createNotificationChannel(NotificationChannel channel) async {
_createdChannels.add(channel);
Expand Down

0 comments on commit 6bf675b

Please sign in to comment.