Added a sync ongoing notification to the status bar instead of progress bars, fixed a crash

pull/14/head
Sam Bosley 13 years ago
parent 977078e73c
commit 794abd5896

@ -14,17 +14,22 @@ import org.apache.http.entity.mime.MultipartEntity;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import com.crittercism.app.Crittercism;
import com.timsu.astrid.R;
import com.todoroo.andlib.data.TodorooCursor;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.NotificationManager;
import com.todoroo.andlib.service.NotificationManager.AndroidNotificationManager;
import com.todoroo.andlib.sql.Query;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities;
@ -109,6 +114,10 @@ public class ActFmSyncThread {
private boolean isTimeForBackgroundSync = false;
private final NotificationManager notificationManager;
private int notificationId = -1;
public static interface SyncMessageCallback {
public void runOnSuccess();
public void runOnErrors(List<JSONArray> errors);
@ -165,6 +174,7 @@ public class ActFmSyncThread {
this.pendingCallbacks = Collections.synchronizedMap(new HashMap<ClientToServerMessage<?>, SyncMessageCallback>());
this.monitor = syncMonitor;
this.syncMigration = Preferences.getBoolean(AstridNewSyncMigrator.PREF_SYNC_MIGRATION, false);
this.notificationManager = new AndroidNotificationManager(ContextManager.getContext());
}
public synchronized void startSyncThread() {
@ -228,6 +238,10 @@ public class ActFmSyncThread {
synchronized(monitor) {
while ((pendingMessages.isEmpty() && !timeForBackgroundSync()) || !actFmPreferenceService.isLoggedIn() || !syncMigration) {
try {
if (pendingMessages.isEmpty() && notificationId >= 0) {
notificationManager.cancel(notificationId);
notificationId = -1;
}
monitor.wait();
AndroidUtilities.sleepDeep(500L); // Wait briefly for large database operations to finish (e.g. adding a task with several tags may trigger a message before all saves are done--fix this?)
@ -276,6 +290,8 @@ public class ActFmSyncThread {
continue;
}
setupNotification();
payload.put(getClientVersion());
JSONArray errors = null;
@ -445,6 +461,23 @@ public class ActFmSyncThread {
}
}
private void setupNotification() {
try {
NotificationCompat.Builder builder = new NotificationCompat.Builder(ContextManager.getContext());
builder.setContentText(ContextManager.getString(R.string.actfm_sync_ongoing))
.setContentTitle(ContextManager.getString(R.string.app_name))
.setOngoing(true)
.setSmallIcon(android.R.drawable.stat_notify_sync)
.setContentIntent(PendingIntent.getActivity(ContextManager.getContext().getApplicationContext(), 0, new Intent(), 0));
notificationManager.notify(0, builder.getNotification());
notificationId = 0;
} catch (Exception e) {
e.printStackTrace();
}
}
private boolean checkForToken() {
if(!actFmPreferenceService.isLoggedIn())
return false;

@ -374,5 +374,7 @@
<string name="actfm_tag_not_authorized_new_list">Create new list</string>
<string name="actfm_tag_not_authorized_leave_list">Leave list</string>
<string name="actfm_sync_ongoing">Sync ongoing...</string>
</resources>

@ -325,7 +325,7 @@ public class UpdateAdapter extends CursorAdapter {
else
commentPictureView.setUrl(pictureThumb);
if(imageCache.contains(pictureThumb) && updateBitmap == null) {
if (pictureThumb != null && imageCache.contains(pictureThumb) && updateBitmap == null) {
try {
commentPictureView.setDefaultImageBitmap(imageCache.get(pictureThumb));
} catch (IOException e) {

Loading…
Cancel
Save