diff --git a/app/src/main/java/eu/faircode/email/AdapterFolder.java b/app/src/main/java/eu/faircode/email/AdapterFolder.java index 38036b3932..d2ee6eaa08 100644 --- a/app/src/main/java/eu/faircode/email/AdapterFolder.java +++ b/app/src/main/java/eu/faircode/email/AdapterFolder.java @@ -251,21 +251,24 @@ public class AdapterFolder extends RecyclerView.Adapter() { + new SimpleTask() { @Override - protected EntityAccount onLoad(Context context, Bundle args) { - long account = args.getLong("account"); - long folder = args.getLong("folder"); + protected Boolean onLoad(Context context, Bundle args) { + long aid = args.getLong("account"); + long fid = args.getLong("folder"); DB db = DB.getInstance(context); - EntityOperation.sync(db, folder); + EntityOperation.sync(db, fid); - return (account < 0 ? null : db.account().getAccount(account)); + if (aid < 0) // outbox + return "connected".equals(db.folder().getFolder(fid).state); + else + return "connected".equals(db.account().getAccount(aid).state); } @Override - protected void onLoaded(Bundle args, EntityAccount account) { - if (account != null && !"connected".equals(account.state)) + protected void onLoaded(Bundle args, Boolean connected) { + if (!connected) Snackbar.make(itemView, R.string.title_sync_queued, Snackbar.LENGTH_LONG).show(); } diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index 9b68245e1d..5ca616e9b6 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -47,7 +47,7 @@ public interface DaoFolder { " AND type = '" + EntityFolder.USER + "'") List getUserFolders(long account); - @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" + + @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + ", COUNT(message.id) AS messages" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" + @@ -66,7 +66,7 @@ public interface DaoFolder { " AND type <> '" + EntityFolder.USER + "'") LiveData> liveSystemFolders(long account); - @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" + + @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + ", COUNT(message.id) AS messages" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" + @@ -84,7 +84,7 @@ public interface DaoFolder { " AND (account.id = :account OR (:account IS NULL AND account.`primary`))") LiveData liveDrafts(Long account); - @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor" + + @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + ", COUNT(message.id) AS messages" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index fa5f43a325..0df2a9dc38 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -43,6 +43,7 @@ import android.widget.TextView; import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.floatingactionbutton.FloatingActionButton; +import com.google.android.material.snackbar.Snackbar; import java.util.ArrayList; import java.util.List; @@ -195,28 +196,51 @@ public class FragmentMessages extends FragmentEx { args.putLong("account", account); args.putLong("folder", folder); - new SimpleTask() { + new SimpleTask() { @Override - protected Void onLoad(Context context, Bundle args) { - long account = args.getLong("account"); - long folder = args.getLong("folder"); + protected Boolean onLoad(Context context, Bundle args) { + long aid = args.getLong("account"); + long fid = args.getLong("folder"); + + boolean connected = false; DB db = DB.getInstance(context); try { db.beginTransaction(); - if (account < 0) { - for (EntityFolder unified : db.folder().getUnifiedFolders()) - EntityOperation.sync(db, unified.id); - } else - EntityOperation.sync(db, folder); + List folders = new ArrayList<>(); + if (aid < 0) + folders.addAll(db.folder().getUnifiedFolders()); + else + folders.add(db.folder().getFolder(fid)); + + for (EntityFolder folder : folders) { + EntityOperation.sync(db, folder.id); + + if (folder.account == null) { // outbox + if ("connected".equals(folder.state)) + connected = true; + } else { + EntityAccount account = db.account().getAccount(folder.account); + if ("connected".equals(account.state)) + connected = true; + } + } db.setTransactionSuccessful(); } finally { db.endTransaction(); } - return null; + return connected; + } + + @Override + protected void onLoaded(Bundle args, Boolean connected) { + if (!connected) { + swipeRefresh.setRefreshing(false); + Snackbar.make(view, R.string.title_sync_queued, Snackbar.LENGTH_LONG).show(); + } } }.load(FragmentMessages.this, args); } @@ -1191,10 +1215,11 @@ public class FragmentMessages extends FragmentEx { boolean refreshing = false; for (TupleFolderEx folder : folders) - if (folder.sync_state != null) { + if (folder.sync_state != null && "connected".equals(folder.accountState)) { refreshing = true; break; } + swipeRefresh.setRefreshing(refreshing); } }); @@ -1217,7 +1242,10 @@ public class FragmentMessages extends FragmentEx { getActivity().invalidateOptionsMenu(); } - swipeRefresh.setRefreshing(folder != null && folder.sync_state != null); + swipeRefresh.setRefreshing( + folder != null && folder.sync_state != null && + "connected".equals(EntityFolder.OUTBOX.equals(folder.type) + ? folder.state : folder.accountState)); } }); break; diff --git a/app/src/main/java/eu/faircode/email/TupleFolderEx.java b/app/src/main/java/eu/faircode/email/TupleFolderEx.java index 98ee67d6d4..64e4c9e1a5 100644 --- a/app/src/main/java/eu/faircode/email/TupleFolderEx.java +++ b/app/src/main/java/eu/faircode/email/TupleFolderEx.java @@ -22,6 +22,7 @@ package eu.faircode.email; public class TupleFolderEx extends EntityFolder { public String accountName; public Integer accountColor; + public String accountState; public int messages; public int content; public int unseen; @@ -33,6 +34,7 @@ public class TupleFolderEx extends EntityFolder { return (super.equals(obj) && (this.accountName == null ? other.accountName == null : accountName.equals(other.accountName)) && (this.accountColor == null ? other.accountColor == null : this.accountColor.equals(other.accountColor)) && + (this.accountState == null ? other.accountState == null : accountState.equals(other.accountState)) && this.messages == other.messages && this.content == other.content && this.unseen == other.unseen); diff --git a/app/src/main/res/layout/fragment_folders.xml b/app/src/main/res/layout/fragment_folders.xml index 31f029d3de..38b0c08e7c 100644 --- a/app/src/main/res/layout/fragment_folders.xml +++ b/app/src/main/res/layout/fragment_folders.xml @@ -1,91 +1,97 @@ - - - - - - + android:layout_height="match_parent" + tools:context=".ActivityView"> - + - + - + - + - + + + + + + + + - +