move all current View tracking to SwapWorkflowActivity
This information is only ever used in SwapWorkflowActivity and nowhere else so if it needs to be stored, it could be stored via saveInstanceState().
This commit is contained in:
parent
39f23f6876
commit
035a89e5f6
@ -15,7 +15,6 @@ import android.net.Uri;
|
|||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.annotation.LayoutRes;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
@ -113,23 +112,6 @@ public class SwapService extends Service {
|
|||||||
return peerFinder;
|
return peerFinder;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int STEP_INTRO = 1;
|
|
||||||
|
|
||||||
@LayoutRes
|
|
||||||
private int currentView = STEP_INTRO;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Current screen that the swap process is up to.
|
|
||||||
*/
|
|
||||||
@LayoutRes
|
|
||||||
public int getCurrentView() {
|
|
||||||
return currentView;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCurrentView(@LayoutRes int currentView) {
|
|
||||||
this.currentView = currentView;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Set<String> getAppsToSwap() {
|
public Set<String> getAppsToSwap() {
|
||||||
return appsToSwap;
|
return appsToSwap;
|
||||||
|
@ -107,6 +107,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
private static final int REQUEST_BLUETOOTH_DISCOVERABLE = 3;
|
private static final int REQUEST_BLUETOOTH_DISCOVERABLE = 3;
|
||||||
private static final int REQUEST_BLUETOOTH_ENABLE_FOR_SEND = 4;
|
private static final int REQUEST_BLUETOOTH_ENABLE_FOR_SEND = 4;
|
||||||
private static final int REQUEST_WRITE_SETTINGS_PERMISSION = 5;
|
private static final int REQUEST_WRITE_SETTINGS_PERMISSION = 5;
|
||||||
|
private static final int STEP_INTRO = 1; // TODO remove this special case, only use layoutResIds
|
||||||
|
|
||||||
private Toolbar toolbar;
|
private Toolbar toolbar;
|
||||||
private SwapView currentView;
|
private SwapView currentView;
|
||||||
@ -115,6 +116,9 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
private LocalBroadcastManager localBroadcastManager;
|
private LocalBroadcastManager localBroadcastManager;
|
||||||
private WifiManager wifiManager;
|
private WifiManager wifiManager;
|
||||||
|
|
||||||
|
@LayoutRes
|
||||||
|
private int currentSwapViewLayoutRes = STEP_INTRO;
|
||||||
|
|
||||||
public static void requestSwap(Context context, String repo) {
|
public static void requestSwap(Context context, String repo) {
|
||||||
requestSwap(context, Uri.parse(repo));
|
requestSwap(context, Uri.parse(repo));
|
||||||
}
|
}
|
||||||
@ -158,7 +162,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (currentView.getLayoutResId() == SwapService.STEP_INTRO) {
|
if (currentView.getLayoutResId() == STEP_INTRO) {
|
||||||
SwapService.stop(this); // TODO SwapService should always be running, while swap is running
|
SwapService.stop(this); // TODO SwapService should always be running, while swap is running
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
@ -169,7 +173,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
int nextStep = -1;
|
int nextStep = -1;
|
||||||
switch (currentView.getLayoutResId()) {
|
switch (currentView.getLayoutResId()) {
|
||||||
case R.layout.swap_confirm_receive:
|
case R.layout.swap_confirm_receive:
|
||||||
nextStep = SwapService.STEP_INTRO;
|
nextStep = STEP_INTRO;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_connecting:
|
case R.layout.swap_connecting:
|
||||||
nextStep = R.layout.swap_select_apps;
|
nextStep = R.layout.swap_select_apps;
|
||||||
@ -178,7 +182,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
nextStep = R.layout.swap_join_wifi;
|
nextStep = R.layout.swap_join_wifi;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_join_wifi:
|
case R.layout.swap_join_wifi:
|
||||||
nextStep = SwapService.STEP_INTRO;
|
nextStep = STEP_INTRO;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_nfc:
|
case R.layout.swap_nfc:
|
||||||
nextStep = R.layout.swap_join_wifi;
|
nextStep = R.layout.swap_join_wifi;
|
||||||
@ -186,22 +190,22 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
case R.layout.swap_select_apps:
|
case R.layout.swap_select_apps:
|
||||||
// TODO: The STEP_JOIN_WIFI step isn't shown first, need to make it
|
// TODO: The STEP_JOIN_WIFI step isn't shown first, need to make it
|
||||||
// so that it is, or so that this doesn't go back there.
|
// so that it is, or so that this doesn't go back there.
|
||||||
nextStep = getState().isConnectingWithPeer() ? SwapService.STEP_INTRO : R.layout.swap_join_wifi;
|
nextStep = getState().isConnectingWithPeer() ? STEP_INTRO : R.layout.swap_join_wifi;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_send_fdroid:
|
case R.layout.swap_send_fdroid:
|
||||||
nextStep = SwapService.STEP_INTRO;
|
nextStep = STEP_INTRO;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_start_swap:
|
case R.layout.swap_start_swap:
|
||||||
nextStep = SwapService.STEP_INTRO;
|
nextStep = STEP_INTRO;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_success:
|
case R.layout.swap_success:
|
||||||
nextStep = SwapService.STEP_INTRO;
|
nextStep = STEP_INTRO;
|
||||||
break;
|
break;
|
||||||
case R.layout.swap_wifi_qr:
|
case R.layout.swap_wifi_qr:
|
||||||
nextStep = R.layout.swap_join_wifi;
|
nextStep = R.layout.swap_join_wifi;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
getService().setCurrentView(nextStep);
|
currentSwapViewLayoutRes = nextStep;
|
||||||
showRelevantView();
|
showRelevantView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -459,14 +463,14 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!forceReload && (container.getVisibility() == View.GONE || currentView != null && currentView.getLayoutResId() == service.getCurrentView())) {
|
if (!forceReload
|
||||||
|
&& (container.getVisibility() == View.GONE || currentView != null && currentView.getLayoutResId() == currentSwapViewLayoutRes)) {
|
||||||
// Already showing the correct step, so don't bother changing anything.
|
// Already showing the correct step, so don't bother changing anything.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int currentView = service.getCurrentView();
|
switch (currentSwapViewLayoutRes) {
|
||||||
switch (currentView) {
|
case STEP_INTRO:
|
||||||
case SwapService.STEP_INTRO:
|
|
||||||
showIntro();
|
showIntro();
|
||||||
return;
|
return;
|
||||||
case R.layout.swap_nfc:
|
case R.layout.swap_nfc:
|
||||||
@ -480,7 +484,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
inflateSwapView(R.layout.swap_start_swap);
|
inflateSwapView(R.layout.swap_start_swap);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
inflateSwapView(currentView);
|
inflateSwapView(currentSwapViewLayoutRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SwapService getState() {
|
public SwapService getState() {
|
||||||
@ -499,7 +503,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
if (service == null) {
|
if (service == null) {
|
||||||
throw new IllegalStateException("We are not in the STEP_INITIAL_LOADING state, but the service is not ready.");
|
throw new IllegalStateException("We are not in the STEP_INITIAL_LOADING state, but the service is not ready.");
|
||||||
}
|
}
|
||||||
service.setCurrentView(currentView.getLayoutResId());
|
currentSwapViewLayoutRes = currentView.getLayoutResId();
|
||||||
}
|
}
|
||||||
|
|
||||||
toolbar.setBackgroundColor(currentView.getToolbarColour());
|
toolbar.setBackgroundColor(currentView.getToolbarColour());
|
||||||
@ -631,7 +635,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
onLocalRepoPrepared();
|
onLocalRepoPrepared();
|
||||||
} else {
|
} else {
|
||||||
LocalRepoService.create(this, getService().getAppsToSwap());
|
LocalRepoService.create(this, getService().getAppsToSwap());
|
||||||
getService().setCurrentView(R.layout.swap_connecting);
|
currentSwapViewLayoutRes = R.layout.swap_connecting;
|
||||||
inflateSwapView(R.layout.swap_connecting);
|
inflateSwapView(R.layout.swap_connecting);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -693,7 +697,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
|
|||||||
*/
|
*/
|
||||||
public void swapWith(NewRepoConfig repoConfig) {
|
public void swapWith(NewRepoConfig repoConfig) {
|
||||||
Peer peer = repoConfig.toPeer();
|
Peer peer = repoConfig.toPeer();
|
||||||
if (getService().getCurrentView() == SwapService.STEP_INTRO || getService().getCurrentView() == R.layout.swap_confirm_receive) {
|
if (currentSwapViewLayoutRes == STEP_INTRO || currentSwapViewLayoutRes == R.layout.swap_confirm_receive) {
|
||||||
// This will force the "Select apps to swap" workflow to begin.
|
// This will force the "Select apps to swap" workflow to begin.
|
||||||
// TODO: Find a better way to decide whether we need to select the apps. Not sure if we
|
// TODO: Find a better way to decide whether we need to select the apps. Not sure if we
|
||||||
// can or cannot be in STEP_INTRO with a full blown repo ready to swap.
|
// can or cannot be in STEP_INTRO with a full blown repo ready to swap.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user