Skip to content

Commit 6d69b16

Browse files
rajveermalviyagnprice
authored andcommitted
notif: Replace flutter_local_notification createNotificationChannel with pigeon
Updates zulip#351
1 parent 1f641b7 commit 6d69b16

File tree

3 files changed

+28
-34
lines changed

3 files changed

+28
-34
lines changed

lib/notifications/display.dart

+8-10
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,14 @@ class NotificationChannelManager {
5353
// channel ID and delete it. See zulip-mobile's `createNotificationChannel`
5454
// in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt .
5555
static Future<void> _ensureChannel() async {
56-
final plugin = ZulipBinding.instance.notifications;
57-
await plugin.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
58-
?.createNotificationChannel(AndroidNotificationChannel(
59-
kChannelId,
60-
'Messages', // TODO(i18n)
61-
importance: Importance.high,
62-
enableLights: true,
63-
vibrationPattern: kVibrationPattern,
64-
// TODO(#340) sound
65-
));
56+
await ZulipBinding.instance.androidNotificationHost.createNotificationChannel(NotificationChannel(
57+
id: kChannelId,
58+
name: 'Messages', // TODO(i18n)
59+
importance: NotificationImportance.high,
60+
lightsEnabled: true,
61+
vibrationPattern: kVibrationPattern,
62+
// TODO(#340) sound
63+
));
6664
}
6765
}
6866

test/model/binding.dart

+13-3
Original file line numberDiff line numberDiff line change
@@ -578,10 +578,20 @@ class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterL
578578
}
579579

580580
class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
581+
/// Consume the log of calls made to [createNotificationChannel].
582+
///
583+
/// This returns a list of the arguments to all calls made
584+
/// to [createNotificationChannel] since the last call to this method.
585+
List<NotificationChannel> takeCreatedChannels() {
586+
final result = _createdChannels;
587+
_createdChannels = [];
588+
return result;
589+
}
590+
List<NotificationChannel> _createdChannels = [];
591+
581592
@override
582-
Future<void> createNotificationChannel(NotificationChannel channel) {
583-
// TODO: implement createNotificationChannel
584-
throw UnimplementedError();
593+
Future<void> createNotificationChannel(NotificationChannel channel) async {
594+
_createdChannels.add(channel);
585595
}
586596

587597
/// Consume the log of calls made to [notify].

test/notifications/display_test.dart

+7-21
Original file line numberDiff line numberDiff line change
@@ -90,20 +90,13 @@ void main() {
9090
group('NotificationChannelManager', () {
9191
test('smoke', () async {
9292
await init();
93-
check(notifAndroid.takeCreatedChannels()).single
93+
check(testBinding.androidNotificationHost.takeCreatedChannels()).single
9494
..id.equals(NotificationChannelManager.kChannelId)
9595
..name.equals('Messages')
96-
..description.isNull()
97-
..groupId.isNull()
98-
..importance.equals(Importance.high)
99-
..playSound.isTrue()
100-
..sound.isNull()
101-
..enableVibration.isTrue()
96+
..importance.equals(NotificationImportance.high)
97+
..lightsEnabled.equals(true)
10298
..vibrationPattern.isNotNull().deepEquals(
10399
NotificationChannelManager.kVibrationPattern)
104-
..showBadge.isTrue()
105-
..enableLights.isTrue()
106-
..ledColor.isNull()
107100
;
108101
});
109102
});
@@ -464,19 +457,12 @@ void main() {
464457
});
465458
}
466459

467-
extension AndroidNotificationChannelChecks on Subject<AndroidNotificationChannel> {
460+
extension NotificationChannelChecks on Subject<NotificationChannel> {
468461
Subject<String> get id => has((x) => x.id, 'id');
469-
Subject<String> get name => has((x) => x.name, 'name');
470-
Subject<String?> get description => has((x) => x.description, 'description');
471-
Subject<String?> get groupId => has((x) => x.groupId, 'groupId');
472-
Subject<Importance> get importance => has((x) => x.importance, 'importance');
473-
Subject<bool> get playSound => has((x) => x.playSound, 'playSound');
474-
Subject<AndroidNotificationSound?> get sound => has((x) => x.sound, 'sound');
475-
Subject<bool> get enableVibration => has((x) => x.enableVibration, 'enableVibration');
476-
Subject<bool> get enableLights => has((x) => x.enableLights, 'enableLights');
462+
Subject<int> get importance => has((x) => x.importance, 'importance');
463+
Subject<String?> get name => has((x) => x.name, 'name');
464+
Subject<bool?> get lightsEnabled => has((x) => x.lightsEnabled, 'lightsEnabled');
477465
Subject<Int64List?> get vibrationPattern => has((x) => x.vibrationPattern, 'vibrationPattern');
478-
Subject<Color?> get ledColor => has((x) => x.ledColor, 'ledColor');
479-
Subject<bool> get showBadge => has((x) => x.showBadge, 'showBadge');
480466
}
481467

482468
extension on Subject<AndroidNotificationHostApiNotifyCall> {

0 commit comments

Comments
 (0)