Skip to content

Commit 1f9a5c6

Browse files
pigeon: Add binding for NotificationChannel.soundUrl
1 parent a41f4fe commit 1f9a5c6

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ data class NotificationChannel (
6262
val importance: Long,
6363
val name: String? = null,
6464
val lightsEnabled: Boolean? = null,
65+
val soundUri: String? = null,
6566
val vibrationPattern: LongArray? = null
6667

6768
) {
@@ -72,8 +73,9 @@ data class NotificationChannel (
7273
val importance = __pigeon_list[1].let { num -> if (num is Int) num.toLong() else num as Long }
7374
val name = __pigeon_list[2] as String?
7475
val lightsEnabled = __pigeon_list[3] as Boolean?
75-
val vibrationPattern = __pigeon_list[4] as LongArray?
76-
return NotificationChannel(id, importance, name, lightsEnabled, vibrationPattern)
76+
val soundUri = __pigeon_list[4] as String?
77+
val vibrationPattern = __pigeon_list[5] as LongArray?
78+
return NotificationChannel(id, importance, name, lightsEnabled, soundUri, vibrationPattern)
7779
}
7880
}
7981
fun toList(): List<Any?> {
@@ -82,6 +84,7 @@ data class NotificationChannel (
8284
importance,
8385
name,
8486
lightsEnabled,
87+
soundUri,
8588
vibrationPattern,
8689
)
8790
}

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

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.content.ContentUris
55
import android.content.ContentValues
66
import android.content.Context
77
import android.content.Intent
8+
import android.media.AudioAttributes
89
import android.net.Uri
910
import android.os.Build
1011
import android.os.Bundle
@@ -60,6 +61,10 @@ private class AndroidNotificationHost(val context: Context)
6061
.Builder(channel.id, channel.importance.toInt()).apply {
6162
channel.name?.let { setName(it) }
6263
channel.lightsEnabled?.let { setLightsEnabled(it) }
64+
channel.soundUri?.let {
65+
setSound(Uri.parse(it),
66+
AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build())
67+
}
6368
channel.vibrationPattern?.let { setVibrationPattern(it) }
6469
}.build()
6570
NotificationManagerCompat.from(context).createNotificationChannel(notificationChannel)

lib/host/android_notifications.g.dart

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class NotificationChannel {
2424
required this.importance,
2525
this.name,
2626
this.lightsEnabled,
27+
this.soundUri,
2728
this.vibrationPattern,
2829
});
2930

@@ -39,6 +40,8 @@ class NotificationChannel {
3940

4041
bool? lightsEnabled;
4142

43+
String? soundUri;
44+
4245
Int64List? vibrationPattern;
4346

4447
Object encode() {
@@ -47,6 +50,7 @@ class NotificationChannel {
4750
importance,
4851
name,
4952
lightsEnabled,
53+
soundUri,
5054
vibrationPattern,
5155
];
5256
}
@@ -58,7 +62,8 @@ class NotificationChannel {
5862
importance: result[1]! as int,
5963
name: result[2] as String?,
6064
lightsEnabled: result[3] as bool?,
61-
vibrationPattern: result[4] as Int64List?,
65+
soundUri: result[4] as String?,
66+
vibrationPattern: result[5] as Int64List?,
6267
);
6368
}
6469
}

pigeon/notifications.dart

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class NotificationChannel {
2020
required this.importance,
2121
this.name,
2222
this.lightsEnabled,
23+
this.soundUri,
2324
this.vibrationPattern,
2425
});
2526

@@ -33,6 +34,7 @@ class NotificationChannel {
3334

3435
final String? name;
3536
final bool? lightsEnabled;
37+
final String? soundUri;
3638
final Int64List? vibrationPattern;
3739
}
3840

test/notifications/display_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ void main() {
129129
..name.equals('Messages')
130130
..importance.equals(NotificationImportance.high)
131131
..lightsEnabled.equals(true)
132+
..soundUri.isNull()
132133
..vibrationPattern.isNotNull().deepEquals(
133134
NotificationChannelManager.kVibrationPattern)
134135
;
@@ -1186,6 +1187,7 @@ extension NotificationChannelChecks on Subject<NotificationChannel> {
11861187
Subject<int> get importance => has((x) => x.importance, 'importance');
11871188
Subject<String?> get name => has((x) => x.name, 'name');
11881189
Subject<bool?> get lightsEnabled => has((x) => x.lightsEnabled, 'lightsEnabled');
1190+
Subject<String?> get soundUri => has((x) => x.soundUri, 'soundUri');
11891191
Subject<Int64List?> get vibrationPattern => has((x) => x.vibrationPattern, 'vibrationPattern');
11901192
}
11911193

0 commit comments

Comments
 (0)