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

Notifications for new messages (Issue #162) #184

Merged
merged 60 commits into from Nov 28, 2014
Merged

Notifications for new messages (Issue #162) #184

merged 60 commits into from Nov 28, 2014

Conversation

dsgkirkby
Copy link
Contributor

This addresses issue #162.

In the onCreate function of MainActivity, I added a call to create an Android alarm that triggers every hour.

I created a BroadcastReceiver that receives the alarm and checks for new messages on Reddit. Once it receives them, it parses the received messages and compares the newest message to the newest message from the previous check (which is saved in system preferences storage). If the new one is different, then the user has received a new message and a notification is broadcast to the user.

When the user taps this notification, it starts the app and there is a check in MainActivity of the Intent created by the activity to find out whether it is from a new message notification. If so, the inbox is opened for the user to view the new message they received.

Finally, I added a setting to enable/disable notifications, and I used Google Translate to provide translations of the setting's name.

@dsgkirkby dsgkirkby changed the title Notifications for new messages Notifications for new messages (Issue #162) Nov 25, 2014
@QuantumBadger
Copy link
Owner

Brilliant stuff, thanks!

A few minor comments before I pull this:

  • Please could you add a GPL copyright header to NewMessageChecker.java -- you can copy/paste this from another source file
  • It seems that NewMessageChecker remembers the last received message by serialising the entire message back to JSON (e.g. if (newMessage.toString().equals(oldMessage)) return;). This is really, really inefficient, and may fail to work in some cases. Please modify this to store just the ID of the message/comment. You can do this by doing the conversion from JsonValue to RedditComment/RedditMessage a bit earlier. The ID can be read from the RedditMessage.name and RedditComment.name fields.
  • The strings here should be moved to strings.xml. No need to translate them yourself :)
  • It's possible to remove the "project proposal" commits entirely using git rebase -i 8c326a3^ in the terminal and then deleting the two lines corresponding to those commits. I don't particularly mind you leaving them in though.
  • GitHub is telling me that a merge conflict has occurred, and the merge has to be done manually. I can do this for you if you want.

Generally this is fantastic stuff, and I hope to be able to put this in v1.8.7. Thanks again!

@dsgkirkby
Copy link
Contributor Author

You're very welcome! I'll fix up those issues tonight and commit them.
I'd be happy to do the merge but I don't know how to get the changes made on your end into my branch.
FYI, this was done for a school project (though I'll be contributing more in the future even though the project is now over!) and I get bonus marks if the pull request is accepted before Dec. 3rd - if you could accept it before then that would be greatly appreciated!

@QuantumBadger
Copy link
Owner

if the pull request is accepted before Dec. 3rd

Absolutely -- I'll accept the pull request as soon as the changes are ready.

I'd be happy to do the merge but I don't know how to get the changes made on your end into my branch.

That's fine. I'm not a GitHub expert, but to get the contents of my repo into your local branch, you could add mine as a remote:

git remote add qb https://github.com/QuantumBadger/RedReader
git fetch qb

Then to rebase your changes onto mine, switch to your branch, and do:

git rebase qb/master

If there's a merge conflict, it can be resolved with git mergetool. If you're using Linux, I'd recommend meld as a merge tool (sudo apt-get install meld).

Even better, git rebase -i qb/master would also let you remove the extraneous commits.

I'm more than happy to do this myself, although it'll mean I can't accept the pull request -- I'd have to do the merge locally and close the pull request on the site. Hopefully that should be sufficient to get credit for your project though, as you'd be able to point to my merge commit on the site.

if (startInbox) {
InboxListingFragment.newInstance().show(this);
} else {
startMessageChecker();
Copy link
Owner

Choose a reason for hiding this comment

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

I think this will actually create an alarm every time MainActivity is created. Over time this could add up to lots of alarms :)

I'd suggest either creating the alarm in the Application class, or ensuring that the alarm is destroyed in onDestroy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean by creating the alarm in the application class?

@QuantumBadger
Copy link
Owner

The Application class is here:

https://github.com/QuantumBadger/RedReader/blob/master/src/main/java/org/quantumbadger/redreader/RedReader.java

onCreate should only be called once for the whole application, so the alarm should be created there. The intent should be stored so that the alarm can be cancelled in onDestroy.

I think even this could end up leaking alarms, if the application force closes. I'm not sure there's a better way to do it though (other than starting the alarm at boot).

Dismissed notifications would pop up again.
@dsgkirkby
Copy link
Contributor Author

I think starting it at boot would be the best way, probably. I'll get that set up.

@@ -82,106 +86,111 @@
@Override
protected void onCreate(final Bundle savedInstanceState) {

PrefsUtility.applyTheme(this);
Copy link
Owner

Choose a reason for hiding this comment

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

The indentation seems to be broken here -- I think the tabs have been replaced with spaces for the whole onCreate method.

@QuantumBadger
Copy link
Owner

Thanks! I've made a couple of comments about indentation -- as soon as those are fixed I'll accept the pull request.

I'm still not 100% sure about whether the alarm behaviour is correct (e.g. I don't think the alarm will be set until the first reboot after installing), but I'll investigate that myself after pulling these changes into the main repo.

Thanks for all your work -- there are lots of people after this feature, and it'll be good to get it into v1.8.7. Please let me know how you'd like to be credited in the changelog.

@dsgkirkby
Copy link
Contributor Author

Yeah, I'm not fully happy with how it starts yet. You're right in that it requires a restart to function.
Maybe have some sort of static alarm stored somewhere (its own class?) and try to start it both at boot and app start?

@dsgkirkby
Copy link
Contributor Author

Just credit me by my GitHub username.

QuantumBadger added a commit that referenced this pull request Nov 28, 2014
@QuantumBadger QuantumBadger merged commit a20958f into QuantumBadger:master Nov 28, 2014
@QuantumBadger
Copy link
Owner

Thanks! I'll try this out myself and will look into the best way to schedule the alarm.

If you're looking for another feature to work on, multireddits would probably be a good choice (if you're feeling ambitious!) I'm guessing some of the code could be adapted from the current subreddit subscription logic (see RedditAPIIndividualSubredditListRequester, RedditSubredditSubscriptionManager, etc).

} catch (IndexOutOfBoundsException e) {} // No new messages

} catch (Throwable t) {
notifyFailure(RequestFailureType.PARSE, t, null, "Parse failure");
Copy link
Owner

Choose a reason for hiding this comment

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

Quick note for future reference -- IIRC notifyFailure() just calls onFailure(), so this doesn't do anything :)

@dsgkirkby
Copy link
Contributor Author

Ok. I think I'll try to put together a static alarm class myself as well. If I get something I think works well, I'll send it your way.
The code up there was copied straight from InboxListingFragment, do you want me to change it or leave it for consistency?
Multireddits could be fun, probably won't start til after my exams finish though.
Thanks a bunch for the feedback!

@QuantumBadger
Copy link
Owner

The code up there was copied straight from InboxListingFragment, do you want me to change it or leave it for consistency?

That's fine -- feel free to leave it as-is.

Multireddits could be fun, probably won't start til after my exams finish though.

No problem, let me know if you have any questions.

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.

None yet

3 participants