use one method everywhere for the "swap back" requests

This commit is contained in:
Hans-Christoph Steiner 2019-05-15 12:53:45 +02:00
parent 014fb0b99d
commit d5f2e26ea7
3 changed files with 19 additions and 24 deletions

View File

@ -19,10 +19,15 @@
package org.fdroid.fdroid.views.swap; package org.fdroid.fdroid.views.swap;
import android.content.Context;
import android.net.Uri;
/** /**
* Dummy version for basic app flavor. * Dummy version for basic app flavor.
*/ */
public class SwapWorkflowActivity { public class SwapWorkflowActivity {
public static final String EXTRA_PREVENT_FURTHER_SWAP_REQUESTS = "preventFurtherSwap"; public static final String EXTRA_PREVENT_FURTHER_SWAP_REQUESTS = "preventFurtherSwap";
public static final String EXTRA_CONFIRM = "EXTRA_CONFIRM"; public static final String EXTRA_CONFIRM = "EXTRA_CONFIRM";
public static void requestSwap(Context context, Uri uri) {
};
} }

View File

@ -62,6 +62,7 @@ import org.fdroid.fdroid.localrepo.peers.Peer;
import org.fdroid.fdroid.net.BluetoothDownloader; import org.fdroid.fdroid.net.BluetoothDownloader;
import org.fdroid.fdroid.net.HttpDownloader; import org.fdroid.fdroid.net.HttpDownloader;
import org.fdroid.fdroid.net.WifiStateChangeService; import org.fdroid.fdroid.net.WifiStateChangeService;
import org.fdroid.fdroid.views.main.MainActivity;
import org.fdroid.fdroid.views.swap.device.camera.CameraCharacteristicsChecker; import org.fdroid.fdroid.views.swap.device.camera.CameraCharacteristicsChecker;
import java.util.Date; import java.util.Date;
@ -72,6 +73,8 @@ import java.util.Set;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import static org.fdroid.fdroid.views.main.MainActivity.ACTION_REQUEST_SWAP;
/** /**
* This activity will do its best to show the most relevant screen about swapping to the user. * This activity will do its best to show the most relevant screen about swapping to the user.
* The problem comes when there are two competing goals - 1) Show the user a list of apps from another * The problem comes when there are two competing goals - 1) Show the user a list of apps from another
@ -89,13 +92,6 @@ public class SwapWorkflowActivity extends AppCompatActivity {
* among each other offering swaps. * among each other offering swaps.
*/ */
public static final String EXTRA_PREVENT_FURTHER_SWAP_REQUESTS = "preventFurtherSwap"; public static final String EXTRA_PREVENT_FURTHER_SWAP_REQUESTS = "preventFurtherSwap";
public static final String EXTRA_CONFIRM = "EXTRA_CONFIRM";
/**
* 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_SWAP_INTENT_HANDLED = "swapIntentHandled";
private ViewGroup container; private ViewGroup container;
@ -113,10 +109,11 @@ public class SwapWorkflowActivity extends AppCompatActivity {
private WifiManager wifiManager; private WifiManager wifiManager;
public static void requestSwap(Context context, String repo) { public static void requestSwap(Context context, String repo) {
Uri repoUri = Uri.parse(repo); requestSwap(context, Uri.parse(repo));
Intent intent = new Intent(context, SwapWorkflowActivity.class); }
intent.setData(repoUri);
intent.putExtra(EXTRA_CONFIRM, true); public static void requestSwap(Context context, Uri uri) {
Intent intent = new Intent(MainActivity.ACTION_REQUEST_SWAP, uri, context, SwapWorkflowActivity.class);
intent.putExtra(EXTRA_PREVENT_FURTHER_SWAP_REQUESTS, true); intent.putExtra(EXTRA_PREVENT_FURTHER_SWAP_REQUESTS, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
@ -358,20 +355,17 @@ public class SwapWorkflowActivity extends AppCompatActivity {
*/ */
private void checkIncomingIntent() { private void checkIncomingIntent() {
Intent intent = getIntent(); Intent intent = getIntent();
if (!ACTION_REQUEST_SWAP.equals(intent.getAction())) {
return;
}
Uri uri = intent.getData(); Uri uri = intent.getData();
if (uri != null && !HttpDownloader.isSwapUrl(uri) && !BluetoothDownloader.isBluetoothUri(uri)) { if (uri != null && !HttpDownloader.isSwapUrl(uri) && !BluetoothDownloader.isBluetoothUri(uri)) {
String msg = getString(R.string.swap_toast_invalid_url, uri); String msg = getString(R.string.swap_toast_invalid_url, uri);
Toast.makeText(this, msg, Toast.LENGTH_LONG).show(); Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
return; return;
} }
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_SWAP_INTENT_HANDLED, true);
confirmSwapConfig = new NewRepoConfig(this, intent); confirmSwapConfig = new NewRepoConfig(this, intent);
} }
}
public void promptToSelectWifiNetwork() { public void promptToSelectWifiNetwork() {
// //

View File

@ -92,11 +92,10 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
private static final String ADD_REPO_INTENT_HANDLED = "addRepoIntentHandled"; private static final String ADD_REPO_INTENT_HANDLED = "addRepoIntentHandled";
private static final String ACTION_ADD_REPO = "org.fdroid.fdroid.MainActivity.ACTION_ADD_REPO"; private static final String ACTION_ADD_REPO = "org.fdroid.fdroid.MainActivity.ACTION_ADD_REPO";
public static final String ACTION_REQUEST_SWAP = "requestSwap";
private static final String STATE_SELECTED_MENU_ID = "selectedMenuId"; private static final String STATE_SELECTED_MENU_ID = "selectedMenuId";
private static final int REQUEST_SWAP = 3;
private RecyclerView pager; private RecyclerView pager;
private MainViewAdapter adapter; private MainViewAdapter adapter;
private BottomNavigationBar bottomNavigation; private BottomNavigationBar bottomNavigation;
@ -390,10 +389,7 @@ public class MainActivity extends AppCompatActivity implements BottomNavigationB
NewRepoConfig parser = new NewRepoConfig(this, intent); NewRepoConfig parser = new NewRepoConfig(this, intent);
if (parser.isValidRepo()) { if (parser.isValidRepo()) {
if (parser.isFromSwap()) { if (parser.isFromSwap()) {
Intent confirmIntent = new Intent(this, SwapWorkflowActivity.class); SwapWorkflowActivity.requestSwap(this, intent.getData());
confirmIntent.putExtra(SwapWorkflowActivity.EXTRA_CONFIRM, true);
confirmIntent.setData(intent.getData());
startActivityForResult(confirmIntent, REQUEST_SWAP);
} else { } else {
Intent clean = new Intent(ACTION_ADD_REPO, intent.getData(), this, ManageReposActivity.class); Intent clean = new Intent(ACTION_ADD_REPO, intent.getData(), this, ManageReposActivity.class);
if (intent.hasExtra(ManageReposActivity.EXTRA_FINISH_AFTER_ADDING_REPO)) { if (intent.hasExtra(ManageReposActivity.EXTRA_FINISH_AFTER_ADDING_REPO)) {