From c6f899e67dc1b47f62c5ad1f063f7b65700ffb7c Mon Sep 17 00:00:00 2001 From: Tim Su Date: Tue, 23 Feb 2010 00:01:49 -0800 Subject: [PATCH] Fixed auto-sync not working by turning SynchronizationService into a real service (wtf). Also added a hook so if auto-sync is set up but no user credentials are specified, login is requested --- AndroidManifest.xml | 25 +++++++++---------- .../astrid/activities/SyncPreferences.java | 24 ++++++++++++++---- src/com/timsu/astrid/activities/TaskList.java | 2 +- .../astrid/sync/SynchronizationService.java | 15 +++++++---- src/com/timsu/astrid/utilities/Constants.java | 2 +- .../astrid/utilities/StartupReceiver.java | 6 ++--- 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index abb99db68..bb238f15e 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -46,8 +46,8 @@ - + android:label="@string/taskEdit_label"> + @@ -92,8 +92,6 @@ - - @@ -107,19 +105,20 @@ - - - - - - + + + + + + - - + + + diff --git a/src/com/timsu/astrid/activities/SyncPreferences.java b/src/com/timsu/astrid/activities/SyncPreferences.java index d1ab669c4..db658109e 100644 --- a/src/com/timsu/astrid/activities/SyncPreferences.java +++ b/src/com/timsu/astrid/activities/SyncPreferences.java @@ -26,7 +26,9 @@ import android.app.Dialog; import android.content.DialogInterface; import android.content.res.Resources; import android.os.Bundle; +import android.preference.Preference; import android.preference.PreferenceActivity; +import android.preference.Preference.OnPreferenceChangeListener; import android.view.KeyEvent; import android.view.View; import android.widget.Button; @@ -48,17 +50,29 @@ import com.timsu.astrid.utilities.Preferences; */ public class SyncPreferences extends PreferenceActivity { - private boolean rtmSyncPreference; + /** whether or not to synchronize with RTM */ + private boolean oldRtmSyncPreference; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Resources r = getResources(); - rtmSyncPreference = Preferences.shouldSyncRTM(this); + oldRtmSyncPreference = Preferences.shouldSyncRTM(this); addPreferencesFromResource(R.xml.sync_preferences); + // set up preferences + findPreference(getString(R.string.p_sync_interval)).setOnPreferenceChangeListener(new OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + if(Preferences.getSyncRTMToken(SyncPreferences.this) == null) + setResult(Constants.RESULT_SYNCHRONIZE); + return true; + } + }); + + // set up footer getListView().addFooterView(getLayoutInflater().inflate( R.layout.sync_footer, getListView(), false)); @@ -79,12 +93,13 @@ public class SyncPreferences extends PreferenceActivity { int which) { Synchronizer.clearUserData(SyncPreferences.this); // force a synchronization if sync preference is still set - rtmSyncPreference = false; + oldRtmSyncPreference = false; } }, null); } }); + // set up labels TextView lastSyncLabel = (TextView)findViewById(R.id.last_sync_label); SimpleDateFormat formatter = new SimpleDateFormat("MM/dd HH:mm"); String syncDate = r.getString(R.string.sync_date_never); @@ -123,13 +138,12 @@ public class SyncPreferences extends PreferenceActivity { public boolean onKeyDown(int keyCode, KeyEvent event) { if(keyCode == KeyEvent.KEYCODE_BACK) { boolean newRtmSyncPreference = Preferences.shouldSyncRTM(this); - if(newRtmSyncPreference != rtmSyncPreference && newRtmSyncPreference) { + if(newRtmSyncPreference != oldRtmSyncPreference && newRtmSyncPreference) { setResult(Constants.RESULT_SYNCHRONIZE); } finish(); return true; } - return false; } } \ No newline at end of file diff --git a/src/com/timsu/astrid/activities/TaskList.java b/src/com/timsu/astrid/activities/TaskList.java index 792cfbfbf..42b56b21f 100644 --- a/src/com/timsu/astrid/activities/TaskList.java +++ b/src/com/timsu/astrid/activities/TaskList.java @@ -67,7 +67,7 @@ public class TaskList extends Activity { /** Bundle Key: variables of current activity */ private static final String LAST_BUNDLE_TAG = "b"; - /** Bundle Key: variables to pass to the subactivity */ + /** Bundle Key: variables to pass to the sub-activity */ public static final String VARIABLES_TAG = "v"; /** Minimum distance a fling must cover to trigger motion */ diff --git a/src/com/timsu/astrid/sync/SynchronizationService.java b/src/com/timsu/astrid/sync/SynchronizationService.java index d2345386b..ef8dd857b 100644 --- a/src/com/timsu/astrid/sync/SynchronizationService.java +++ b/src/com/timsu/astrid/sync/SynchronizationService.java @@ -4,9 +4,10 @@ import java.util.Date; import android.app.AlarmManager; import android.app.PendingIntent; -import android.content.BroadcastReceiver; +import android.app.Service; import android.content.Context; import android.content.Intent; +import android.os.IBinder; import android.util.Log; import com.timsu.astrid.utilities.Constants; @@ -20,7 +21,7 @@ import com.timsu.astrid.utilities.Preferences; * @author Tim Su * */ -public class SynchronizationService extends BroadcastReceiver { +public class SynchronizationService extends Service { /** miniumum time before an auto-sync */ private static final long AUTO_SYNC_MIN_OFFSET = 5*60*1000L; @@ -32,9 +33,10 @@ public class SynchronizationService extends BroadcastReceiver { /** Receive the alarm - start the synchronize service! */ @Override - public void onReceive(Context context, Intent intent) { + public void onStart(Intent intent, int startId) { + Log.i("astrid", "wassup"); if(intent.getAction().equals(SYNC_ACTION)) - startSynchronization(context); + startSynchronization(this); } /** Start the actual synchronization */ @@ -139,6 +141,9 @@ public class SynchronizationService extends BroadcastReceiver { return offset; } - + @Override + public IBinder onBind(Intent intent) { + return null; + } } diff --git a/src/com/timsu/astrid/utilities/Constants.java b/src/com/timsu/astrid/utilities/Constants.java index 4bbeef5e9..82eef6f6b 100644 --- a/src/com/timsu/astrid/utilities/Constants.java +++ b/src/com/timsu/astrid/utilities/Constants.java @@ -13,7 +13,7 @@ public class Constants { /** Flurry API KEy */ public static final String FLURRY_KEY = "T3JAY9TV2JFMJR4YTG16"; - public static final boolean DEBUG = false; + public static final boolean DEBUG = true; public static final long WIDGET_UPDATE_INTERVAL = 30 * 60 * 1000L; diff --git a/src/com/timsu/astrid/utilities/StartupReceiver.java b/src/com/timsu/astrid/utilities/StartupReceiver.java index 6916a7d2c..0df073e6f 100644 --- a/src/com/timsu/astrid/utilities/StartupReceiver.java +++ b/src/com/timsu/astrid/utilities/StartupReceiver.java @@ -82,6 +82,9 @@ public class StartupReceiver extends BroadcastReceiver { 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); am.setInexactRepeating(AlarmManager.RTC, 0, Constants.WIDGET_UPDATE_INTERVAL, pendingIntent); + + // start synchronization service + SynchronizationService.scheduleService(context); } }).start(); @@ -90,9 +93,6 @@ public class StartupReceiver extends BroadcastReceiver { // check for task killers showTaskKillerHelp(context); - // start synchronization service - SynchronizationService.scheduleService(context); - hasStartedUp = true; }