From 663dfd0ea019ddb297fe12f427b670543347971d Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 10 Nov 2018 17:58:09 +0000 Subject: [PATCH] Check server when needed only --- .../java/eu/faircode/email/FragmentAccount.java | 16 ++++++++++++---- .../java/eu/faircode/email/FragmentIdentity.java | 14 ++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index de29486dbd..74cb772a4b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -631,6 +631,7 @@ public class FragmentAccount extends FragmentEx { new SimpleTask() { @Override protected Void onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); String host = args.getString("host"); boolean starttls = args.getBoolean("starttls"); boolean insecure = args.getBoolean("insecure"); @@ -665,11 +666,19 @@ public class FragmentAccount extends FragmentEx { interval = "19"; if (synchronize && drafts == null) throw new Throwable(getContext().getString(R.string.title_no_drafts)); + if (Color.TRANSPARENT == color) color = null; + DB db = DB.getInstance(context); + EntityAccount account = db.account().getAccount(id); + + boolean check = (account == null || (synchronize && + (!host.equals(account.host) || Integer.parseInt(port) != account.port) || + !user.equals(account.user) || !password.equals(account.password))); + // Check IMAP server - if (synchronize) { + if (check) { Session isession = Session.getInstance(MessageHelper.getSessionProperties(auth_type, insecure), null); isession.setDebug(true); IMAPStore istore = null; @@ -696,11 +705,9 @@ public class FragmentAccount extends FragmentEx { if (TextUtils.isEmpty(name)) name = user; - DB db = DB.getInstance(getContext()); try { db.beginTransaction(); - EntityAccount account = db.account().getAccount(args.getLong("id")); boolean update = (account != null); if (account == null) account = new EntityAccount(); @@ -785,7 +792,8 @@ public class FragmentAccount extends FragmentEx { db.endTransaction(); } - ServiceSynchronize.reload(getContext(), "save account"); + if (check) + ServiceSynchronize.reload(getContext(), "save account"); return null; } diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 10752e6de8..7ef5c17ed5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -406,8 +406,15 @@ public class FragmentIdentity extends FragmentEx { if (Color.TRANSPARENT == color) color = null; + DB db = DB.getInstance(context); + EntityIdentity identity = db.identity().getIdentity(id); + + boolean check = (identity == null || (synchronize && + (!host.equals(identity.host) || Integer.parseInt(port) != identity.port) || + !user.equals(identity.user) || !password.equals(identity.password))); + // Check SMTP server - if (synchronize) { + if (check) { Properties props = MessageHelper.getSessionProperties(auth_type, insecure); Session isession = Session.getInstance(props, null); isession.setDebug(true); @@ -427,11 +434,9 @@ public class FragmentIdentity extends FragmentEx { } } - DB db = DB.getInstance(getContext()); try { db.beginTransaction(); - EntityIdentity identity = db.identity().getIdentity(id); boolean update = (identity != null); if (identity == null) identity = new EntityIdentity(); @@ -467,7 +472,8 @@ public class FragmentIdentity extends FragmentEx { db.endTransaction(); } - ServiceSynchronize.reload(getContext(), "save identity"); + if (check) + ServiceSynchronize.reload(getContext(), "save identity"); return null; }