-
Notifications
You must be signed in to change notification settings - Fork 316
notif: Use Zulip's notification sound on Android #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2771f58
7eef966
dcb3b36
2af661c
ca1eefd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,10 @@ AndroidNotificationHostApi get _androidHost => ZulipBinding.instance.androidNoti | |
/// Service for configuring our Android "notification channel". | ||
class NotificationChannelManager { | ||
@visibleForTesting | ||
static const kChannelId = 'messages-1'; | ||
static const kChannelId = 'messages-2'; | ||
|
||
@visibleForTesting | ||
static const kDefaultSoundResourceName = 'chime3'; // 'Zulip - Chime.m4a' | ||
|
||
/// The vibration pattern we set for notifications. | ||
// We try to set a vibration pattern that, with the phone in one's pocket, | ||
|
@@ -52,18 +55,34 @@ class NotificationChannelManager { | |
// settings for the channel -- like "override Do Not Disturb", or "use | ||
// a different sound", or "don't pop on screen" -- their changes get | ||
// reset. So this has to be done sparingly. | ||
// | ||
// If we do this, we should also look for any channel with the old | ||
// channel ID and delete it. See zulip-mobile's `createNotificationChannel` | ||
// in android/app/src/main/java/com/zulipmobile/notifications/NotificationChannelManager.kt . | ||
static Future<void> _ensureChannel() async { | ||
// See if our current-version channel already exists; delete any obsolete | ||
// previous channels. | ||
var found = false; | ||
final channels = await _androidHost.getNotificationChannels(); | ||
for (final channel in channels) { | ||
assert(channel != null); // TODO(flutter#97848) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: we can refer to #942 here |
||
if (channel!.id == kChannelId) { | ||
found = true; | ||
} else { | ||
await _androidHost.deleteNotificationChannel(channel.id); | ||
} | ||
} | ||
|
||
if (found) { | ||
// The channel already exists; nothing to do. | ||
return; | ||
} | ||
|
||
// The channel doesn't exist. Create it. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove empty line |
||
await _androidHost.createNotificationChannel(NotificationChannel( | ||
id: kChannelId, | ||
name: 'Messages', // TODO(i18n) | ||
importance: NotificationImportance.high, | ||
lightsEnabled: true, | ||
soundResourceName: kDefaultSoundResourceName, | ||
vibrationPattern: kVibrationPattern, | ||
// TODO(#340) sound | ||
)); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ class NotificationChannel { | |||||||||
required this.importance, | ||||||||||
this.name, | ||||||||||
this.lightsEnabled, | ||||||||||
this.soundResourceName, | ||||||||||
this.vibrationPattern, | ||||||||||
}); | ||||||||||
|
||||||||||
|
@@ -33,6 +34,15 @@ class NotificationChannel { | |||||||||
|
||||||||||
final String? name; | ||||||||||
final bool? lightsEnabled; | ||||||||||
|
||||||||||
/// The name of the sound file resource. | ||||||||||
/// | ||||||||||
/// The resource ID is retrieved using | ||||||||||
/// `android.content.res.Resources.getIdentifier`, which is then used to | ||||||||||
/// generate an `android.resource://` URI. This URI is then passed | ||||||||||
/// to the `NotificationChannelCompat` builder. | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could rephrase this to something similar to zulip-flutter/pigeon/notifications.dart Lines 172 to 175 in cdbe141
soundResourceName is expected to be known in keep.xml.
|
||||||||||
final String? soundResourceName; | ||||||||||
|
||||||||||
final Int64List? vibrationPattern; | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -155,6 +165,16 @@ class StatusBarNotification { | |||||||||
|
||||||||||
@HostApi() | ||||||||||
abstract class AndroidNotificationHostApi { | ||||||||||
/// Corresponds to `androidx.core.app.NotificationManagerCompat.getNotificationChannelsCompat`. | ||||||||||
/// | ||||||||||
/// 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) | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a comment similar to the one in 785df22.