Fixed folder states

pull/152/head
M66B 7 years ago
parent e970e54b6a
commit 794e05df64

@ -238,8 +238,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
PopupMenu popupMenu = new PopupMenu(context, itemView); PopupMenu popupMenu = new PopupMenu(context, itemView);
popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now) popupMenu.getMenu().add(Menu.NONE, action_synchronize_now, 1, R.string.title_synchronize_now);
.setEnabled(folder.account != null || "connected".equals(folder.state) /* outbox */);
if (folder.account != null) if (folder.account != null)
popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local); popupMenu.getMenu().add(Menu.NONE, action_delete_local, 2, R.string.title_delete_local);
@ -303,8 +302,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
boolean now; boolean now;
if (aid < 0) { if (aid < 0) {
// Outbox // Outbox
now = internet; if (internet) {
now = true;
EntityOperation.sync(context, db, fid); EntityOperation.sync(context, db, fid);
} else
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
} else { } else {
EntityAccount account = db.account().getAccount(aid); EntityAccount account = db.account().getAccount(aid);
if (account.ondemand) { if (account.ondemand) {

@ -50,7 +50,9 @@ public interface DaoFolder {
" AND (:search OR (account.synchronize AND account.browse))") " AND (:search OR (account.synchronize AND account.browse))")
EntityFolder getBrowsableFolder(long folder, boolean search); EntityFolder getBrowsableFolder(long folder, boolean search);
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + @Query("SELECT folder.*" +
", account.name AS accountName, account.color AS accountColor" +
", account.state AS accountState, account.ondemand AS accountOnDemand" +
", COUNT(message.id) AS messages" + ", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", 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" + ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
@ -64,7 +66,9 @@ public interface DaoFolder {
" GROUP BY folder.id") " GROUP BY folder.id")
LiveData<List<TupleFolderEx>> liveFolders(Long account); LiveData<List<TupleFolderEx>> liveFolders(Long account);
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + @Query("SELECT folder.*" +
", account.name AS accountName, account.color AS accountColor" +
", account.state AS accountState, account.ondemand AS accountOnDemand" +
", COUNT(message.id) AS messages" + ", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", 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" + ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
@ -81,7 +85,9 @@ public interface DaoFolder {
" WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'") " WHERE `primary` AND type = '" + EntityFolder.DRAFTS + "'")
LiveData<EntityFolder> livePrimaryDrafts(); LiveData<EntityFolder> livePrimaryDrafts();
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + @Query("SELECT folder.*" +
", account.name AS accountName, account.color AS accountColor" +
", account.state AS accountState, account.ondemand AS accountOnDemand" +
", COUNT(message.id) AS messages" + ", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", 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" + ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +

@ -516,8 +516,11 @@ public class FragmentMessages extends FragmentBase {
for (EntityFolder folder : folders) for (EntityFolder folder : folders)
if (folder.account == null) { if (folder.account == null) {
// Outbox // Outbox
now = internet; if (internet) {
now = true;
EntityOperation.sync(context, db, folder.id); EntityOperation.sync(context, db, folder.id);
} else
nointernet = true;
} else { } else {
EntityAccount account = db.account().getAccount(folder.account); EntityAccount account = db.account().getAccount(folder.account);
if (account.ondemand) { if (account.ondemand) {
@ -1555,7 +1558,7 @@ public class FragmentMessages extends FragmentBase {
boolean refreshing = false; boolean refreshing = false;
for (TupleFolderEx folder : folders) for (TupleFolderEx folder : folders)
if (folder.sync_state != null && "connected".equals(folder.accountState)) { if (folder.isSynchronizing()) {
refreshing = true; refreshing = true;
break; break;
} }
@ -1585,10 +1588,7 @@ public class FragmentMessages extends FragmentBase {
} }
} }
swipeRefresh.setRefreshing( swipeRefresh.setRefreshing(folder != null && folder.isSynchronizing());
folder != null && folder.sync_state != null &&
"connected".equals(EntityFolder.OUTBOX.equals(folder.type)
? folder.state : folder.accountState));
} }
}); });
break; break;

@ -185,6 +185,7 @@ public class ServiceSend extends LifecycleService {
Log.e(outbox.name, ex); Log.e(outbox.name, ex);
db.folder().setFolderError(outbox.id, Helper.formatThrowable(ex, true)); db.folder().setFolderError(outbox.id, Helper.formatThrowable(ex, true));
} finally { } finally {
db.folder().setFolderState(outbox.id, null);
db.folder().setFolderSyncState(outbox.id, null); db.folder().setFolderSyncState(outbox.id, null);
} }
} finally { } finally {

@ -306,6 +306,9 @@ public class ServiceUI extends IntentService {
} }
public static void sync(Context context, long folder) { public static void sync(Context context, long folder) {
DB db = DB.getInstance(context);
db.folder().setFolderSyncState(folder, "requested");
context.startService( context.startService(
new Intent(context, ServiceUI.class) new Intent(context, ServiceUI.class)
.setAction("synchronize:" + folder)); .setAction("synchronize:" + folder));

@ -25,10 +25,17 @@ public class TupleFolderEx extends EntityFolder {
public String accountName; public String accountName;
public Integer accountColor; public Integer accountColor;
public String accountState; public String accountState;
public Boolean accountOnDemand;
public int messages; public int messages;
public int content; public int content;
public int unseen; public int unseen;
boolean isSynchronizing() {
return (sync_state != null &&
(EntityFolder.OUTBOX.equals(type) ||
accountOnDemand || "connected".equals(accountState)));
}
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof TupleFolderEx) { if (obj instanceof TupleFolderEx) {
@ -37,6 +44,7 @@ public class TupleFolderEx extends EntityFolder {
Objects.equals(accountName, other.accountName) && Objects.equals(accountName, other.accountName) &&
Objects.equals(this.accountColor, other.accountColor) && Objects.equals(this.accountColor, other.accountColor) &&
Objects.equals(accountState, other.accountState) && Objects.equals(accountState, other.accountState) &&
Objects.equals(this.accountOnDemand, other.accountOnDemand) &&
this.messages == other.messages && this.messages == other.messages &&
this.content == other.content && this.content == other.content &&
this.unseen == other.unseen); this.unseen == other.unseen);

Loading…
Cancel
Save