move requestSwap method to static Intent-sending method pattern

This commit is contained in:
Hans-Christoph Steiner 2018-08-06 10:13:20 +02:00
parent ddb85befa6
commit e4c9d1d522
2 changed files with 11 additions and 12 deletions

View File

@ -69,17 +69,6 @@ public class LocalHTTPD extends NanoHTTPD {
return newUri;
}
private void requestSwap(String repo) {
Utils.debugLog(TAG, "Received request to swap with " + repo);
Utils.debugLog(TAG, "Showing confirm screen to check whether that is okay with the user.");
Uri repoUri = Uri.parse(repo);
Intent intent = new Intent(context, SwapWorkflowActivity.class);
intent.setData(repoUri);
intent.putExtra(SwapWorkflowActivity.EXTRA_CONFIRM, true);
intent.putExtra(SwapWorkflowActivity.EXTRA_PREVENT_FURTHER_SWAP_REQUESTS, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
@Override
@ -111,7 +100,7 @@ public class LocalHTTPD extends NanoHTTPD {
return newFixedLengthResponse(Response.Status.BAD_REQUEST, MIME_PLAINTEXT,
"Requires 'repo' parameter to be posted.");
}
requestSwap(session.getParms().get("repo"));
SwapWorkflowActivity.requestSwap(context, session.getParms().get("repo"));
return newFixedLengthResponse(Response.Status.OK, MIME_PLAINTEXT, "Swap request received.");
}
return newFixedLengthResponse("");

View File

@ -123,6 +123,16 @@ public class SwapWorkflowActivity extends AppCompatActivity {
private LocalBroadcastManager localBroadcastManager;
private WifiManager wifiManager;
public static void requestSwap(Context context, String repo) {
Uri repoUri = Uri.parse(repo);
Intent intent = new Intent(context, SwapWorkflowActivity.class);
intent.setData(repoUri);
intent.putExtra(EXTRA_CONFIRM, true);
intent.putExtra(EXTRA_PREVENT_FURTHER_SWAP_REQUESTS, true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
@NonNull
private final ServiceConnection serviceConnection = new ServiceConnection() {
@Override