|
@@ -68,9 +68,14 @@ import de.tudarmstadt.informatik.hostage.ui.activity.MainActivity;
|
|
*/
|
|
*/
|
|
public class SyncUtils {
|
|
public class SyncUtils {
|
|
public static final int SYNC_SUCCESSFUL = 0x0;
|
|
public static final int SYNC_SUCCESSFUL = 0x0;
|
|
|
|
+ private static final long SYNC_FREQUENCY_MINUTES = 5;
|
|
|
|
+ private static final long SYNC_FREQUENCY_UNIT = 60;
|
|
|
|
+ private static final long SYNC_FREQUENCY = SYNC_FREQUENCY_UNIT * SYNC_FREQUENCY_MINUTES;
|
|
|
|
|
|
public static final String CONTENT_AUTHORITY = "de.tudarmstadt.informatik.hostage.androidsync";
|
|
public static final String CONTENT_AUTHORITY = "de.tudarmstadt.informatik.hostage.androidsync";
|
|
private static final String PREF_SETUP_COMPLETE = "sync_setup_complete";
|
|
private static final String PREF_SETUP_COMPLETE = "sync_setup_complete";
|
|
|
|
+ private static final String PREF_SYNC_INTERNAL_FREQUENCY = "pref_sync_internal_frequency";
|
|
|
|
+ private static final String PREF_SYNC_FREQUENCY = "pref_sync_frequency";
|
|
|
|
|
|
private static final Map<String, Integer> protocolsTypeMap;
|
|
private static final Map<String, Integer> protocolsTypeMap;
|
|
|
|
|
|
@@ -97,8 +102,8 @@ public class SyncUtils {
|
|
*/
|
|
*/
|
|
public static void CreateSyncAccount(Context context) {
|
|
public static void CreateSyncAccount(Context context) {
|
|
boolean newAccount = false;
|
|
boolean newAccount = false;
|
|
- boolean setupComplete = PreferenceManager
|
|
+ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
|
- .getDefaultSharedPreferences(context).getBoolean(PREF_SETUP_COMPLETE, false);
|
|
+ boolean setupComplete = preferences.getBoolean(PREF_SETUP_COMPLETE, false);
|
|
|
|
|
|
|
|
|
|
Account account = HostageAccountService.GetAccount();
|
|
Account account = HostageAccountService.GetAccount();
|
|
@@ -113,7 +118,8 @@ public class SyncUtils {
|
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
|
|
long syncFrequency = pref.getInt("pref_sync_frequency", 5*60);
|
|
long syncFrequency = pref.getInt("pref_sync_frequency", 5*60);
|
|
ContentResolver.addPeriodicSync(
|
|
ContentResolver.addPeriodicSync(
|
|
- account, CONTENT_AUTHORITY, new Bundle(),syncFrequency);
|
|
+ account, CONTENT_AUTHORITY, new Bundle(), SYNC_FREQUENCY);
|
|
|
|
+ preferences.edit().putLong(PREF_SYNC_INTERNAL_FREQUENCY, SYNC_FREQUENCY).commit();
|
|
newAccount = true;
|
|
newAccount = true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -122,8 +128,19 @@ public class SyncUtils {
|
|
|
|
|
|
if (newAccount || !setupComplete) {
|
|
if (newAccount || !setupComplete) {
|
|
TriggerRefresh();
|
|
TriggerRefresh();
|
|
- PreferenceManager.getDefaultSharedPreferences(context).edit()
|
|
+ preferences.edit().putBoolean(PREF_SETUP_COMPLETE, true).commit();
|
|
- .putBoolean(PREF_SETUP_COMPLETE, true).commit();
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(setupComplete){
|
|
|
|
+ long syncFrequency = Long.valueOf(preferences.getString(PREF_SYNC_FREQUENCY, "" + SYNC_FREQUENCY_MINUTES)) * SYNC_FREQUENCY_UNIT;
|
|
|
|
+ long internalFrequency = preferences.getLong(PREF_SYNC_INTERNAL_FREQUENCY, SYNC_FREQUENCY);
|
|
|
|
+
|
|
|
|
+ if(syncFrequency != internalFrequency){
|
|
|
|
+ ContentResolver.removePeriodicSync(account, CONTENT_AUTHORITY, new Bundle());
|
|
|
|
+ ContentResolver.addPeriodicSync(account, CONTENT_AUTHORITY, new Bundle(), syncFrequency);
|
|
|
|
+
|
|
|
|
+ preferences.edit().putLong(PREF_SYNC_INTERNAL_FREQUENCY, syncFrequency).commit();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|