Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

rajveermalviya
Copy link
Member

@rajveermalviya rajveermalviya commented Jun 2, 2024

Updates: #340

For now, only includes the default sound, i.e. it doesn't show multiple sound options in notification settings - this will be done in later PRs.


// Delete any older channels.
var found = false;
final channels = await androidPlugin.getNotificationChannels();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than add more parts of the package:flutter_local_notifications API that we use, let's use Pigeon for this. That way in order to be confident of understanding what the code is doing, we only have to read our own code and the Android docs, and not also the flutter_local_notifications code 🙂 (which often introduces a lot of logic of its own).

As a concrete strategy, let's put this issue after #351: so we convert the existing call sites first (the remaining ones, after #592 covered the most complex of them), and then we go on to add Pigeon bindings for more of the notifications API.

@gnprice gnprice marked this pull request as draft June 4, 2024 00:44
@rajveermalviya rajveermalviya force-pushed the notif-sound branch 3 times, most recently from c82baa1 to a018fe3 Compare August 23, 2024 22:43
@rajveermalviya rajveermalviya marked this pull request as ready for review August 23, 2024 22:43
@rajveermalviya rajveermalviya added the buddy review GSoC buddy review needed. label Aug 23, 2024
Copy link
Collaborator

@sm-sayedi sm-sayedi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rajveermalviya for this. A few small nits below, otherwise LGTM! I have also tested it on my phone, and the notification sound works fine.

As this PR was opened during the official GSoC period, let's move on to the mentor review with @sumanthvrao.

*
* The resource ID is retrieved using
* `android.content.res.Resources.getIdentifier`, which is then used to
* generate a `android.resource://` URI. This URI is then passed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* generate a `android.resource://` URI. This URI is then passed
* generate an `android.resource://` URI. This URI is then passed

///
/// The resource ID is retrieved using
/// `android.content.res.Resources.getIdentifier`, which is then used to
/// generate a `android.resource://` URI. This URI is then passed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// generate a `android.resource://` URI. This URI is then passed
/// generate an `android.resource://` URI. This URI is then passed

///
/// The resource ID is retrieved using
/// `android.content.res.Resources.getIdentifier`, which is then used to
/// generate a `android.resource://` URI. This URI is then passed
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// generate a `android.resource://` URI. This URI is then passed
/// generate an `android.resource://` URI. This URI is then passed

@sm-sayedi sm-sayedi added mentor review GSoC mentor review needed. and removed buddy review GSoC buddy review needed. labels Sep 2, 2024
@gnprice gnprice added the maintainer review PR ready for review by Zulip maintainers label Sep 10, 2024
@rajveermalviya rajveermalviya force-pushed the notif-sound branch 3 times, most recently from c5d12fb to 16b9f47 Compare September 11, 2024 16:28
@rajveermalviya
Copy link
Member Author

Thanks for the review @sm-sayedi, pushed a new revision.

Copy link
Member

@PIG208 PIG208 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Tested manually and it works well for me. Left some comments.

static const kChannelId = 'messages-2';

@visibleForTesting
static const kDefaultSoundResourceName = 'chime3'; // 'Zulip - Chime.m4a'
Copy link
Member

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.

/// 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could rephrase this to something similar to

/// The `smallIconResourceName` is passed to `android.content.res.Resources.getIdentifier`
/// to get a resource ID to pass to `Builder.setSmallIcon`.
/// Whatever name is passed there must appear in keep.xml too:
/// see https://github.com/zulip/zulip-flutter/issues/528 .
, mentioning how soundResourceName is expected to be known in keep.xml.

}

// The channel doesn't exist. Create it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove empty line

var found = false;
final channels = await _androidHost.getNotificationChannels();
for (final channel in channels) {
assert(channel != null); // TODO(flutter#97848)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can refer to #942 here

@rajveermalviya
Copy link
Member Author

I've split this PR into separate ones: #981 for the notification migration and #982 to support custom notification sounds. The reason for this is that unlike the current PR, #982 fully resolves issue #340 by allowing users to select multiple notification sounds from the settings. Because the full implementation commits became substantial, it seemed like it need to be split in separate PRs.

Thus closing this in favor of #981 and #982.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintainer review PR ready for review by Zulip maintainers mentor review GSoC mentor review needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants