From ea311c993e8e1d5a5c378b93f98e32777d06d9b7 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Wed, 25 Dec 2024 21:35:24 +0100 Subject: [PATCH] Deeplink to reviewer closes everything 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 f26aa95bdf4bb0fb378da1bf626a70eecb46a2e5. 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 --- .../main/java/com/ichi2/anki/IntentHandler.kt | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt b/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt index 1908de4dfe0d..d6164158555d 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/IntentHandler.kt @@ -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) @@ -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() } @@ -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) } } }