Fixed bug on preferences saving. Modified automatic synchronization

configuration. Closes #58 #59 #60 #61 #75
This commit is contained in:
Juan Miguel Boyero Corral 2013-12-14 22:31:48 +01:00
parent de9cd86e8b
commit b7893b18e1
4 changed files with 39 additions and 25 deletions

View File

@ -148,6 +148,16 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
*/ */
private String userPassword; private String userPassword;
/**
* Synchronization preferences changed flag
*/
private boolean syncPrefsChanged = false;
/**
* User password preference changed flag
*/
private boolean userPasswordPrefChanged = false;
/** /**
* Shows an error message. * Shows an error message.
* *
@ -366,6 +376,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
//If preferences have changed, logout //If preferences have changed, logout
logoutClean(key); logoutClean(key);
syncPrefsChanged = true;
} else if (Preferences.USERPASSWORDPREF.equals(key)) { } else if (Preferences.USERPASSWORDPREF.equals(key)) {
try { try {
userPassword = Crypto.encryptPassword((String) newValue); userPassword = Crypto.encryptPassword((String) newValue);
@ -374,6 +385,8 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
//If preferences have changed, logout //If preferences have changed, logout
Constants.setLogged(false); Constants.setLogged(false);
Log.i(TAG, "Forced logout due to " + key + " change in preferences"); Log.i(TAG, "Forced logout due to " + key + " change in preferences");
userPasswordPrefChanged = true;
syncPrefsChanged = true;
} catch (NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
error(TAG, ex.getMessage(), ex, true); error(TAG, ex.getMessage(), ex, true);
} }
@ -382,20 +395,14 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
//If preferences have changed, logout //If preferences have changed, logout
logoutClean(key); logoutClean(key);
syncPrefsChanged = true;
} else if(Preferences.SYNCENABLEPREF.equals(key)) { } else if(Preferences.SYNCENABLEPREF.equals(key)) {
boolean syncEnabled = (Boolean) newValue; boolean syncEnabled = (Boolean) newValue;
Preferences.setSyncEnabled(syncEnabled); Preferences.setSyncEnabled(syncEnabled);
if(syncEnabled) {
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.valueOf(Preferences.getSyncTime()), ctx);
} else {
SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, ctx);
}
syncEnablePref.setChecked(syncEnabled); syncEnablePref.setChecked(syncEnabled);
syncPrefsChanged = true;
} else if(Preferences.SYNCTIMEPREF.equals(key)) { } else if(Preferences.SYNCTIMEPREF.equals(key)) {
String syncTime = (String) newValue; String syncTime = (String) newValue;
boolean syncEnabled = Preferences.isSyncEnabled();
long lastSyncTime = Preferences.getLastSyncTime(); long lastSyncTime = Preferences.getLastSyncTime();
Preferences.setSyncTime(syncTime); Preferences.setSyncTime(syncTime);
@ -405,12 +412,6 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
int prefSyncTimeIndex = prefSyncTimeValues.indexOf(syncTime); int prefSyncTimeIndex = prefSyncTimeValues.indexOf(syncTime);
String prefSyncTimeEntry = prefSyncTimeEntries.get(prefSyncTimeIndex); String prefSyncTimeEntry = prefSyncTimeEntries.get(prefSyncTimeIndex);
SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, ctx);
if (!syncTime.equals("0") && syncEnabled) {
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.parseLong(syncTime), ctx);
}
if(lastSyncTime == 0) { if(lastSyncTime == 0) {
syncEnablePref.setSummary(getString(R.string.lastSyncTimeLabel) + ": " syncEnablePref.setSummary(getString(R.string.lastSyncTimeLabel) + ": "
+ getString(R.string.neverLabel)); + getString(R.string.neverLabel));
@ -425,6 +426,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
} }
syncTimePref.setSummary(prefSyncTimeEntry); syncTimePref.setSummary(prefSyncTimeEntry);
syncPrefsChanged = true;
} else if(Preferences.NOTIFLIMITPREF.equals(key)) { } else if(Preferences.NOTIFLIMITPREF.equals(key)) {
int notifLimit = (Integer) newValue; int notifLimit = (Integer) newValue;
Preferences.setNotifLimit(notifLimit); Preferences.setNotifLimit(notifLimit);
@ -476,15 +478,18 @@ public class PreferencesActivity extends PreferenceActivity implements OnPrefere
super.onPause(); super.onPause();
//Set final password //Set final password
Preferences.setUserPassword(userPassword); if(userPasswordPrefChanged) {
Preferences.setUserPassword(userPassword);
}
/* //Reconfigure automatic synchronization
* First run if(syncPrefsChanged) {
* If syncEnable checkbox is checked but automatic synchronization is disabled, enable it SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, ctx);
*/ if (!Preferences.getSyncTime().equals("0") && Preferences.isSyncEnabled()) {
if(syncEnablePref.isChecked() && !SyncUtils.isSyncAutomatically(this)) { SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY,
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, Long.valueOf(Preferences.getSyncTime()), this); Long.parseLong(Preferences.getSyncTime()), ctx);
} }
}
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@ -332,6 +332,13 @@ public class SWADMain extends MenuExpandableListActivity {
Preferences.upgradeCredentials(); Preferences.upgradeCredentials();
Preferences.setSyncTime(String.valueOf(Constants.DEFAULT_SYNC_TIME)); Preferences.setSyncTime(String.valueOf(Constants.DEFAULT_SYNC_TIME));
} else if(lastVersion < 57) {
//Reconfigure automatic synchronization
SyncUtils.removePeriodicSync(Constants.AUTHORITY, Bundle.EMPTY, this);
if(!Preferences.getSyncTime().equals("0") && Preferences.isSyncEnabled()) {
SyncUtils.addPeriodicSync(Constants.AUTHORITY, Bundle.EMPTY,
Long.valueOf(Preferences.getSyncTime()), this);
}
} }
Preferences.setLastVersion(currentVersion); Preferences.setLastVersion(currentVersion);

View File

@ -83,7 +83,7 @@ public class NotificationsMarkAllAsRead extends Module {
numMarkedNotifications = Integer.parseInt(soap.toString()); numMarkedNotifications = Integer.parseInt(soap.toString());
} }
Log.i(TAG, "Marked " + numMarkedNotifications + " notifications as read"); Log.i(TAG, "Marked " + numMarkedNotifications + " notifications as readed");
dbHelper.updateAllNotifications("seenRemote", Utils.parseBoolString(true)); dbHelper.updateAllNotifications("seenRemote", Utils.parseBoolString(true));
if(numMarkedNotifications != numMarkedNotificationsList) { if(numMarkedNotifications != numMarkedNotificationsList) {

View File

@ -442,7 +442,9 @@ public class NotificationsSyncAdapterService extends Service {
SecureConnection.initSecureConnection(); SecureConnection.initSecureConnection();
//If last login time > Global.RELOGIN_TIME, force login //If last login time > Global.RELOGIN_TIME, force login
if (System.currentTimeMillis() - Constants.getLastLoginTime() > Constants.RELOGIN_TIME) { if (Constants.isLogged() &&
((System.currentTimeMillis() - Constants.getLastLoginTime()) > Constants.RELOGIN_TIME)) {
Constants.setLogged(false); Constants.setLogged(false);
} }