From 16b765a6b864125fdc865802100814800ff2a265 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 7 Jan 2016 21:51:22 +1100 Subject: [PATCH 1/3] 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); From b4bf5d6daf27856144c1e44f9633bd66c81a7253 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 7 Jan 2016 21:52:32 +1100 Subject: [PATCH 2/3] Remove unused constant. --- .../src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java | 1 - 1 file changed, 1 deletion(-) diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 3c1dc267b..5915cab5c 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -76,7 +76,6 @@ public class SwapWorkflowActivity extends AppCompatActivity { */ public static final String EXTRA_PREVENT_FURTHER_SWAP_REQUESTS = "preventFurtherSwap"; public static final String EXTRA_CONFIRM = "EXTRA_CONFIRM"; - public static final String EXTRA_REPO_ID = "repoId"; /** * Ensure that we don't try to handle specific intents more than once in onResume() From 315f1fa932eea6f7d170f75e90f1eca668635ff2 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 7 Jan 2016 21:52:49 +1100 Subject: [PATCH 3/3] Use a better name than "handled" for swap activity. Before, both the swap activity and the fdroid activity would use the "handled" key to check if an intent had been handled. This caused problems, because by the time we got to handling the add repo intent, it had already been "handled" by the swap activity so we bailed. --- .../org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 5915cab5c..27bd0a276 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -81,7 +81,7 @@ public class SwapWorkflowActivity extends AppCompatActivity { * Ensure that we don't try to handle specific intents more than once in onResume() * (e.g. the "Do you want to swap back with ..." intent). */ - public static final String EXTRA_HANDLED = "handled"; + public static final String EXTRA_SWAP_INTENT_HANDLED = "swapIntentHandled"; private ViewGroup container; @@ -209,10 +209,10 @@ public class SwapWorkflowActivity extends AppCompatActivity { private void checkIncomingIntent() { Intent intent = getIntent(); - if (intent.getBooleanExtra(EXTRA_CONFIRM, false) && !intent.getBooleanExtra(EXTRA_HANDLED, false)) { + if (intent.getBooleanExtra(EXTRA_CONFIRM, false) && !intent.getBooleanExtra(EXTRA_SWAP_INTENT_HANDLED, false)) { // Storing config in this variable will ensure that when showRelevantView() is next // run, it will show the connect swap view (if the service is available). - intent.putExtra(EXTRA_HANDLED, true); + intent.putExtra(EXTRA_SWAP_INTENT_HANDLED, true); confirmSwapConfig = new NewRepoConfig(this, intent); } }