Skip to content

Commit

Permalink
notification can now take to reviewer Activity if review was in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
IAmJaishree committed Mar 17, 2021
1 parent 7921fc2 commit 68882a5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
14 changes: 14 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/Reviewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.ichi2.anki.dialogs.RescheduleDialog;
import com.ichi2.anki.reviewer.PeripheralKeymap;
import com.ichi2.anki.reviewer.ReviewerUi;
import com.ichi2.anki.services.NotificationService;
import com.ichi2.anki.workarounds.FirefoxSnackbarWorkaround;
import com.ichi2.anki.reviewer.ActionButtons;
import com.ichi2.async.CollectionTask;
Expand Down Expand Up @@ -162,6 +163,19 @@ public void onPostExecute(PairWithBoolean<Card[]> result) {

@Override
protected void onCreate(Bundle savedInstanceState) {

//This checks if the control came here through Notification tap.
if (getIntent().getExtras() != null && getIntent().getExtras().containsKey(NotificationService.THROUGH_NOTIFICATION)) {
/* It verifies if there are pending cards to review
if there are pending cards, then this Activity will resume the pending Review
else the control will go to the DeckPicker Activity to show the Deck List
*/
if (getCol().getSched().count() == 0) {
startActivityWithoutAnimation(new Intent(this, DeckPicker.class));
finishWithoutAnimation();
}
}

if (showedActivityFailedScreen(savedInstanceState)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
import androidx.core.content.ContextCompat;

import com.ichi2.anki.AnkiDroidApp;
import com.ichi2.anki.CollectionHelper;
import com.ichi2.anki.DeckPicker;
import com.ichi2.anki.NotificationChannels;
import com.ichi2.anki.Preferences;
import com.ichi2.anki.R;
import com.ichi2.anki.Reviewer;
import com.ichi2.libanki.Card;
import com.ichi2.widget.WidgetStatus;

import timber.log.Timber;
Expand All @@ -40,6 +43,11 @@ public class NotificationService extends BroadcastReceiver {

public static final String INTENT_ACTION = "com.ichi2.anki.intent.action.SHOW_NOTIFICATION";

/**
* This constant is used by Activities to check if the control came from Notification tap.
*/
public static final String THROUGH_NOTIFICATION = "throughNotification";

@Override
public void onReceive(Context context, Intent intent) {
Timber.i("NotificationService: OnStartCommand");
Expand Down Expand Up @@ -71,7 +79,14 @@ public void onReceive(Context context, Intent intent) {
builder.setLights(Color.BLUE, 1000, 1000);
}
// Creates an explicit intent for an Activity in your app
Intent resultIntent = new Intent(context, DeckPicker.class);
// If there are pending reviews then tapping the notification will open Review Activity instead of DeckPicer Activity
Intent resultIntent;
if (CollectionHelper.getInstance().getCol(context).getSched().count() > 0) {
resultIntent = new Intent(context, Reviewer.class);
resultIntent.putExtra(THROUGH_NOTIFICATION, true);
} else {
resultIntent = new Intent(context, DeckPicker.class);
}
resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Expand Down

0 comments on commit 68882a5

Please sign in to comment.