Skip to content
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

Implemented daily notification with custom time #33

Merged
merged 4 commits into from
May 15, 2018

Conversation

javiercbk
Copy link
Contributor

@javiercbk javiercbk commented May 11, 2018

I've implemented it for android, I'll try to make it work for IOS as well

Caveat: The notification time is hardcoded in the example app

screen shot 2018-05-11 at 00 13 21

screen shot 2018-05-11 at 00 13 08

Copy link
Owner

@MaikuB MaikuB left a comment

Choose a reason for hiding this comment

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

Looks good! I've left some comments on what I'd say should be changed. Also need to update the rescheduleNotifications() method in FlutterLocalNotificationsPlugin.java. That method is called when a device has been rebooted. Anything scheduled via the alarm manager is wiped out when the device has been turned off.

Once you've done the iOS side. I'll take a look and see if I can test out your fork before I'll merge it in. Also I've no problem with hardcoding the time in the example app as it's just for demonstration purposes so you'd need to do that anyway :)

{String payload}) async {
Map<String, dynamic> serializedPlatformSpecifics =
_retrievePlatformSpecificNotificationDetails(notificationDetails);
await _channel.invokeMethod('periodicallyShow', <String, dynamic>{
Copy link
Owner

Choose a reason for hiding this comment

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

invokeMethod should pass in 'showDailyAtTime' for better separation. This means that the onMethodCall override on the native side will need a different case to handle what needs to be done. If you could also split up repeatNotification to two separate methods (one for interval-based, the other for time-based) then that would be good as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have chosen this approach because I considered this feature as a Daily periodicallyShow use case, that way changes in both Java and Objective-C remain minimal. I can add that change though.

Copy link
Owner

Choose a reason for hiding this comment

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

Valid point, however from the Dart side they're separate methods so from a maintainability perspective, I think it's better to separate it out as it makes mapping between the Java/Objective C and Dart more obvious


Time([this.hour = 0, this.minute = 0, this.second = 0]);

Map<String, int> get serialized => {
Copy link
Owner

Choose a reason for hiding this comment

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

if you could make this a toMap() method to be consistent with the rest of the code then that would be great as reading something like time.serialized feels awkward

final int minute;
final int second;

Time([this.hour = 0, this.minute = 0, this.second = 0]);
Copy link
Owner

Choose a reason for hiding this comment

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

there should be some validation here to restrict the accepted values, possibly through assert statements. Should add documentation as well through comments but you can leave that for me to do

javiercbk added 2 commits May 11, 2018 04:13
fixed bad time constructor

Fixed param name, suppresed warning

Better notification body
@javiercbk
Copy link
Contributor Author

Added support to IOS as well

screen shot 2018-05-11 at 04 11 49

screen shot 2018-05-11 at 04 11 41

@MaikuB
Copy link
Owner

MaikuB commented May 11, 2018

Yep I took a look and it looks about right but will need some of the changes I commented about earlier regarding the string that's passed from Dart side via the invokeMethod call. I think once all the changes are made, we're good to merge it. I'll then do some clean up and testing before publishing a new version.

Thanks for your contribution btw. I've just realised that I've been using your JSON to Dart tool. Super handy and I've asked on the Flutter repo about putting a link to your site but go no response :S

@javiercbk
Copy link
Contributor Author

I've made the requested changes to the Dart's Time class. I'll make the other changes tomorrow.

Glad that my Dart to JSON tool is helping others

@javiercbk
Copy link
Contributor Author

I've added a weekday bitwise flag option. I haven't test it though but I will tonight

@MaikuB
Copy link
Owner

MaikuB commented May 14, 2018

By that are you referring to the ability to just have notifications displayed on weekdays only? If so then I don't think that works for the user notifications framework on iOS with the date components as you'd have to create a separate notification for each day, which means each one has their own ID. On that note, i think it'll be possible to schedule a notification to fire on a specified a day of the week and time but that's a separate discussion :)

@javiercbk
Copy link
Contributor Author

javiercbk commented May 14, 2018

In android it was easy, you just schedule a notification every day and when the intent is fired you just choose not to fire the notification. In IOS things are a bit mor complicated, you have to schedule one notification for each day.

My first solution is to provide the first notification ID and then increment the number internally. But that solution is really ugly because the plugin user would have to calculate the new notifications id. This is just a proof of concept. If it works I would generate the notification id with some uuid or the unix timestamp and return an array of ids. That of course would break the default API usage because there would be a single function that does generate the ids for you but the others won't.

It would be up to you to accept that change or not and I would understand if you don't want that change in your project. In that case I would create a plugin of my own and publish it because I need weekdays notifications for my project :)

@MaikuB
Copy link
Owner

MaikuB commented May 14, 2018

Yeah I had a feeling Android would be easier and that it would be more harder on iOS. I would say leave that for the moment and if you could make the other changes then we can merge this PR in. Looking at how to do it for weekdays can be done in a separate PR or something I can look into even

@javiercbk
Copy link
Contributor Author

javiercbk commented May 14, 2018

Ok, let me wrap up what I got and finish this PR tonight (It's 19:45 Argentina so I guess that I would finish this in a couple of hours)

@MaikuB
Copy link
Owner

MaikuB commented May 14, 2018

Cheers mate. I should have some bandwidth to look into the weekday one and touched on the rough idea i've got for it :)

@javiercbk
Copy link
Contributor Author

javiercbk commented May 15, 2018

Done, I've created a custom name for the new channel method and reverted the changes on the weekdays. I've created a new branch on my fork with my work on weekdays notification. I'll leave that branch for you to check the code.

Since I need to send notifications on weekdays for my app, I'have to create my own plugin to do that. I prefer swift over Objective C but probably I will reusing some parts of this project and I'll mention you and your project as well in the library that I'm creating.

Let me know if you need anything. Cheers

@MaikuB
Copy link
Owner

MaikuB commented May 15, 2018

Np, I should be able to merge your changes later. I do prefer Swift as well except I originally ran into issues with debugging in Swift. I heard there use to be issues with plugins written in Swift that were consumed by apps where the iOS head project is in Objective C. Not sure if that issue still exists as it's not something I've been monitoring

@MaikuB MaikuB merged commit e353dfd into MaikuB:master May 15, 2018
@MaikuB
Copy link
Owner

MaikuB commented May 16, 2018

fyi, i've uploaded a new version that includes your changes with fixes I made. Also added ability to show a weekly notification on a specific day and time that you could also use to solve your problem for showing notifications on weekdays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants