Skip to content

Commit e37e269

Browse files
notif: Replace flutter_local_notification createNotificationChannel with pigeon
Updates zulip#351
1 parent 14be993 commit e37e269

File tree

3 files changed

+25
-51
lines changed

3 files changed

+25
-51
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

+10-15
Original file line numberDiff line numberDiff line change
@@ -474,27 +474,23 @@ class FakeFlutterLocalNotificationsPlugin extends Fake implements FlutterLocalNo
474474
}
475475

476476
class FakeAndroidFlutterLocalNotificationsPlugin extends Fake implements AndroidFlutterLocalNotificationsPlugin {
477+
}
478+
479+
class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterLocalNotificationsPlugin {
480+
}
481+
482+
class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
477483
/// Consume the log of calls made to [createNotificationChannel].
478484
///
479485
/// This returns a list of the arguments to all calls made
480486
/// to [createNotificationChannel] since the last call to this method.
481-
List<AndroidNotificationChannel> takeCreatedChannels() {
487+
List<NotificationChannel> takeCreatedChannels() {
482488
final result = _createdChannels;
483489
_createdChannels = [];
484490
return result;
485491
}
486-
List<AndroidNotificationChannel> _createdChannels = [];
487-
488-
@override
489-
Future<void> createNotificationChannel(AndroidNotificationChannel notificationChannel) async {
490-
_createdChannels.add(notificationChannel);
491-
}
492-
}
492+
List<NotificationChannel> _createdChannels = [];
493493

494-
class FakeIOSFlutterLocalNotificationsPlugin extends Fake implements IOSFlutterLocalNotificationsPlugin {
495-
}
496-
497-
class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
498494
/// Consume the log of calls made to [notify].
499495
///
500496
/// This returns a list of the arguments to all calls made
@@ -514,9 +510,8 @@ class FakeAndroidNotificationHostApi implements AndroidNotificationHostApi {
514510
}
515511

516512
@override
517-
Future<void> createNotificationChannel(NotificationChannel channel) {
518-
// TODO: implement createNotificationChannel
519-
throw UnimplementedError();
513+
Future<void> createNotificationChannel(NotificationChannel channel) async {
514+
_createdChannels.add(channel);
520515
}
521516

522517
@override

test/notifications/display_test.dart

+7-26
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ import '../test_navigation.dart';
2929
import '../widgets/message_list_checks.dart';
3030
import '../widgets/page_checks.dart';
3131

32-
FakeAndroidFlutterLocalNotificationsPlugin get notifAndroid =>
33-
testBinding.notifications
34-
.resolvePlatformSpecificImplementation<AndroidFlutterLocalNotificationsPlugin>()
35-
as FakeAndroidFlutterLocalNotificationsPlugin;
36-
3732
MessageFcmMessage messageFcmMessage(
3833
Message zulipMessage, {
3934
String? streamName,
@@ -90,20 +85,13 @@ void main() {
9085
group('NotificationChannelManager', () {
9186
test('smoke', () async {
9287
await init();
93-
check(notifAndroid.takeCreatedChannels()).single
88+
check(testBinding.androidNotificationHost.takeCreatedChannels()).single
9489
..id.equals(NotificationChannelManager.kChannelId)
9590
..name.equals('Messages')
96-
..description.isNull()
97-
..groupId.isNull()
98-
..importance.equals(Importance.high)
99-
..playSound.isTrue()
100-
..sound.isNull()
101-
..enableVibration.isTrue()
91+
..importance.equals(NotificationImportance.high)
92+
..lightsEnabled.equals(true)
10293
..vibrationPattern.isNotNull().deepEquals(
10394
NotificationChannelManager.kVibrationPattern)
104-
..showBadge.isTrue()
105-
..enableLights.isTrue()
106-
..ledColor.isNull()
10795
;
10896
});
10997
});
@@ -462,19 +450,12 @@ void main() {
462450
});
463451
}
464452

465-
extension AndroidNotificationChannelChecks on Subject<AndroidNotificationChannel> {
453+
extension NotificationChannelChecks on Subject<NotificationChannel> {
466454
Subject<String> get id => has((x) => x.id, 'id');
467-
Subject<String> get name => has((x) => x.name, 'name');
468-
Subject<String?> get description => has((x) => x.description, 'description');
469-
Subject<String?> get groupId => has((x) => x.groupId, 'groupId');
470-
Subject<Importance> get importance => has((x) => x.importance, 'importance');
471-
Subject<bool> get playSound => has((x) => x.playSound, 'playSound');
472-
Subject<AndroidNotificationSound?> get sound => has((x) => x.sound, 'sound');
473-
Subject<bool> get enableVibration => has((x) => x.enableVibration, 'enableVibration');
474-
Subject<bool> get enableLights => has((x) => x.enableLights, 'enableLights');
455+
Subject<int> get importance => has((x) => x.importance, 'importance');
456+
Subject<String?> get name => has((x) => x.name, 'name');
457+
Subject<bool?> get lightsEnabled => has((x) => x.lightsEnabled, 'lightsEnabled');
475458
Subject<Int64List?> get vibrationPattern => has((x) => x.vibrationPattern, 'vibrationPattern');
476-
Subject<Color?> get ledColor => has((x) => x.ledColor, 'ledColor');
477-
Subject<bool> get showBadge => has((x) => x.showBadge, 'showBadge');
478459
}
479460

480461
extension on Subject<AndroidNotificationHostApiNotifyCall> {

0 commit comments

Comments
 (0)