From bab97f32a4969b62ebab1052f67f39effc1e04f1 Mon Sep 17 00:00:00 2001 From: MasterWanna Date: Mon, 3 May 2021 23:49:00 +0800 Subject: [PATCH] SyncWorker called for update settings into running --- .../notes/importaccount/ImportAccountActivity.java | 13 +++++++++++++ .../persistence/migration/Migration_21_22.java | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/importaccount/ImportAccountActivity.java b/app/src/main/java/it/niedermann/owncloud/notes/importaccount/ImportAccountActivity.java index 25493110..918b23b9 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/importaccount/ImportAccountActivity.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/importaccount/ImportAccountActivity.java @@ -1,6 +1,8 @@ package it.niedermann.owncloud.notes.importaccount; +import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import android.util.Log; import android.view.View; @@ -8,6 +10,7 @@ import android.view.View; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.ViewModelProvider; +import androidx.preference.PreferenceManager; import com.nextcloud.android.sso.AccountImporter; import com.nextcloud.android.sso.exceptions.AccountImportCancelledException; @@ -24,6 +27,7 @@ import it.niedermann.owncloud.notes.exception.ExceptionDialogFragment; import it.niedermann.owncloud.notes.exception.ExceptionHandler; import it.niedermann.owncloud.notes.persistence.CapabilitiesClient; import it.niedermann.owncloud.notes.persistence.SSOClient; +import it.niedermann.owncloud.notes.persistence.SyncWorker; import it.niedermann.owncloud.notes.persistence.entity.Account; import it.niedermann.owncloud.notes.shared.model.Capabilities; import it.niedermann.owncloud.notes.shared.model.IResponseCallback; @@ -86,8 +90,17 @@ public class ImportAccountActivity extends AppCompatActivity { Log.i(TAG, "Loading capabilities for " + ssoAccount.name); final Capabilities capabilities = CapabilitiesClient.getCapabilities(getApplicationContext(), ssoAccount, null); importAccountViewModel.addAccount(ssoAccount.url, ssoAccount.userId, ssoAccount.name, capabilities, new IResponseCallback() { + + /** + * Update syncing when adding account + * https://github.com/stefan-niedermann/nextcloud-deck/issues/531 + * @param account the account to add + */ @Override public void onSuccess(Account account) { + Context context = getApplicationContext(); + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); + SyncWorker.update(context, !sharedPreferences.getString("backgroundSync", "on").equals("off")); runOnUiThread(() -> { Log.i(TAG, capabilities.toString()); BrandingUtil.saveBrandColors(ImportAccountActivity.this, capabilities.getColor(), capabilities.getTextColor()); diff --git a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java index 641b943b..18e9eba0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/persistence/migration/Migration_21_22.java @@ -8,6 +8,8 @@ import androidx.preference.PreferenceManager; import androidx.room.migration.Migration; import androidx.sqlite.db.SupportSQLiteDatabase; +import it.niedermann.owncloud.notes.persistence.SyncWorker; + /** * Enabling backgroundSync, set from {@link String} values to {@link Boolean} values * https://github.com/stefan-niedermann/nextcloud-notes/issues/1168 @@ -30,10 +32,14 @@ public class Migration_21_22 extends Migration { if (sharedPreferences.getString("backgroundSync", "on").equals("off")) { editor.remove("backgroundSync"); editor.putBoolean("backgroundSync", false); + SyncWorker.update(context, false); } else { editor.remove("backgroundSync"); editor.putBoolean("backgroundSync", true); + SyncWorker.update(context, true); } + } else { + SyncWorker.update(context, true); } editor.apply(); }