convert repo update dialog to a notification

Since the repo updates are happening in an IntentService, they are already
running in a separate thread.  Ironically, the dialog was showing in spite
of that.  This removes the dialog entirely and instead puts up a
Notification with the same messages.  Ultimately, the "refresh" button
should go away, the repos should be updated whenever someone goes to
install an app, and all APK downloads should also show up in the same
Notification.

This removes UpdateReceiver entirely and replaces it with local broadcasts,
since that is a common pattern in FDroid and Android.  It also reduces the
amount of code here.

refs #103 https://gitlab.com/fdroid/fdroidclient/issues/103
This commit is contained in:
Hans-Christoph Steiner 2015-06-19 14:34:16 -04:00
parent 1d263b2aee
commit 4fd914ac7a
5 changed files with 203 additions and 235 deletions

View File

@ -210,6 +210,7 @@
- Percentage complete (int between 0-100)
-->
<string name="status_download">Downloading\n%2$s / %3$s (%4$d%%) from\n%1$s</string>
<string name="update_notification_title">Updating repositories</string>
<string name="status_processing_xml_percent">Processing %2$s / %3$s (%4$d%%) from %1$s</string>
<string name="status_connecting_to_repo">Connecting to\n%1$s</string>
<string name="status_checking_compatibility">Checking apps compatibility with your device…</string>

View File

@ -20,13 +20,15 @@ package org.fdroid.fdroid;
import android.app.AlarmManager;
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.BroadcastReceiver;
import android.content.ContentProviderOperation;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.OperationApplicationException;
import android.content.SharedPreferences;
import android.database.Cursor;
@ -35,13 +37,12 @@ import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.ResultReceiver;
import android.os.SystemClock;
import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.TaskStackBuilder;
import android.support.v4.content.LocalBroadcastManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Toast;
@ -63,30 +64,26 @@ public class UpdateService extends IntentService implements ProgressListener {
private static final String TAG = "UpdateService";
public static final String RESULT_MESSAGE = "msg";
public static final String RESULT_EVENT = "event";
public static final String RESULT_REPO_ERRORS = "repoErrors";
public static final String LOCAL_ACTION_STATUS = "status";
public static final String EXTRA_MESSAGE = "msg";
public static final String EXTRA_REPO_ERRORS = "repoErrors";
public static final String EXTRA_STATUS_CODE = "status";
public static final String EXTRA_ADDRESS = "address";
public static final String EXTRA_MANUAL_UPDATE = "manualUpdate";
public static final int STATUS_COMPLETE_WITH_CHANGES = 0;
public static final int STATUS_COMPLETE_AND_SAME = 1;
public static final int STATUS_ERROR_GLOBAL = 2;
public static final int STATUS_ERROR_LOCAL = 3;
public static final int STATUS_ERROR_LOCAL_SMALL = 4;
public static final int STATUS_INFO = 5;
public static final int STATUS_COMPLETE_AND_SAME = 1;
public static final int STATUS_ERROR_GLOBAL = 2;
public static final int STATUS_ERROR_LOCAL = 3;
public static final int STATUS_ERROR_LOCAL_SMALL = 4;
public static final int STATUS_INFO = 5;
// I don't like that I've had to dupliacte the statuses above with strings here, however
// one method of communication/notification is using ResultReceiver (int status codes)
// while the other uses progress events (string event types).
public static final String EVENT_COMPLETE_WITH_CHANGES = "repoUpdateComplete (changed)";
public static final String EVENT_COMPLETE_AND_SAME = "repoUpdateComplete (not changed)";
public static final String EVENT_FINISHED = "repoUpdateFinished";
public static final String EVENT_ERROR = "repoUpdateError";
public static final String EVENT_INFO = "repoUpdateInfo";
private static final int NOTIFY_ID_UPDATING = 0;
private static final int NOTIFY_ID_UPDATES_AVAILABLE = 1;
public static final String EXTRA_RECEIVER = "receiver";
public static final String EXTRA_ADDRESS = "address";
private ResultReceiver receiver = null;
private NotificationManager notificationManager;
private NotificationCompat.Builder notificationBuilder;
public UpdateService() {
super("UpdateService");
@ -106,130 +103,17 @@ public class UpdateService extends IntentService implements ProgressListener {
AppProvider.DataColumns.IGNORE_THISUPDATE
};
// For receiving results from the UpdateService when we've told it to
// update in response to a user request.
public static class UpdateReceiver extends ResultReceiver {
private Context context;
private ProgressDialog dialog;
private ProgressListener listener;
private String lastShownMessage = null;
public UpdateReceiver(Handler handler) {
super(handler);
}
public UpdateReceiver setDialog(ProgressDialog dialog) {
this.dialog = dialog;
return this;
}
public UpdateReceiver setListener(ProgressListener listener) {
this.listener = listener;
return this;
}
private void forwardEvent(String type) {
if (listener != null) {
listener.onProgress(new Event(type));
}
}
private void ensureDialog() {
if (dialog == null) {
String title = context.getString(R.string.process_wait_title);
String message = lastShownMessage == null ? context.getString(R.string.process_update_msg) : lastShownMessage;
dialog = ProgressDialog.show(context, title, message, true, true);
dialog.setIcon(android.R.drawable.ic_dialog_info);
dialog.setCanceledOnTouchOutside(false);
}
}
public UpdateReceiver showDialog(Context context) {
this.context = context;
ensureDialog();
dialog.show();
return this;
}
public void hideDialog() {
dialog.hide();
dialog.dismiss();
dialog = null;
}
@Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
final String message = resultData.getString(RESULT_MESSAGE);
boolean finished = false;
switch (resultCode) {
case STATUS_ERROR_GLOBAL:
forwardEvent(EVENT_ERROR);
Toast.makeText(context, context.getString(R.string.global_error_updating_repos) + " " + message, Toast.LENGTH_LONG).show();
finished = true;
break;
case STATUS_ERROR_LOCAL:
case STATUS_ERROR_LOCAL_SMALL:
StringBuilder msgB = new StringBuilder();
List<CharSequence> repoErrors = resultData.getCharSequenceArrayList(RESULT_REPO_ERRORS);
for (CharSequence error : repoErrors) {
if (msgB.length() > 0) msgB.append('\n');
msgB.append(error);
}
if (resultCode == STATUS_ERROR_LOCAL_SMALL) {
msgB.append('\n').append(context.getString(R.string.all_other_repos_fine));
}
Toast.makeText(context, msgB.toString(), Toast.LENGTH_LONG).show();
finished = true;
break;
case STATUS_COMPLETE_WITH_CHANGES:
forwardEvent(EVENT_COMPLETE_WITH_CHANGES);
finished = true;
break;
case STATUS_COMPLETE_AND_SAME:
forwardEvent(EVENT_COMPLETE_AND_SAME);
Toast.makeText(context, context.getString(R.string.repos_unchanged), Toast.LENGTH_LONG).show();
finished = true;
break;
case STATUS_INFO:
forwardEvent(EVENT_INFO);
if (dialog != null) {
lastShownMessage = message;
dialog.setMessage(message);
}
break;
}
if (finished) {
forwardEvent(EVENT_FINISHED);
if (dialog != null && dialog.isShowing()) {
try {
dialog.dismiss();
} catch (IllegalArgumentException e) {
// sometimes dialog.isShowing() doesn't work :(
// https://stackoverflow.com/questions/19538282/view-not-attached-to-window-manager-dialog-dismiss
e.printStackTrace();
}
}
}
}
public static void updateNow(Context context) {
updateRepoNow(null, context);
}
public static UpdateReceiver updateNow(Context context) {
return updateRepoNow(null, context);
}
public static UpdateReceiver updateRepoNow(String address, Context context) {
public static void updateRepoNow(String address, Context context) {
Intent intent = new Intent(context, UpdateService.class);
UpdateReceiver receiver = new UpdateReceiver(new Handler());
receiver.showDialog(context);
intent.putExtra(EXTRA_RECEIVER, receiver);
intent.putExtra(EXTRA_MANUAL_UPDATE, true);
if (!TextUtils.isEmpty(address)) {
intent.putExtra(EXTRA_ADDRESS, address);
}
context.startService(intent);
return receiver;
}
// Schedule (or cancel schedule for) this service, according to the
@ -259,36 +143,109 @@ public class UpdateService extends IntentService implements ProgressListener {
}
@Override
public void onCreate() {
super.onCreate();
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(localBroadcastReceiver, new IntentFilter(LOCAL_ACTION_STATUS));
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_refresh_white)
.setOngoing(true)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
.setContentTitle(getString(R.string.update_notification_title));
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
}
@Override
public void onDestroy() {
super.onDestroy();
notificationManager.cancel(NOTIFY_ID_UPDATING);
}
protected void sendStatus(int statusCode) {
sendStatus(statusCode, null);
}
protected void sendStatus(int statusCode, String message) {
if (receiver != null) {
Bundle resultData = new Bundle();
if (!TextUtils.isEmpty(message)) {
resultData.putString(RESULT_MESSAGE, message);
}
receiver.send(statusCode, resultData);
}
Intent intent = new Intent(LOCAL_ACTION_STATUS);
intent.putExtra(EXTRA_STATUS_CODE, statusCode);
if (!TextUtils.isEmpty(message))
intent.putExtra(EXTRA_MESSAGE, message);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
protected void sendRepoErrorStatus(int statusCode, ArrayList<CharSequence> repoErrors) {
if (receiver != null) {
Bundle resultData = new Bundle();
resultData.putCharSequenceArrayList(RESULT_REPO_ERRORS, repoErrors);
receiver.send(statusCode, resultData);
}
Intent intent = new Intent(LOCAL_ACTION_STATUS);
intent.putExtra(EXTRA_STATUS_CODE, statusCode);
intent.putExtra(EXTRA_REPO_ERRORS, repoErrors);
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
}
/**
* We might be doing a scheduled run, or we might have been launched by the
* app in response to a user's request. If we have a receiver, it's the
* latter...
*/
private boolean isScheduledRun() {
return receiver == null;
}
// For receiving results from the UpdateService when we've told it to
// update in response to a user request.
private BroadcastReceiver localBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action == null)
return;
if (!action.equals(LOCAL_ACTION_STATUS))
return;
final String message = intent.getStringExtra(EXTRA_MESSAGE);
int resultCode = intent.getIntExtra(EXTRA_STATUS_CODE, -1);
String text;
switch (resultCode) {
case STATUS_INFO:
notificationBuilder.setContentText(message)
.setProgress(0, 0, true)
.setCategory(NotificationCompat.CATEGORY_SERVICE);
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
break;
case STATUS_ERROR_GLOBAL:
text = context.getString(R.string.global_error_updating_repos) + " " + message;
notificationBuilder.setContentText(text)
.setCategory(Notification.CATEGORY_ERROR)
.setSmallIcon(android.R.drawable.ic_dialog_alert);
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
break;
case STATUS_ERROR_LOCAL:
case STATUS_ERROR_LOCAL_SMALL:
StringBuilder msgBuilder = new StringBuilder();
CharSequence[] repoErrors = intent.getCharSequenceArrayExtra(EXTRA_REPO_ERRORS);
for (CharSequence error : repoErrors) {
if (msgBuilder.length() > 0) msgBuilder.append('\n');
msgBuilder.append(error);
}
if (resultCode == STATUS_ERROR_LOCAL_SMALL) {
msgBuilder.append('\n').append(context.getString(R.string.all_other_repos_fine));
}
text = msgBuilder.toString();
notificationBuilder.setContentText(text)
.setCategory(Notification.CATEGORY_ERROR)
.setSmallIcon(android.R.drawable.ic_dialog_info);
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
break;
case STATUS_COMPLETE_WITH_CHANGES:
break;
case STATUS_COMPLETE_AND_SAME:
text = context.getString(R.string.repos_unchanged);
notificationBuilder.setContentText(text)
.setCategory(NotificationCompat.CATEGORY_SERVICE);
notificationManager.notify(NOTIFY_ID_UPDATING, notificationBuilder.build());
break;
}
}
};
/**
* Check whether it is time to run the scheduled update.
@ -332,15 +289,14 @@ public class UpdateService extends IntentService implements ProgressListener {
@Override
protected void onHandleIntent(Intent intent) {
receiver = intent.getParcelableExtra(EXTRA_RECEIVER);
String address = intent.getStringExtra(EXTRA_ADDRESS);
boolean manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false);
long startTime = System.currentTimeMillis();
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
// See if it's time to actually do anything yet...
if (!isScheduledRun()) {
if (manualUpdate) {
Log.d(TAG, "Unscheduled (manually requested) update");
} else if (!verifyIsTimeForScheduledRun()) {
return;
@ -460,11 +416,6 @@ public class UpdateService extends IntentService implements ProgressListener {
"Exception during update processing:\n"
+ Log.getStackTraceString(e));
sendStatus(STATUS_ERROR_GLOBAL, e.getMessage());
} finally {
Log.d(TAG, "Update took "
+ ((System.currentTimeMillis() - startTime) / 1000)
+ " seconds.");
receiver = null;
}
}
@ -557,8 +508,7 @@ public class UpdateService extends IntentService implements ProgressListener {
.setContentText(contentText)
.setStyle(createNotificationBigStyle(hasUpdates));
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
nm.notify(1, builder.build());
notificationManager.notify(NOTIFY_ID_UPDATES_AVAILABLE, builder.build());
}
private List<String> getKnownAppIds(List<App> apps) {

View File

@ -19,10 +19,12 @@
package org.fdroid.fdroid.views;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
import android.database.Cursor;
@ -40,6 +42,7 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.app.NavUtils;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.AlertDialog;
import android.text.Editable;
@ -64,7 +67,6 @@ import org.apache.http.impl.client.DefaultHttpClient;
import org.fdroid.fdroid.FDroid;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.Preferences;
import org.fdroid.fdroid.ProgressListener;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.compat.ClipboardCompat;
@ -103,8 +105,6 @@ public class ManageReposActivity extends ActionBarActivity {
IS_SWAP
}
private UpdateService.UpdateReceiver updateHandler = null;
private static boolean changed = false;
private RepoListFragment listFragment;
@ -151,9 +151,10 @@ public class ManageReposActivity extends ActionBarActivity {
@Override
protected void onResume() {
super.onResume();
if (updateHandler != null) {
updateHandler.showDialog(this);
}
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
/* let's see if someone is trying to send us a new repo */
addRepoFromIntent(getIntent());
}
@ -161,9 +162,7 @@ public class ManageReposActivity extends ActionBarActivity {
@Override
protected void onPause() {
super.onPause();
if (updateHandler != null) {
updateHandler.hideDialog();
}
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
}
@Override
@ -209,7 +208,7 @@ public class ManageReposActivity extends ActionBarActivity {
showAddRepo();
return true;
case R.id.action_update_repo:
updateRepos();
UpdateService.updateNow(this);
return true;
case R.id.action_find_local_repos:
scanForRepos();
@ -218,25 +217,16 @@ public class ManageReposActivity extends ActionBarActivity {
return super.onOptionsItemSelected(item);
}
private void updateRepos() {
updateHandler = UpdateService.updateNow(this).setListener(
new ProgressListener() {
@Override
public void onProgress(Event event) {
switch (event.type) {
case UpdateService.EVENT_COMPLETE_AND_SAME:
case UpdateService.EVENT_COMPLETE_WITH_CHANGES:
// No need to prompt to update any more, we just
// did it!
changed = false;
break;
case UpdateService.EVENT_FINISHED:
updateHandler = null;
break;
}
}
});
}
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1);
if (statusCode == UpdateService.STATUS_COMPLETE_AND_SAME
|| statusCode == UpdateService.STATUS_COMPLETE_WITH_CHANGES)
// No need to prompt to update any more, we just did it!
changed = false;
}
};
private void scanForRepos() {
final RepoScanListAdapter adapter = new RepoScanListAdapter(this);

View File

@ -1,9 +1,12 @@
package org.fdroid.fdroid.views;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.nfc.NdefMessage;
import android.nfc.NfcAdapter;
@ -12,6 +15,7 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.AlertDialog;
import android.support.v4.app.NavUtils;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBarActivity;
import android.text.TextUtils;
import android.util.Log;
@ -25,7 +29,6 @@ import android.widget.Toast;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.NfcHelper;
import org.fdroid.fdroid.NfcNotEnabledActivity;
import org.fdroid.fdroid.ProgressListener;
import org.fdroid.fdroid.QrGenAsyncTask;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
@ -146,6 +149,9 @@ public class RepoDetailsActivity extends ActionBarActivity {
repo = RepoProvider.Helper.findById(this, repoId);
updateRepoView();
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
// FDroid.java and AppDetails set different NFC actions, so reset here
setNfc();
processIntent(getIntent());
@ -175,6 +181,21 @@ public class RepoDetailsActivity extends ActionBarActivity {
}
}
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1);
if (statusCode == UpdateService.STATUS_COMPLETE_WITH_CHANGES)
updateRepoView();
}
};
@Override
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.repo_details_activity, menu);
@ -316,16 +337,7 @@ public class RepoDetailsActivity extends ActionBarActivity {
values.put(RepoProvider.DataColumns.IN_USE, 1);
RepoProvider.Helper.update(this, repo, values);
UpdateService.updateRepoNow(repo.address, this).setListener(new ProgressListener() {
@Override
public void onProgress(Event event) {
switch (event.type) {
case UpdateService.EVENT_COMPLETE_WITH_CHANGES:
updateRepoView();
break;
}
}
});
UpdateService.updateRepoNow(repo.address, this);
}
private void promptForDelete() {

View File

@ -1,13 +1,17 @@
package org.fdroid.fdroid.views.swap;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.net.http.AndroidHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
@ -20,7 +24,6 @@ import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.fdroid.fdroid.FDroidApp;
import org.fdroid.fdroid.ProgressListener;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.UpdateService;
import org.fdroid.fdroid.Utils;
@ -33,7 +36,7 @@ import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
public class ConnectSwapActivity extends ActionBarActivity implements ProgressListener {
public class ConnectSwapActivity extends ActionBarActivity {
private static final String TAG = "ConnectSwapActivity";
private static final String STATE_CONFIRM = "startSwap";
@ -79,6 +82,10 @@ public class ConnectSwapActivity extends ActionBarActivity implements ProgressLi
@Override
protected void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
// Only confirm the action, and then return a result...
newRepoConfig = new NewRepoConfig(this, getIntent());
if (newRepoConfig.isValidRepo()) {
@ -91,40 +98,48 @@ public class ConnectSwapActivity extends ActionBarActivity implements ProgressLi
}
@Override
@SuppressWarnings("fallthrough")
public void onProgress(Event event) {
// TODO: Show progress, but we can worry about that later.
// Might be nice to have it nicely embedded in the UI, rather than as
// an additional dialog. E.g. White text on blue, letting the user
// know what we are up to.
protected void onPause() {
super.onPause();
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
}
switch (event.type) {
case UpdateService.EVENT_COMPLETE_AND_SAME:
Log.i(TAG, "EVENT_COMPLETE_AND_SAME");
case UpdateService.EVENT_COMPLETE_WITH_CHANGES:
Log.i(TAG, "EVENT_COMPLETE_WITH_CHANGES");
Intent intent = new Intent(this, SwapAppListActivity.class);
intent.putExtra(SwapAppListActivity.EXTRA_REPO_ID, repo.getId());
startActivity(intent);
finish();
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: Show progress, but we can worry about that later.
// Might be nice to have it nicely embedded in the UI, rather than as
// an additional dialog. E.g. White text on blue, letting the user
// know what we are up to.
int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1);
switch (statusCode) {
case UpdateService.STATUS_COMPLETE_AND_SAME:
Log.i(TAG, "STATUS_COMPLETE_AND_SAME");
case UpdateService.STATUS_COMPLETE_WITH_CHANGES:
Log.i(TAG, "STATUS_COMPLETE_WITH_CHANGES");
Intent salIntent = new Intent(getBaseContext(), SwapAppListActivity.class);
salIntent.putExtra(SwapAppListActivity.EXTRA_REPO_ID, repo.getId());
startActivity(salIntent);
finish();
/*
// TODO: Load repo from database to get proper name. This is what the category we want to select will be called.
intent.putExtra("category", newRepoConfig.getHost());
getActivity().setResult(Activity.RESULT_OK, intent);
*/
break;
case UpdateService.EVENT_ERROR:
// TODO: Show message on this screen (with a big "okay" button that goes back to F-Droid activity)
// rather than finishing directly.
finish();
break;
break;
case UpdateService.STATUS_ERROR_GLOBAL:
// TODO: Show message on this screen (with a big "okay" button that goes back to F-Droid activity)
// rather than finishing directly.
finish();
break;
}
}
}
};
private void confirm() {
repo = ensureRepoExists();
if (repo != null) {
UpdateService.updateRepoNow(repo.address, this).setListener(this);
UpdateService.updateRepoNow(repo.address, this);
}
}