change sync interval on change in code
This commit is contained in:
@@ -47,6 +47,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.KeychainApplication;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
@@ -422,8 +423,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
super.onResume();
|
||||
// this needs to be done in onResume since the user can change sync values from Android
|
||||
// settings and we need to reflect that change when the user navigates back
|
||||
AccountManager manager = AccountManager.get(getActivity());
|
||||
final Account account = manager.getAccountsByType(Constants.ACCOUNT_TYPE)[0];
|
||||
final Account account = KeychainApplication.createAccountIfNecessary(getActivity());
|
||||
// for keyserver sync
|
||||
initializeSyncCheckBox(
|
||||
(SwitchPreference) findPreference(Constants.Pref.SYNC_KEYSERVER),
|
||||
@@ -441,8 +441,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
private void initializeSyncCheckBox(final SwitchPreference syncCheckBox,
|
||||
final Account account,
|
||||
final String authority) {
|
||||
boolean syncEnabled = ContentResolver.getSyncAutomatically(account, authority)
|
||||
&& checkContactsPermission(authority);
|
||||
// account is null if it could not be created for some reason
|
||||
boolean syncEnabled =
|
||||
account != null
|
||||
&& ContentResolver.getSyncAutomatically(account, authority)
|
||||
&& checkContactsPermission(authority);
|
||||
syncCheckBox.setChecked(syncEnabled);
|
||||
setSummary(syncCheckBox, authority, syncEnabled);
|
||||
|
||||
@@ -464,6 +467,11 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (account == null) {
|
||||
// if account could not be created for some reason,
|
||||
// we can't have our sync
|
||||
return false;
|
||||
}
|
||||
// disable syncs
|
||||
ContentResolver.setSyncAutomatically(account, authority, false);
|
||||
// immediately delete any linked contacts
|
||||
|
||||
Reference in New Issue
Block a user