From 0e16eae5bc28348db55f6ab900e6624f15b8864b Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Thu, 28 May 2015 17:20:22 +1000 Subject: [PATCH] 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. --- .../org/fdroid/fdroid/localrepo/SwapState.java | 15 +++------------ .../fdroid/fdroid/views/swap/SelectAppsView.java | 5 ++++- .../fdroid/views/swap/SwapWorkflowActivity.java | 3 ++- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapState.java b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapState.java index 635676c8b..bea440d76 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapState.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapState.java @@ -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 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 appsToSwap; - private SwapState(@NonNull Context context, @SwapStep int step, @NonNull Set appsToSwap) { + private SwapState(@NonNull Context context, @NonNull Set 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 diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SelectAppsView.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SelectAppsView.java index fa8864d20..27ac9a012 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SelectAppsView.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SelectAppsView.java @@ -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 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 c954a1c03..5a185c672 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -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 apps) { - context = SwapWorkflowActivity.this.getApplicationContext(); + context = SwapWorkflowActivity.this; selectedApps = apps; progressDialog = new ProgressDialog(context); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);