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:
parent
1d263b2aee
commit
4fd914ac7a
@ -210,6 +210,7 @@
|
|||||||
- Percentage complete (int between 0-100)
|
- 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="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_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_connecting_to_repo">Connecting to\n%1$s</string>
|
||||||
<string name="status_checking_compatibility">Checking apps compatibility with your device…</string>
|
<string name="status_checking_compatibility">Checking apps compatibility with your device…</string>
|
||||||
|
@ -20,13 +20,15 @@ package org.fdroid.fdroid;
|
|||||||
|
|
||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
|
import android.app.Notification;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.ProgressDialog;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentProviderOperation;
|
import android.content.ContentProviderOperation;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.OperationApplicationException;
|
import android.content.OperationApplicationException;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -35,13 +37,12 @@ import android.net.NetworkInfo;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ResultReceiver;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -63,30 +64,26 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
|
|
||||||
private static final String TAG = "UpdateService";
|
private static final String TAG = "UpdateService";
|
||||||
|
|
||||||
public static final String RESULT_MESSAGE = "msg";
|
public static final String LOCAL_ACTION_STATUS = "status";
|
||||||
public static final String RESULT_EVENT = "event";
|
|
||||||
public static final String RESULT_REPO_ERRORS = "repoErrors";
|
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_WITH_CHANGES = 0;
|
||||||
public static final int STATUS_COMPLETE_AND_SAME = 1;
|
public static final int STATUS_COMPLETE_AND_SAME = 1;
|
||||||
public static final int STATUS_ERROR_GLOBAL = 2;
|
public static final int STATUS_ERROR_GLOBAL = 2;
|
||||||
public static final int STATUS_ERROR_LOCAL = 3;
|
public static final int STATUS_ERROR_LOCAL = 3;
|
||||||
public static final int STATUS_ERROR_LOCAL_SMALL = 4;
|
public static final int STATUS_ERROR_LOCAL_SMALL = 4;
|
||||||
public static final int STATUS_INFO = 5;
|
public static final int STATUS_INFO = 5;
|
||||||
|
|
||||||
// I don't like that I've had to dupliacte the statuses above with strings here, however
|
private static final int NOTIFY_ID_UPDATING = 0;
|
||||||
// one method of communication/notification is using ResultReceiver (int status codes)
|
private static final int NOTIFY_ID_UPDATES_AVAILABLE = 1;
|
||||||
// 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";
|
|
||||||
|
|
||||||
public static final String EXTRA_RECEIVER = "receiver";
|
private NotificationManager notificationManager;
|
||||||
public static final String EXTRA_ADDRESS = "address";
|
private NotificationCompat.Builder notificationBuilder;
|
||||||
|
|
||||||
private ResultReceiver receiver = null;
|
|
||||||
|
|
||||||
public UpdateService() {
|
public UpdateService() {
|
||||||
super("UpdateService");
|
super("UpdateService");
|
||||||
@ -106,130 +103,17 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
AppProvider.DataColumns.IGNORE_THISUPDATE
|
AppProvider.DataColumns.IGNORE_THISUPDATE
|
||||||
};
|
};
|
||||||
|
|
||||||
// For receiving results from the UpdateService when we've told it to
|
public static void updateNow(Context context) {
|
||||||
// update in response to a user request.
|
updateRepoNow(null, context);
|
||||||
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 UpdateReceiver updateNow(Context context) {
|
public static void updateRepoNow(String address, Context context) {
|
||||||
return updateRepoNow(null, context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static UpdateReceiver updateRepoNow(String address, Context context) {
|
|
||||||
Intent intent = new Intent(context, UpdateService.class);
|
Intent intent = new Intent(context, UpdateService.class);
|
||||||
UpdateReceiver receiver = new UpdateReceiver(new Handler());
|
intent.putExtra(EXTRA_MANUAL_UPDATE, true);
|
||||||
receiver.showDialog(context);
|
|
||||||
intent.putExtra(EXTRA_RECEIVER, receiver);
|
|
||||||
if (!TextUtils.isEmpty(address)) {
|
if (!TextUtils.isEmpty(address)) {
|
||||||
intent.putExtra(EXTRA_ADDRESS, address);
|
intent.putExtra(EXTRA_ADDRESS, address);
|
||||||
}
|
}
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
|
|
||||||
return receiver;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schedule (or cancel schedule for) this service, according to the
|
// 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) {
|
protected void sendStatus(int statusCode) {
|
||||||
sendStatus(statusCode, null);
|
sendStatus(statusCode, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendStatus(int statusCode, String message) {
|
protected void sendStatus(int statusCode, String message) {
|
||||||
if (receiver != null) {
|
Intent intent = new Intent(LOCAL_ACTION_STATUS);
|
||||||
Bundle resultData = new Bundle();
|
intent.putExtra(EXTRA_STATUS_CODE, statusCode);
|
||||||
if (!TextUtils.isEmpty(message)) {
|
if (!TextUtils.isEmpty(message))
|
||||||
resultData.putString(RESULT_MESSAGE, message);
|
intent.putExtra(EXTRA_MESSAGE, message);
|
||||||
}
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||||
receiver.send(statusCode, resultData);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void sendRepoErrorStatus(int statusCode, ArrayList<CharSequence> repoErrors) {
|
protected void sendRepoErrorStatus(int statusCode, ArrayList<CharSequence> repoErrors) {
|
||||||
if (receiver != null) {
|
Intent intent = new Intent(LOCAL_ACTION_STATUS);
|
||||||
Bundle resultData = new Bundle();
|
intent.putExtra(EXTRA_STATUS_CODE, statusCode);
|
||||||
resultData.putCharSequenceArrayList(RESULT_REPO_ERRORS, repoErrors);
|
intent.putExtra(EXTRA_REPO_ERRORS, repoErrors);
|
||||||
receiver.send(statusCode, resultData);
|
LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// For receiving results from the UpdateService when we've told it to
|
||||||
* We might be doing a scheduled run, or we might have been launched by the
|
// update in response to a user request.
|
||||||
* app in response to a user's request. If we have a receiver, it's the
|
private BroadcastReceiver localBroadcastReceiver = new BroadcastReceiver() {
|
||||||
* latter...
|
|
||||||
*/
|
@Override
|
||||||
private boolean isScheduledRun() {
|
public void onReceive(Context context, Intent intent) {
|
||||||
return receiver == null;
|
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.
|
* Check whether it is time to run the scheduled update.
|
||||||
@ -332,15 +289,14 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
@Override
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
|
|
||||||
receiver = intent.getParcelableExtra(EXTRA_RECEIVER);
|
|
||||||
String address = intent.getStringExtra(EXTRA_ADDRESS);
|
String address = intent.getStringExtra(EXTRA_ADDRESS);
|
||||||
|
boolean manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false);
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
|
||||||
try {
|
try {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||||
|
|
||||||
// See if it's time to actually do anything yet...
|
// See if it's time to actually do anything yet...
|
||||||
if (!isScheduledRun()) {
|
if (manualUpdate) {
|
||||||
Log.d(TAG, "Unscheduled (manually requested) update");
|
Log.d(TAG, "Unscheduled (manually requested) update");
|
||||||
} else if (!verifyIsTimeForScheduledRun()) {
|
} else if (!verifyIsTimeForScheduledRun()) {
|
||||||
return;
|
return;
|
||||||
@ -460,11 +416,6 @@ public class UpdateService extends IntentService implements ProgressListener {
|
|||||||
"Exception during update processing:\n"
|
"Exception during update processing:\n"
|
||||||
+ Log.getStackTraceString(e));
|
+ Log.getStackTraceString(e));
|
||||||
sendStatus(STATUS_ERROR_GLOBAL, e.getMessage());
|
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)
|
.setContentText(contentText)
|
||||||
.setStyle(createNotificationBigStyle(hasUpdates));
|
.setStyle(createNotificationBigStyle(hasUpdates));
|
||||||
|
|
||||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
notificationManager.notify(NOTIFY_ID_UPDATES_AVAILABLE, builder.build());
|
||||||
nm.notify(1, builder.build());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<String> getKnownAppIds(List<App> apps) {
|
private List<String> getKnownAppIds(List<App> apps) {
|
||||||
|
@ -19,10 +19,12 @@
|
|||||||
|
|
||||||
package org.fdroid.fdroid.views;
|
package org.fdroid.fdroid.views;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -40,6 +42,7 @@ import android.support.v4.app.LoaderManager;
|
|||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
import android.support.v4.content.Loader;
|
import android.support.v4.content.Loader;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
@ -64,7 +67,6 @@ import org.apache.http.impl.client.DefaultHttpClient;
|
|||||||
import org.fdroid.fdroid.FDroid;
|
import org.fdroid.fdroid.FDroid;
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.ProgressListener;
|
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.UpdateService;
|
import org.fdroid.fdroid.UpdateService;
|
||||||
import org.fdroid.fdroid.compat.ClipboardCompat;
|
import org.fdroid.fdroid.compat.ClipboardCompat;
|
||||||
@ -103,8 +105,6 @@ public class ManageReposActivity extends ActionBarActivity {
|
|||||||
IS_SWAP
|
IS_SWAP
|
||||||
}
|
}
|
||||||
|
|
||||||
private UpdateService.UpdateReceiver updateHandler = null;
|
|
||||||
|
|
||||||
private static boolean changed = false;
|
private static boolean changed = false;
|
||||||
|
|
||||||
private RepoListFragment listFragment;
|
private RepoListFragment listFragment;
|
||||||
@ -151,9 +151,10 @@ public class ManageReposActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.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 */
|
/* let's see if someone is trying to send us a new repo */
|
||||||
addRepoFromIntent(getIntent());
|
addRepoFromIntent(getIntent());
|
||||||
}
|
}
|
||||||
@ -161,9 +162,7 @@ public class ManageReposActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
if (updateHandler != null) {
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
||||||
updateHandler.hideDialog();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -209,7 +208,7 @@ public class ManageReposActivity extends ActionBarActivity {
|
|||||||
showAddRepo();
|
showAddRepo();
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_update_repo:
|
case R.id.action_update_repo:
|
||||||
updateRepos();
|
UpdateService.updateNow(this);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_find_local_repos:
|
case R.id.action_find_local_repos:
|
||||||
scanForRepos();
|
scanForRepos();
|
||||||
@ -218,25 +217,16 @@ public class ManageReposActivity extends ActionBarActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateRepos() {
|
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||||
updateHandler = UpdateService.updateNow(this).setListener(
|
@Override
|
||||||
new ProgressListener() {
|
public void onReceive(Context context, Intent intent) {
|
||||||
@Override
|
int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1);
|
||||||
public void onProgress(Event event) {
|
if (statusCode == UpdateService.STATUS_COMPLETE_AND_SAME
|
||||||
switch (event.type) {
|
|| statusCode == UpdateService.STATUS_COMPLETE_WITH_CHANGES)
|
||||||
case UpdateService.EVENT_COMPLETE_AND_SAME:
|
// No need to prompt to update any more, we just did it!
|
||||||
case UpdateService.EVENT_COMPLETE_WITH_CHANGES:
|
changed = false;
|
||||||
// No need to prompt to update any more, we just
|
}
|
||||||
// did it!
|
};
|
||||||
changed = false;
|
|
||||||
break;
|
|
||||||
case UpdateService.EVENT_FINISHED:
|
|
||||||
updateHandler = null;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void scanForRepos() {
|
private void scanForRepos() {
|
||||||
final RepoScanListAdapter adapter = new RepoScanListAdapter(this);
|
final RepoScanListAdapter adapter = new RepoScanListAdapter(this);
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package org.fdroid.fdroid.views;
|
package org.fdroid.fdroid.views;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.nfc.NdefMessage;
|
import android.nfc.NdefMessage;
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
@ -12,6 +15,7 @@ import android.os.Bundle;
|
|||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v4.app.NavUtils;
|
import android.support.v4.app.NavUtils;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -25,7 +29,6 @@ import android.widget.Toast;
|
|||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.NfcHelper;
|
import org.fdroid.fdroid.NfcHelper;
|
||||||
import org.fdroid.fdroid.NfcNotEnabledActivity;
|
import org.fdroid.fdroid.NfcNotEnabledActivity;
|
||||||
import org.fdroid.fdroid.ProgressListener;
|
|
||||||
import org.fdroid.fdroid.QrGenAsyncTask;
|
import org.fdroid.fdroid.QrGenAsyncTask;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.UpdateService;
|
import org.fdroid.fdroid.UpdateService;
|
||||||
@ -146,6 +149,9 @@ public class RepoDetailsActivity extends ActionBarActivity {
|
|||||||
repo = RepoProvider.Helper.findById(this, repoId);
|
repo = RepoProvider.Helper.findById(this, repoId);
|
||||||
updateRepoView();
|
updateRepoView();
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
|
||||||
|
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
|
||||||
|
|
||||||
// FDroid.java and AppDetails set different NFC actions, so reset here
|
// FDroid.java and AppDetails set different NFC actions, so reset here
|
||||||
setNfc();
|
setNfc();
|
||||||
processIntent(getIntent());
|
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
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
getMenuInflater().inflate(R.menu.repo_details_activity, 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);
|
values.put(RepoProvider.DataColumns.IN_USE, 1);
|
||||||
RepoProvider.Helper.update(this, repo, values);
|
RepoProvider.Helper.update(this, repo, values);
|
||||||
|
|
||||||
UpdateService.updateRepoNow(repo.address, this).setListener(new ProgressListener() {
|
UpdateService.updateRepoNow(repo.address, this);
|
||||||
@Override
|
|
||||||
public void onProgress(Event event) {
|
|
||||||
switch (event.type) {
|
|
||||||
case UpdateService.EVENT_COMPLETE_WITH_CHANGES:
|
|
||||||
updateRepoView();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void promptForDelete() {
|
private void promptForDelete() {
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
package org.fdroid.fdroid.views.swap;
|
package org.fdroid.fdroid.views.swap;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.http.AndroidHttpClient;
|
import android.net.http.AndroidHttpClient;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.content.LocalBroadcastManager;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.ActionBarActivity;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
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.client.methods.HttpPost;
|
||||||
import org.apache.http.message.BasicNameValuePair;
|
import org.apache.http.message.BasicNameValuePair;
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
import org.fdroid.fdroid.ProgressListener;
|
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.UpdateService;
|
import org.fdroid.fdroid.UpdateService;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
@ -33,7 +36,7 @@ import java.io.UnsupportedEncodingException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
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 TAG = "ConnectSwapActivity";
|
||||||
|
|
||||||
private static final String STATE_CONFIRM = "startSwap";
|
private static final String STATE_CONFIRM = "startSwap";
|
||||||
@ -79,6 +82,10 @@ public class ConnectSwapActivity extends ActionBarActivity implements ProgressLi
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
|
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver,
|
||||||
|
new IntentFilter(UpdateService.LOCAL_ACTION_STATUS));
|
||||||
|
|
||||||
// Only confirm the action, and then return a result...
|
// Only confirm the action, and then return a result...
|
||||||
newRepoConfig = new NewRepoConfig(this, getIntent());
|
newRepoConfig = new NewRepoConfig(this, getIntent());
|
||||||
if (newRepoConfig.isValidRepo()) {
|
if (newRepoConfig.isValidRepo()) {
|
||||||
@ -91,40 +98,48 @@ public class ConnectSwapActivity extends ActionBarActivity implements ProgressLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("fallthrough")
|
protected void onPause() {
|
||||||
public void onProgress(Event event) {
|
super.onPause();
|
||||||
// TODO: Show progress, but we can worry about that later.
|
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
||||||
// 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.
|
|
||||||
|
|
||||||
switch (event.type) {
|
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||||
case UpdateService.EVENT_COMPLETE_AND_SAME:
|
@Override
|
||||||
Log.i(TAG, "EVENT_COMPLETE_AND_SAME");
|
public void onReceive(Context context, Intent intent) {
|
||||||
case UpdateService.EVENT_COMPLETE_WITH_CHANGES:
|
// TODO: Show progress, but we can worry about that later.
|
||||||
Log.i(TAG, "EVENT_COMPLETE_WITH_CHANGES");
|
// Might be nice to have it nicely embedded in the UI, rather than as
|
||||||
Intent intent = new Intent(this, SwapAppListActivity.class);
|
// an additional dialog. E.g. White text on blue, letting the user
|
||||||
intent.putExtra(SwapAppListActivity.EXTRA_REPO_ID, repo.getId());
|
// know what we are up to.
|
||||||
startActivity(intent);
|
int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1);
|
||||||
finish();
|
|
||||||
|
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.
|
// 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());
|
intent.putExtra("category", newRepoConfig.getHost());
|
||||||
getActivity().setResult(Activity.RESULT_OK, intent);
|
getActivity().setResult(Activity.RESULT_OK, intent);
|
||||||
*/
|
*/
|
||||||
break;
|
break;
|
||||||
case UpdateService.EVENT_ERROR:
|
case UpdateService.STATUS_ERROR_GLOBAL:
|
||||||
// TODO: Show message on this screen (with a big "okay" button that goes back to F-Droid activity)
|
// TODO: Show message on this screen (with a big "okay" button that goes back to F-Droid activity)
|
||||||
// rather than finishing directly.
|
// rather than finishing directly.
|
||||||
finish();
|
finish();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
private void confirm() {
|
private void confirm() {
|
||||||
repo = ensureRepoExists();
|
repo = ensureRepoExists();
|
||||||
if (repo != null) {
|
if (repo != null) {
|
||||||
UpdateService.updateRepoNow(repo.address, this).setListener(this);
|
UpdateService.updateRepoNow(repo.address, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user