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

Fix #4006: More advanced notification options #4450

Merged
merged 1 commit into from
Nov 2, 2016
Merged

Fix #4006: More advanced notification options #4450

merged 1 commit into from
Nov 2, 2016

Conversation

madhead
Copy link
Contributor

@madhead madhead commented Oct 9, 2016

No description provided.

@madhead
Copy link
Contributor Author

madhead commented Oct 13, 2016

This need some extra work. However, are you ok with the idea?

Copy link
Member

@hssm hssm left a comment

Choose a reason for hiding this comment

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

The idea is fine. Just added a couple of comments.

import android.content.SharedPreferences;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.*;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe you've set up your editor to do this automatically, but there is no reason to change these imports to wildcards in this PR.

+ "'reminder': {"
+ "'enabled': False,"
+ "'time': [0, 0]"
+ "},"
Copy link
Member

Choose a reason for hiding this comment

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

Don't add this to the default config. We try to avoid changing libanki code where it deviates from the original python, and in this case the feature will work without it since we already handle cases where it's missing.

break;
}
}
if ((null == deckDue) || (deckDue.newCount <= 0)) {
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 think it's better to use deckDue.revCount + deckDue.lrnCount + deckDue.newCount here, instead of just newCount, because sometimes there are no "new" cards, only reviews.

final long deckId = intent.getLongExtra(ReminderService.EXTRA_DECK_ID, 0);
Sched.DeckDueTreeNode deckDue = null;

for (Sched.DeckDueTreeNode node : CollectionHelper.getInstance().getCol(this).getSched().deckDueList()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

deckDueList() does not work for nested decks well, I should use deckDueTree() here

@timrae
Copy link
Member

timrae commented Oct 23, 2016

Are you ready for re-review?

@madhead
Copy link
Contributor Author

madhead commented Oct 23, 2016

Yes, @timrae, @hssm, please review this PR?

mValues.put("reminderEnabled", Boolean.toString(reminder.getBoolean("enabled")));
mValues.put("reminderTime", String.format("%1$02d:%2$02d", reminderTime.get(0), reminderTime.get(1)));
} else {
mValues.put("reminderEnabled", "false");
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to insert the preference value even when it's not enabled? I.e., can we get away with not adding the value into the user's collection unless they explicitly turn on the feature first?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes logic simpler in cases where user already had reminders enabled and want to disable them.

final AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
final PendingIntent reminderIntent = PendingIntent.getBroadcast(
getApplicationContext(),
(int) mDeck.getLong("id"),
Copy link
Member

@hssm hssm Oct 25, 2016

Choose a reason for hiding this comment

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

Will this cast (and all the other ones) cause a problem?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically, yes, it can cause a problem. E.g. if you have two decks, one with id equal to 2147484647 (Integer.MAX_INT + 1000) and the other with -2147482649, then both (int) 2147484647 and (int) -2147482649 will be the same value, -2147482649. But the expected argument type here is int, so data loss is inevitable, whether it is casting or bit shifts.

I just hope that users usually don't have thousands of decks and the probability of a collision is low.

Copy link
Member

Choose a reason for hiding this comment

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

It shouldn't be problem since we aren't writing any data back into the collection.


<string name="reminder_title">Do not forget to study today!</string>
<plurals name="reminder_text">
<item quantity="one">%1$s deck has %2$d new card to review</item>
Copy link
Member

Choose a reason for hiding this comment

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

I think you can reword this:

20 new cards to review in Japanese

The word "deck" shouldn't be necessary.,

0
);

alarmManager.cancel(reminderIntent);
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this belongs here.

Would it make more sense if the service, on handling an alarm, checks first to see if its deck still exists, and then cancel the alarm if it doesn't?

@hssm
Copy link
Member

hssm commented Nov 1, 2016

Okay, I think this is fine now. If you could squash this down to a single commit I will merge it.

@timrae
Copy link
Member

timrae commented Nov 1, 2016

Would you be able to add some documentation to the manual?
https://github.com/ankidroid/ankidroiddocs

@madhead
Copy link
Contributor Author

madhead commented Nov 1, 2016

Ok, I will.

@madhead
Copy link
Contributor Author

madhead commented Nov 1, 2016

Created a PR in the docs repo.

@timrae timrae merged commit 92df7d3 into ankidroid:develop Nov 2, 2016
@madhead madhead deleted the advanced_notifications branch November 2, 2016 08:17
@timrae
Copy link
Member

timrae commented Jan 18, 2017

@madhead
Do you have time to fix #4525 and #4530? There's talk about pulling the feature out of the final release if they can't be quickly fixed:

https://groups.google.com/forum/#!topic/anki-android/qgURUxwTFLg

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.

3 participants