Skip to content

Commit

Permalink
Deeplink to reviewer closes everything
Browse files Browse the repository at this point in the history
Currently, the code ensured there was at most one IntentHandler. We
honestly don't care about it. The intended meaning was that there is a
single reviewer.

This bug was probably introduced in #17422 with commit
f26aa95.

I would love to test to avoid another regression. However, it's really
not clear to me how to deal with shortcuts, widget or remainders as
they are outside of the main app.

I discovered that having a single reviewer is still not
enough. Because what is below the reviewer could be nonsense. Instead,
I followed standard practice for deep link. I close everything and
create a fresh stack.

Bug #16956.
Fixes #17664.

Co-authored-by: Mike Hardy <github@mikehardy.net>
  • Loading branch information
2 people authored and david-allison committed Jan 4, 2025
1 parent 0b3f7a2 commit ea311c9
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class IntentHandler : AbstractIntentHandler() {
finish()
}
LaunchType.SYNC -> runIfStoragePermissions { handleSyncIntent(reloadIntent, action) }
LaunchType.REVIEW -> runIfStoragePermissions { handleReviewIntent(intent) }
LaunchType.REVIEW -> runIfStoragePermissions { handleReviewIntent(reloadIntent, intent) }
LaunchType.DEFAULT_START_APP_IF_NEW -> {
Timber.d("onCreate() performing default action")
launchDeckPickerIfNoOtherTasks(reloadIntent)
Expand Down Expand Up @@ -144,17 +144,29 @@ class IntentHandler : AbstractIntentHandler() {
}
}

private fun handleReviewIntent(intent: Intent) {
private fun handleReviewIntent(
reloadIntent: Intent,
reviewerIntent: Intent,
) {
val deckId = intent.getLongExtra(ReminderService.EXTRA_DECK_ID, 0)
Timber.i("Handling intent to review deck '%d'", deckId)

val reviewIntent =
if (sharedPrefs().getBoolean("newReviewer", false)) {
ReviewerFragment.getIntent(this)
} else {
Intent(this, Reviewer::class.java)
Intent(this, Reviewer::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}
CollectionManager.getColUnsafe().decks.select(deckId)
startActivity(reviewIntent)
// Clean the stack out under the reviewer to avoid any incorrect activities / dialogs /
// data state from prior app usage showing after reviewer exits if going to reviewer directly
TaskStackBuilder
.create(applicationContext)
.addNextIntent(reloadIntent)
.addNextIntent(reviewIntent)
.startActivities()
finish()
}

Expand Down Expand Up @@ -439,7 +451,6 @@ class IntentHandler : AbstractIntentHandler() {
) = Intent(context, IntentHandler::class.java).apply {
setAction(Intent.ACTION_VIEW)
putExtra(ReminderService.EXTRA_DECK_ID, deckId)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}
}

0 comments on commit ea311c9

Please sign in to comment.