From e84e9c15e2decb3916c13f223ff923e6c490225b Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Sun, 29 Jun 2014 08:11:53 +0930 Subject: [PATCH] Support "back" button navigation during swap process. Start service at end of swap. The back button will take you back through each step of the swap process now, and remove the swap Activity completely if you press back from the first screen. Also, when the WiFi QR code is shown, the local repo manager actually starts the relevant service. --- res/layout/swap_create.xml | 1 + .../fdroid/views/swap/SelectAppsFragment.java | 2 +- .../fdroid/views/swap/SwapActivity.java | 54 ++++---- .../fdroid/views/swap/WifiQrFragment.java | 119 ++++++++++++++++++ 4 files changed, 150 insertions(+), 26 deletions(-) diff --git a/res/layout/swap_create.xml b/res/layout/swap_create.xml index d7445db93..3fa5bb414 100644 --- a/res/layout/swap_create.xml +++ b/res/layout/swap_create.xml @@ -5,6 +5,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@android:color/white" xmlns:tools="http://schemas.android.com/tools" tools:context=".views.swap.SwapActivity"> { + private static final String TAG = "UpdateAsyncTask"; + private ProgressDialog progressDialog; + private String[] selectedApps; + private Uri sharingUri; + + public UpdateAsyncTask(Context c, String[] apps) { + selectedApps = apps; + progressDialog = new ProgressDialog(c); + progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); + progressDialog.setTitle(R.string.updating); + sharingUri = Utils.getSharingUri(c, FDroidApp.repo); + } + + @Override + protected void onPreExecute() { + progressDialog.show(); + } + + @Override + protected Void doInBackground(Void... params) { + try { + final LocalRepoManager lrm = LocalRepoManager.get(getActivity()); + publishProgress(getString(R.string.deleting_repo)); + lrm.deleteRepo(); + for (String app : selectedApps) { + publishProgress(String.format(getString(R.string.adding_apks_format), app)); + lrm.addApp(getActivity(), app); + } + lrm.writeIndexPage(sharingUri.toString()); + publishProgress(getString(R.string.writing_index_jar)); + lrm.writeIndexJar(); + publishProgress(getString(R.string.linking_apks)); + lrm.copyApksToRepo(); + publishProgress(getString(R.string.copying_icons)); + // run the icon copy without progress, its not a blocker + new AsyncTask() { + + @Override + protected Void doInBackground(Void... params) { + lrm.copyIconsToRepo(); + return null; + } + }.execute(); + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + @Override + protected void onProgressUpdate(String... progress) { + super.onProgressUpdate(progress); + progressDialog.setMessage(progress[0]); + } + + @Override + protected void onPostExecute(Void result) { + progressDialog.dismiss(); + Toast.makeText(getActivity(), R.string.updated_local_repo, Toast.LENGTH_SHORT).show(); + } + } + }