Reset pull down to refresh on no connectivity

This commit is contained in:
M66B
2018-12-06 09:09:30 +01:00
parent 9576f34b3c
commit 0ee61448a8
5 changed files with 138 additions and 99 deletions

View File

@@ -251,21 +251,24 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
args.putLong("account", folder.account == null ? -1 : folder.account);
args.putLong("folder", folder.id);
new SimpleTask<EntityAccount>() {
new SimpleTask<Boolean>() {
@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();
}

View File

@@ -47,7 +47,7 @@ public interface DaoFolder {
" AND type = '" + EntityFolder.USER + "'")
List<EntityFolder> 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<List<EntityFolder>> 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<EntityFolder> 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" +

View File

@@ -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<Void>() {
new SimpleTask<Boolean>() {
@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<EntityFolder> 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;

View File

@@ -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);