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
Notifications for new messages (Issue #162) #184
Conversation
Brilliant stuff, thanks! A few minor comments before I pull this:
Generally this is fantastic stuff, and I hope to be able to put this in v1.8.7. Thanks again! |
You're very welcome! I'll fix up those issues tonight and commit them. |
Absolutely -- I'll accept the pull request as soon as the changes are ready.
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:
Then to rebase your changes onto mine, switch to your branch, and do:
If there's a merge conflict, it can be resolved with Even better, 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(); |
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.
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.
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.
What do you mean by creating the alarm in the application class?
Initialization and declaration in one line.
The code now uses strings.xml values rather than hard-coded stuff and only stores message IDs in system preferences.
…ew-Message-Notification Conflicts: res/values-es/strings.xml
The Application class is here: 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). |
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); |
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.
The indentation seems to be broken here -- I think the tabs have been replaced with spaces for the whole onCreate method.
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. |
Yeah, I'm not fully happy with how it starts yet. You're right in that it requires a restart to function. |
Just credit me by my GitHub username. |
Notifications for new messages (Issue #162)
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 |
} catch (IndexOutOfBoundsException e) {} // No new messages | ||
|
||
} catch (Throwable t) { | ||
notifyFailure(RequestFailureType.PARSE, t, null, "Parse failure"); |
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.
Quick note for future reference -- IIRC notifyFailure()
just calls onFailure()
, so this doesn't do anything :)
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. |
That's fine -- feel free to leave it as-is.
No problem, let me know if you have any questions. |
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.