diff --git a/astrid/AndroidManifest.xml b/astrid/AndroidManifest.xml index cd68ff90f..642b9513e 100644 --- a/astrid/AndroidManifest.xml +++ b/astrid/AndroidManifest.xml @@ -48,6 +48,9 @@ + + + @@ -420,6 +423,12 @@ + + + + + + - - - diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java index 4a4c6322c..a7af07699 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncThread.java @@ -15,10 +15,13 @@ import org.json.JSONArray; import org.json.JSONObject; import android.app.PendingIntent; +import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.support.v4.app.NotificationCompat; import android.util.Log; @@ -488,4 +491,21 @@ public class ActFmSyncThread { if (ActFmInvoker.SYNC_DEBUG) Log.e(ERROR_TAG, message); } + + public static class NetworkStateChangedReceiver extends BroadcastReceiver { + private static long lastSyncFromNetworkChange = 0; + private static final String PREF_LAST_SYNC_FROM_NETWORK_CHANGE = "p_last_sync_from_net_change"; //$NON-NLS-1$ + @Override + public void onReceive(Context context, Intent intent) { + lastSyncFromNetworkChange = Preferences.getLong(PREF_LAST_SYNC_FROM_NETWORK_CHANGE, 0L); + if (DateUtilities.now() - lastSyncFromNetworkChange > DateUtilities.ONE_MINUTE * 10) { + NetworkInfo info = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO); + if (info != null && NetworkInfo.State.CONNECTED.equals(info.getState())) { + ActFmSyncThread syncThread = ActFmSyncThread.getInstance(); + syncThread.repopulateQueueFromOutstandingTables(); + Preferences.setLong(PREF_LAST_SYNC_FROM_NETWORK_CHANGE, DateUtilities.now()); + } + } + } + } }