Skip to content

Commit b9addf2

Browse files
committed
notif [nfc]: Make shorter local alias for ZulipBinding.instance.androidNotificationHost
This is quite a mouthful and we repeat it a lot in this file. A nice short local name also helps things fit more easily on a line.
1 parent bfba284 commit b9addf2

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lib/notifications/display.dart

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import '../widgets/page.dart';
2020
import '../widgets/store.dart';
2121
import '../widgets/theme.dart';
2222

23+
AndroidNotificationHostApi get _androidHost => ZulipBinding.instance.androidNotificationHost;
24+
2325
/// Service for configuring our Android "notification channel".
2426
class NotificationChannelManager {
2527
@visibleForTesting
@@ -54,7 +56,7 @@ class NotificationChannelManager {
5456
// channel ID and delete it. See zulip-mobile's `createNotificationChannel`
5557
// in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt .
5658
static Future<void> _ensureChannel() async {
57-
await ZulipBinding.instance.androidNotificationHost.createNotificationChannel(NotificationChannel(
59+
await _androidHost.createNotificationChannel(NotificationChannel(
5860
id: kChannelId,
5961
name: 'Messages', // TODO(i18n)
6062
importance: NotificationImportance.high,
@@ -95,7 +97,7 @@ class NotificationDisplayManager {
9597
final groupKey = _groupKey(data);
9698
final conversationKey = _conversationKey(data, groupKey);
9799

98-
final oldMessagingStyle = await ZulipBinding.instance.androidNotificationHost
100+
final oldMessagingStyle = await _androidHost
99101
.getActiveNotificationMessagingStyleByTag(conversationKey);
100102

101103
final MessagingStyle messagingStyle;
@@ -141,7 +143,7 @@ class NotificationDisplayManager {
141143
name: data.senderFullName,
142144
iconBitmap: await _fetchBitmap(data.senderAvatarUrl))));
143145

144-
await ZulipBinding.instance.androidNotificationHost.notify(
146+
await _androidHost.notify(
145147
// TODO the notification ID can be constant, instead of matching requestCode
146148
// (This is a legacy of `flutter_local_notifications`.)
147149
id: notificationIdAsHashOf(conversationKey),
@@ -184,7 +186,7 @@ class NotificationDisplayManager {
184186
autoCancel: true,
185187
);
186188

187-
await ZulipBinding.instance.androidNotificationHost.notify(
189+
await _androidHost.notify(
188190
id: notificationIdAsHashOf(groupKey),
189191
tag: groupKey,
190192
channelId: NotificationChannelManager.kChannelId,
@@ -210,9 +212,8 @@ class NotificationDisplayManager {
210212
assert(debugLog('notif remove zulipMessageIds: ${data.zulipMessageIds}'));
211213

212214
final groupKey = _groupKey(data);
213-
final activeNotifications =
214-
await ZulipBinding.instance.androidNotificationHost.getActiveNotifications(
215-
desiredExtras: [kExtraZulipMessageId]);
215+
final activeNotifications = await _androidHost.getActiveNotifications(
216+
desiredExtras: [kExtraZulipMessageId]);
216217

217218
var haveRemaining = false;
218219
for (final statusBarNotification in activeNotifications) {
@@ -237,8 +238,8 @@ class NotificationDisplayManager {
237238
if (data.zulipMessageIds.contains(lastMessageId)) {
238239
// The latest Zulip message in this conversation was read.
239240
// That's our cue to cancel the notification for the conversation.
240-
await ZulipBinding.instance.androidNotificationHost
241-
.cancel(tag: statusBarNotification.tag, id: statusBarNotification.id);
241+
await _androidHost.cancel(
242+
tag: statusBarNotification.tag, id: statusBarNotification.id);
242243
assert(debugLog(' … notif cancelled.'));
243244
} else {
244245
// This notification is for another conversation that's still unread.
@@ -254,8 +255,8 @@ class NotificationDisplayManager {
254255
// Even though we enable the `autoCancel` flag for summary notification
255256
// during creation, the summary notification doesn't get auto canceled if
256257
// child notifications are canceled programatically as done above.
257-
await ZulipBinding.instance.androidNotificationHost
258-
.cancel(tag: groupKey, id: notificationIdAsHashOf(groupKey));
258+
await _androidHost.cancel(
259+
tag: groupKey, id: notificationIdAsHashOf(groupKey));
259260
}
260261
}
261262

0 commit comments

Comments
 (0)