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

@ -46,8 +46,8 @@
<!-- Activity that creates or edits tasks -->
<activity android:name=".activities.TaskEdit"
android:icon="@drawable/icon_add"
android:label="@string/taskEdit_label">
<intent-filter>
android:label="@string/taskEdit_label">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
@ -92,8 +92,6 @@
<receiver android:name=".utilities.Notifications" />
<receiver android:name=".sync.SynchronizationService" />
<receiver android:name=".utilities.LocaleReceiver">
<intent-filter>
<action android:name="com.timsu.astrid.action.LOCALE_ALERT" />
@ -107,19 +105,20 @@
</intent-filter>
</receiver>
<receiver android:name=".appwidget.AstridAppWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_info" />
</receiver>
<receiver android:name=".appwidget.AstridAppWidgetProvider" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/widget_provider_info" />
</receiver>
<!-- ======================== Services ========================== -->
<service android:name=".appwidget.AstridAppWidgetProvider$UpdateService"></service>
<service android:name=".appwidget.AstridAppWidgetProvider$UpdateService"></service>
<service android:name=".sync.SynchronizationService" />
<!-- ======================== Providers ========================== -->

@ -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;
}
}

@ -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 */

@ -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;
}
}

@ -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;

@ -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;
}

Loading…
Cancel
Save