From 01c1d76a48d33fa65fcfe317d0134e3225a1c918 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 11 Apr 2019 17:47:58 +0200 Subject: [PATCH] Sync when account connected --- .../java/eu/faircode/email/AdapterFolder.java | 19 ++++++++++++++++++- .../eu/faircode/email/AdapterMessage.java | 2 +- .../eu/faircode/email/FragmentFolder.java | 2 +- .../eu/faircode/email/FragmentFolders.java | 16 +++++++++++++++- .../eu/faircode/email/FragmentMessages.java | 19 +++++++++++++++++-- app/src/main/res/values/strings.xml | 1 + 6 files changed, 53 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 1d685162cf..303025a253 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -432,11 +432,23 @@ public class AdapterFolder extends RecyclerView.Adapter folders = db.folder().getFoldersSynchronizingUnified(); - for (EntityFolder folder : folders) + for (EntityFolder folder : folders) { EntityOperation.sync(context, folder.id, true); + + if (folder.account != null) { + EntityAccount account = db.account().getAccount(folder.account); + if (account != null && !"connected".equals(account.state)) + now = false; + } + } } else { // Folder list SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); @@ -341,6 +350,11 @@ public class FragmentFolders extends FragmentBase { db.endTransaction(); } + if (!now) { + ServiceSynchronize.reset(context); + throw new IllegalArgumentException(context.getString(R.string.title_no_connection)); + } + return null; } diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index 15c01d8a9b..8362db0b2f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -630,6 +630,8 @@ public class FragmentMessages extends FragmentBase { if (!Helper.getNetworkState(context).isSuitable()) throw new IllegalArgumentException(context.getString(R.string.title_no_internet)); + boolean now = true; + DB db = DB.getInstance(context); try { db.beginTransaction(); @@ -642,14 +644,27 @@ public class FragmentMessages extends FragmentBase { if (folder != null) folders.add(folder); } - for (EntityFolder folder : folders) + + for (EntityFolder folder : folders) { EntityOperation.sync(context, folder.id, true); + if (folder.account != null) { + EntityAccount account = db.account().getAccount(folder.account); + if (account != null && !"connected".equals(account.state)) + now = false; + } + } + db.setTransactionSuccessful(); } finally { db.endTransaction(); } + if (!now) { + ServiceSynchronize.reset(context); + throw new IllegalArgumentException(context.getString(R.string.title_no_connection)); + } + return null; } @@ -1732,7 +1747,7 @@ public class FragmentMessages extends FragmentBase { boolean refreshing = false; for (TupleFolderEx folder : folders) - if (folder.sync_state != null) { + if (folder.sync_state != null && (folder.account == null || "connected".equals(folder.accountState))) { refreshing = true; break; } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1b6c4d29d8..545a28ef57 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -371,6 +371,7 @@ An outdated app sent a file path instead of a file stream Contact picker not available No or no suitable internet connection + Synchronization will be performed on next account connection Folder does not exist Messages moved across accounts will be downloaded again resulting in extra data usage Raw message saved