Network state changed receiver

pull/14/head
Sam Bosley 12 years ago
parent b210048fd3
commit 1171dee9db

@ -48,6 +48,9 @@
<!-- Required for GCM - keeps the processor from sleeping when a message is received. --> <!-- Required for GCM - keeps the processor from sleeping when a message is received. -->
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<!-- Used to initiate sync when device comes back online -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- ============================================== Exported Permissions = --> <!-- ============================================== Exported Permissions = -->
@ -420,6 +423,12 @@
<service android:name=".GCMIntentService" /> <service android:name=".GCMIntentService" />
<receiver android:name="com.todoroo.astrid.actfm.sync.ActFmSyncThread.NetworkStateChangedReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
</receiver>
<!-- gtasks --> <!-- gtasks -->
<activity android:name="com.todoroo.astrid.gtasks.GtasksListFragment" <activity android:name="com.todoroo.astrid.gtasks.GtasksListFragment"
android:windowSoftInputMode="stateHidden|adjustResize" android:windowSoftInputMode="stateHidden|adjustResize"
@ -649,9 +658,7 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<!-- Task Rabbit --> <activity android:name="com.todoroo.astrid.welcome.tutorial.WelcomeWalkthrough"
<activity android:name="com.todoroo.astrid.taskrabbit.TaskRabbitMapActivity"></activity>
<activity android:name="com.todoroo.astrid.taskrabbit.TaskRabbitActivity"></activity><activity android:name="com.todoroo.astrid.welcome.tutorial.WelcomeWalkthrough"
android:windowSoftInputMode="stateHidden" android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait"></activity> android:screenOrientation="portrait"></activity>

@ -15,10 +15,13 @@ import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
@ -488,4 +491,21 @@ public class ActFmSyncThread {
if (ActFmInvoker.SYNC_DEBUG) if (ActFmInvoker.SYNC_DEBUG)
Log.e(ERROR_TAG, message); 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());
}
}
}
}
} }

Loading…
Cancel
Save