From 16b765a6b864125fdc865802100814800ff2a265 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 7 Jan 2016 21:51:22 +1100 Subject: [PATCH] Handle add repo intents after F-Droid is already open. Before, it only happened in onResume(). Now, it happens in onNewIntent() too (but ensures to only handle the same intent once). Note the onResume() only ever handles the original intent, not the new intent. Fixes #524. --- F-Droid/src/org/fdroid/fdroid/FDroid.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/FDroid.java b/F-Droid/src/org/fdroid/fdroid/FDroid.java index 54a1ff618..37ae1d41f 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroid.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroid.java @@ -65,6 +65,8 @@ public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextL public static final String ACTION_ADD_REPO = "org.fdroid.fdroid.FDroid.ACTION_ADD_REPO"; + private static final String ADD_REPO_INTENT_HANDLED = "addRepoIntentHandled"; + private FDroidApp fdroidApp; private ViewPager viewPager; @@ -135,13 +137,24 @@ public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextL super.onResume(); // AppDetails and RepoDetailsActivity set different NFC actions, so reset here NfcHelper.setAndroidBeam(this, getApplication().getPackageName()); - checkForAddRepoIntent(); + checkForAddRepoIntent(getIntent()); } @Override protected void onNewIntent(Intent intent) { super.onNewIntent(intent); handleSearchOrAppViewIntent(intent); + + // This is called here as well as onResume(), because onNewIntent() is not called the first + // time the activity is created. An alternative option to make sure that the add repo intent + // is always handled is to call setIntent(intent) here. However, after this good read: + // http://stackoverflow.com/a/7749347 it seems that adding a repo is not really more + // important than the original intent which caused the activity to start (even though it + // could technically have been an add repo intent itself). + // The end result is that this method will be called twice for one add repo intent. Once + // here and once in onResume(). However, the method deals with this by ensuring it only + // handles the same intent once. + checkForAddRepoIntent(intent); } private void handleSearchOrAppViewIntent(Intent intent) { @@ -236,14 +249,13 @@ public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextL } } - private void checkForAddRepoIntent() { + private void checkForAddRepoIntent(Intent intent) { // Don't handle the intent after coming back to this view (e.g. after hitting the back button) // http://stackoverflow.com/a/14820849 - Intent intent = getIntent(); - if (!intent.hasExtra("handled")) { + if (!intent.hasExtra(ADD_REPO_INTENT_HANDLED)) { NewRepoConfig parser = new NewRepoConfig(this, intent); if (parser.isValidRepo()) { - intent.putExtra("handled", true); + intent.putExtra(ADD_REPO_INTENT_HANDLED, true); if (parser.isFromSwap()) { Intent confirmIntent = new Intent(this, SwapWorkflowActivity.class); confirmIntent.putExtra(SwapWorkflowActivity.EXTRA_CONFIRM, true);