Fixes for auto-synchronization. Yay for testing.

pull/14/head
Tim Su 17 years ago
parent 655c839550
commit e98cbb0fa0

@ -127,7 +127,8 @@ public class TaskList extends Activity {
// sync now if requested // sync now if requested
if(synchronizeNow) { if(synchronizeNow) {
Synchronizer.synchronize(this, true, null); synchronizeNow = false;
Synchronizer.synchronize(this, false, null);
} }
// if we have no filter tag, we're not on the last task // if we have no filter tag, we're not on the last task

@ -238,6 +238,9 @@ public class RTMSyncProvider extends SynchronizationProvider {
Date syncTime = new Date(System.currentTimeMillis() + 1000); Date syncTime = new Date(System.currentTimeMillis() + 1000);
Preferences.setSyncRTMLastSync(context, syncTime); Preferences.setSyncRTMLastSync(context, syncTime);
// on with the synchronization
Synchronizer.continueSynchronization(context);
} catch (Exception e) { } catch (Exception e) {
showError(context, e, null); showError(context, e, null);
} }

@ -27,7 +27,6 @@ import java.util.LinkedList;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Handler; import android.os.Handler;
import android.util.Log; import android.util.Log;
@ -497,15 +496,11 @@ public abstract class SynchronizationProvider {
progressDialog.hide(); progressDialog.hide();
Resources r = context.getResources(); Resources r = context.getResources();
if(Preferences.shouldSuppressSyncDialogs(context)) if(Preferences.shouldSuppressSyncDialogs(context)) {
return; return;
}
Dialog.OnClickListener finishListener = new Dialog.OnClickListener() { Dialog.OnClickListener finishListener = null;
public void onClick(DialogInterface dialog,
int which) {
Synchronizer.continueSynchronization(context);
}
};
// nothing updated // nothing updated
if(localCreatedTasks + localUpdatedTasks + localDeletedTasks + if(localCreatedTasks + localUpdatedTasks + localDeletedTasks +

@ -60,14 +60,17 @@ public class SynchronizationService extends Service {
// figure out last synchronize time // figure out last synchronize time
Date lastSyncDate = Preferences.getSyncLastSync(context); Date lastSyncDate = Preferences.getSyncLastSync(context);
Date lastAutoSyncDate = Preferences.getSyncLastSyncAttempt(context); Date lastAutoSyncDate = Preferences.getSyncLastSyncAttempt(context);
long latestSyncMillis = 0;
// if user never synchronized, give them a full offset period before bg sync
long latestSyncMillis = System.currentTimeMillis();
if(lastSyncDate != null) if(lastSyncDate != null)
latestSyncMillis = lastSyncDate.getTime(); latestSyncMillis = lastSyncDate.getTime();
if(lastAutoSyncDate != null && lastAutoSyncDate.getTime() > latestSyncMillis) if(lastAutoSyncDate != null && lastAutoSyncDate.getTime() > latestSyncMillis)
latestSyncMillis = lastAutoSyncDate.getTime(); latestSyncMillis = lastAutoSyncDate.getTime();
long offset = 0; long offset = 0;
if(latestSyncMillis != 0) if(latestSyncMillis != 0)
offset = Math.max(0, latestSyncMillis + interval - System.currentTimeMillis()); offset = Math.min(offset, Math.max(0, latestSyncMillis + interval -
System.currentTimeMillis()));
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
@Override @Override

@ -114,7 +114,7 @@ public class Synchronizer {
private static boolean autoSync; private static boolean autoSync;
/** Called to do the next step of synchronization. Run me on the UI thread! */ /** Called to do the next step of synchronization. */
static void continueSynchronization(Context context) { static void continueSynchronization(Context context) {
ServiceWrapper serviceWrapper = ServiceWrapper serviceWrapper =
ServiceWrapper.values()[currentStep]; ServiceWrapper.values()[currentStep];
@ -124,7 +124,7 @@ public class Synchronizer {
continueSynchronization(context); continueSynchronization(context);
break; break;
case RTM: case RTM:
if(Preferences.shouldSyncRTM(context)) { if(serviceWrapper.isActivated(context)) {
servicesSynced++; servicesSynced++;
serviceWrapper.service.synchronizeService(context, autoSync); serviceWrapper.service.synchronizeService(context, autoSync);
} else { } else {

Loading…
Cancel
Save