Minor fixes to swap after refactor.

List views need to have their header view set _before_ an adapter is
assigned to them.

Was incorrectly passing an application context instead of an Activity
context to the progress dialog for swap.

Extend ActionBarActivity rather than FragmentActivity.

Don't persist swap workflow state to disk, only store it in the
singleton.
This commit is contained in:
Peter Serwylo 2015-05-28 17:20:22 +10:00
parent ea61e8f2d3
commit 0e16eae5bc
3 changed files with 9 additions and 14 deletions

View File

@ -31,11 +31,8 @@ public class SwapState {
public static SwapState load(@NonNull Context context) {
if (instance == null) {
SharedPreferences preferences = context.getSharedPreferences(SHARED_PREFERENCES, Context.MODE_PRIVATE);
@SwapStep int step = preferences.getInt(KEY_STEP, STEP_INTRO);
Set<String> appsToSwap = deserializePackages(preferences.getString(KEY_APPS_TO_SWAP, ""));
instance = new SwapState(context, step, appsToSwap);
instance = new SwapState(context, appsToSwap);
}
return instance;
@ -47,9 +44,8 @@ public class SwapState {
@NonNull
private Set<String> appsToSwap;
private SwapState(@NonNull Context context, @SwapStep int step, @NonNull Set<String> appsToSwap) {
private SwapState(@NonNull Context context, @NonNull Set<String> appsToSwap) {
this.context = context.getApplicationContext();
this.step = step;
this.appsToSwap = appsToSwap;
}
@ -74,7 +70,7 @@ public class SwapState {
public static final int STEP_SHOW_NFC = 4;
public static final int STEP_WIFI_QR = 5;
private @SwapStep int step;
private @SwapStep int step = STEP_INTRO;
/**
* Current screen that the swap process is up to.
@ -87,7 +83,6 @@ public class SwapState {
public SwapState setStep(@SwapStep int step) {
this.step = step;
persistStep();
return this;
}
@ -95,10 +90,6 @@ public class SwapState {
return appsToSwap;
}
private void persistStep() {
persistence().edit().putInt(KEY_STEP, step).commit();
}
/**
* Ensure that we don't get put into an incorrect state, by forcing people to pass valid
* states to setStep. Ideally this would be done by requiring an enum or something to

View File

@ -87,8 +87,11 @@ public class SelectAppsView extends ListView implements
super.onFinishInflate();
adapter = new AppListAdapter(this, getContext(),
getContext().getContentResolver().query(InstalledAppProvider.getContentUri(), InstalledAppProvider.DataColumns.ALL, null, null, null));
setAdapter(adapter);
// Has to be _before_ "setAdapter()", as per the API docs.
addHeaderView(inflate(getContext(), R.layout.swap_create_header, null), null, false);
setAdapter(adapter);
setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
// either reconnect with an existing loader or start a new one

View File

@ -10,6 +10,7 @@ import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -264,7 +265,7 @@ public class SwapWorkflowActivity extends FragmentActivity {
private final Context context;
public UpdateAsyncTask(@NonNull Set<String> apps) {
context = SwapWorkflowActivity.this.getApplicationContext();
context = SwapWorkflowActivity.this;
selectedApps = apps;
progressDialog = new ProgressDialog(context);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);