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

pull/14/head
Tim Su 16 years ago
parent 32f0b9910d
commit c6f899e67d

@ -92,8 +92,6 @@
<receiver android:name=".utilities.Notifications" /> <receiver android:name=".utilities.Notifications" />
<receiver android:name=".sync.SynchronizationService" />
<receiver android:name=".utilities.LocaleReceiver"> <receiver android:name=".utilities.LocaleReceiver">
<intent-filter> <intent-filter>
<action android:name="com.timsu.astrid.action.LOCALE_ALERT" /> <action android:name="com.timsu.astrid.action.LOCALE_ALERT" />
@ -120,6 +118,7 @@
<service android:name=".appwidget.AstridAppWidgetProvider$UpdateService"></service> <service android:name=".appwidget.AstridAppWidgetProvider$UpdateService"></service>
<service android:name=".sync.SynchronizationService" />
<!-- ======================== Providers ========================== --> <!-- ======================== Providers ========================== -->

@ -26,7 +26,9 @@ import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceActivity; import android.preference.PreferenceActivity;
import android.preference.Preference.OnPreferenceChangeListener;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
@ -48,17 +50,29 @@ import com.timsu.astrid.utilities.Preferences;
*/ */
public class SyncPreferences extends PreferenceActivity { public class SyncPreferences extends PreferenceActivity {
private boolean rtmSyncPreference; /** whether or not to synchronize with RTM */
private boolean oldRtmSyncPreference;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Resources r = getResources(); Resources r = getResources();
rtmSyncPreference = Preferences.shouldSyncRTM(this); oldRtmSyncPreference = Preferences.shouldSyncRTM(this);
addPreferencesFromResource(R.xml.sync_preferences); 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( getListView().addFooterView(getLayoutInflater().inflate(
R.layout.sync_footer, getListView(), false)); R.layout.sync_footer, getListView(), false));
@ -79,12 +93,13 @@ public class SyncPreferences extends PreferenceActivity {
int which) { int which) {
Synchronizer.clearUserData(SyncPreferences.this); Synchronizer.clearUserData(SyncPreferences.this);
// force a synchronization if sync preference is still set // force a synchronization if sync preference is still set
rtmSyncPreference = false; oldRtmSyncPreference = false;
} }
}, null); }, null);
} }
}); });
// set up labels
TextView lastSyncLabel = (TextView)findViewById(R.id.last_sync_label); TextView lastSyncLabel = (TextView)findViewById(R.id.last_sync_label);
SimpleDateFormat formatter = new SimpleDateFormat("MM/dd HH:mm"); SimpleDateFormat formatter = new SimpleDateFormat("MM/dd HH:mm");
String syncDate = r.getString(R.string.sync_date_never); 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) { public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK) { if(keyCode == KeyEvent.KEYCODE_BACK) {
boolean newRtmSyncPreference = Preferences.shouldSyncRTM(this); boolean newRtmSyncPreference = Preferences.shouldSyncRTM(this);
if(newRtmSyncPreference != rtmSyncPreference && newRtmSyncPreference) { if(newRtmSyncPreference != oldRtmSyncPreference && newRtmSyncPreference) {
setResult(Constants.RESULT_SYNCHRONIZE); setResult(Constants.RESULT_SYNCHRONIZE);
} }
finish(); finish();
return true; return true;
} }
return false; return false;
} }
} }

@ -67,7 +67,7 @@ public class TaskList extends Activity {
/** Bundle Key: variables of current activity */ /** Bundle Key: variables of current activity */
private static final String LAST_BUNDLE_TAG = "b"; 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"; public static final String VARIABLES_TAG = "v";
/** Minimum distance a fling must cover to trigger motion */ /** Minimum distance a fling must cover to trigger motion */

@ -4,9 +4,10 @@ import java.util.Date;
import android.app.AlarmManager; import android.app.AlarmManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver; import android.app.Service;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.IBinder;
import android.util.Log; import android.util.Log;
import com.timsu.astrid.utilities.Constants; import com.timsu.astrid.utilities.Constants;
@ -20,7 +21,7 @@ import com.timsu.astrid.utilities.Preferences;
* @author Tim Su * @author Tim Su
* *
*/ */
public class SynchronizationService extends BroadcastReceiver { public class SynchronizationService extends Service {
/** miniumum time before an auto-sync */ /** miniumum time before an auto-sync */
private static final long AUTO_SYNC_MIN_OFFSET = 5*60*1000L; 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! */ /** Receive the alarm - start the synchronize service! */
@Override @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)) if(intent.getAction().equals(SYNC_ACTION))
startSynchronization(context); startSynchronization(this);
} }
/** Start the actual synchronization */ /** Start the actual synchronization */
@ -139,6 +141,9 @@ public class SynchronizationService extends BroadcastReceiver {
return offset; return offset;
} }
@Override
public IBinder onBind(Intent intent) {
return null;
}
} }

@ -13,7 +13,7 @@ public class Constants {
/** Flurry API KEy */ /** Flurry API KEy */
public static final String FLURRY_KEY = "T3JAY9TV2JFMJR4YTG16"; 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; public static final long WIDGET_UPDATE_INTERVAL = 30 * 60 * 1000L;

@ -82,6 +82,9 @@ public class StartupReceiver extends BroadcastReceiver {
0, intent, PendingIntent.FLAG_CANCEL_CURRENT); 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
am.setInexactRepeating(AlarmManager.RTC, 0, am.setInexactRepeating(AlarmManager.RTC, 0,
Constants.WIDGET_UPDATE_INTERVAL, pendingIntent); Constants.WIDGET_UPDATE_INTERVAL, pendingIntent);
// start synchronization service
SynchronizationService.scheduleService(context);
} }
}).start(); }).start();
@ -90,9 +93,6 @@ public class StartupReceiver extends BroadcastReceiver {
// check for task killers // check for task killers
showTaskKillerHelp(context); showTaskKillerHelp(context);
// start synchronization service
SynchronizationService.scheduleService(context);
hasStartedUp = true; hasStartedUp = true;
} }

Loading…
Cancel
Save