Sync frequency bug fixed

This commit is contained in:
Caesar2011
2019-02-06 09:47:04 +01:00
parent c6d9a288a6
commit 8f026f95d8
2 changed files with 10 additions and 9 deletions

View File

@@ -152,8 +152,10 @@ public class MainActivity extends AppCompatActivity
} }
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) { if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
registerSync(); registerSync(true);
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true); Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
} else {
registerSync(false);
} }
CustomNotificationManager.createNotificationChannel(this); CustomNotificationManager.createNotificationChannel(this);
/*getKVV().modules().list().recv(list -> { /*getKVV().modules().list().recv(list -> {
@@ -189,7 +191,7 @@ public class MainActivity extends AppCompatActivity
updateNavigation(); updateNavigation();
if (restoreResult == Login.RESTORE_STATUS_SUCCESS && !isLoggedInBeforePause) { if (restoreResult == Login.RESTORE_STATUS_SUCCESS && !isLoggedInBeforePause) {
changeFragment(getDefaultFragmentAfterLogin()); changeFragment(getDefaultFragmentAfterLogin());
registerSync(); registerSync(true);
} else if (restoreResult == Login.RESTORE_STATUS_INVALID_PASSWORD && isLoggedInBeforePause) { } else if (restoreResult == Login.RESTORE_STATUS_INVALID_PASSWORD && isLoggedInBeforePause) {
getKVV().account().logout(false); getKVV().account().logout(false);
changeFragment(getDefaultFragmentAfterLogout()); changeFragment(getDefaultFragmentAfterLogout());
@@ -388,15 +390,16 @@ public class MainActivity extends AppCompatActivity
changeFragment(newFragment); changeFragment(newFragment);
} }
private void registerSync() { private void registerSync(boolean onLogin) {
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE); Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
if (accountByType != null) { if (accountByType != null) {
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true); if (onLogin)
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
ContentResolver.addPeriodicSync( ContentResolver.addPeriodicSync(
accountByType, accountByType,
KVVContentProvider.PROVIDER_NAME, KVVContentProvider.PROVIDER_NAME,
Bundle.EMPTY, Bundle.EMPTY,
Long.parseLong(Preferences.getStringArray(this, R.array.pref_sync_frequency))); Long.parseLong(Preferences.getStringArray(this, R.array.pref_sync_frequency))*60*60);
} }
} }

View File

@@ -30,11 +30,9 @@ public class FUAuthenticator extends AbstractAccountAuthenticator {
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException { public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
final AccountManager am = AccountManager.get(mContext); final AccountManager am = AccountManager.get(mContext);
if (am.getAccountsByType(accountType).length > 0) { if (am.getAccountsByType(accountType).length > 0) {
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
intent.putExtra(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
intent.putExtra(AccountManager.KEY_ERROR_MESSAGE, "Already an account added!");
final Bundle bundle = new Bundle(); final Bundle bundle = new Bundle();
bundle.putParcelable(AccountManager.KEY_INTENT, intent); bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "Already an account added!");
return bundle; return bundle;
} }