From 4fd0e02d1040895979286c569f258ba9f47188fd Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 13 Aug 2021 15:09:14 +0200 Subject: [PATCH] Reload on OAuth update --- .../main/java/eu/faircode/email/FragmentGmail.java | 14 ++++++++++---- .../main/java/eu/faircode/email/FragmentOAuth.java | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentGmail.java b/app/src/main/java/eu/faircode/email/FragmentGmail.java index 3ca28145aa..4841174497 100644 --- a/app/src/main/java/eu/faircode/email/FragmentGmail.java +++ b/app/src/main/java/eu/faircode/email/FragmentGmail.java @@ -445,11 +445,11 @@ public class FragmentGmail extends FragmentBase { max_size = iservice.getMaxSize(); } + EntityAccount update = null; DB db = DB.getInstance(context); try { db.beginTransaction(); - EntityAccount update = null; if (args.getBoolean("update")) update = db.account().getAccount(user, AUTH_TYPE_GMAIL); if (update == null) { @@ -521,7 +521,7 @@ public class FragmentGmail extends FragmentBase { identity.id = db.identity().insertIdentity(identity); EntityLog.log(context, "Gmail identity=" + identity.name + " email=" + identity.email); } else { - args.putLong("account", -1); + args.putLong("account", update.id); EntityLog.log(context, "Gmail update account=" + update.name); db.account().setAccountPassword(update.id, password); db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type); @@ -532,14 +532,20 @@ public class FragmentGmail extends FragmentBase { db.endTransaction(); } - ServiceSynchronize.eval(context, "Gmail"); + if (update == null) + ServiceSynchronize.eval(context, "Gmail"); + else { + args.putBoolean("updated", true); + ServiceSynchronize.reload(context, update.id, true, "Gmail"); + } return null; } @Override protected void onExecuted(Bundle args, Void data) { - if (args.getLong("account") < 0) { + boolean updated = args.getBoolean("updated"); + if (updated) { finish(); ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show(); } else { diff --git a/app/src/main/java/eu/faircode/email/FragmentOAuth.java b/app/src/main/java/eu/faircode/email/FragmentOAuth.java index cfd37447d7..3fd9e6a45d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOAuth.java +++ b/app/src/main/java/eu/faircode/email/FragmentOAuth.java @@ -670,11 +670,11 @@ public class FragmentOAuth extends FragmentBase { Log.i("OAuth passed provider=" + provider.id); + EntityAccount update = null; DB db = DB.getInstance(context); try { db.beginTransaction(); - EntityAccount update = null; if (args.getBoolean("update")) update = db.account().getAccount(username, AUTH_TYPE_OAUTH); if (update == null) { @@ -755,7 +755,7 @@ public class FragmentOAuth extends FragmentBase { EntityLog.log(context, "OAuth identity=" + ident.name + " email=" + ident.email); } } else { - args.putLong("account", -1); + args.putLong("account", update.id); EntityLog.log(context, "OAuth update account=" + update.name); db.account().setAccountPassword(update.id, state); db.identity().setIdentityPassword(update.id, update.user, state, update.auth_type); @@ -766,7 +766,12 @@ public class FragmentOAuth extends FragmentBase { db.endTransaction(); } - ServiceSynchronize.eval(context, "OAuth"); + if (update == null) + ServiceSynchronize.eval(context, "OAuth"); + else { + args.putBoolean("updated", true); + ServiceSynchronize.reload(context, update.id, true, "OAuth"); + } return null; } @@ -775,7 +780,8 @@ public class FragmentOAuth extends FragmentBase { protected void onExecuted(Bundle args, Void data) { pbOAuth.setVisibility(View.GONE); - if (args.getLong("account") < 0) { + boolean updated = args.getBoolean("updated"); + if (updated) { finish(); ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show(); } else {