From f2352fccb13151922d4c2027000741b62a0ef08c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 12 Nov 2018 18:42:36 +0100 Subject: [PATCH] Live FAQ compose --- .../java/eu/faircode/email/DaoAccount.java | 6 ++++ .../eu/faircode/email/FragmentMessages.java | 28 +++---------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/DaoAccount.java b/app/src/main/java/eu/faircode/email/DaoAccount.java index cbbf41178a..33e865a070 100644 --- a/app/src/main/java/eu/faircode/email/DaoAccount.java +++ b/app/src/main/java/eu/faircode/email/DaoAccount.java @@ -56,6 +56,12 @@ public interface DaoAccount { @Query("SELECT * FROM account WHERE id = :id") LiveData liveAccount(long id); + @Query("SELECT account.* FROM account" + + " JOIN folder ON folder.account = account.id" + + " WHERE (account.id = :id OR (:id IS NULL AND account.`primary`))" + + " AND folder.type = '" + EntityFolder.DRAFTS + "'") + LiveData liveAccountDraft(Long id); + @Query("SELECT" + " (SELECT COUNT(account.id) FROM account WHERE synchronize AND state = 'connected') AS accounts" + ", (SELECT COUNT(operation.id) FROM operation" + diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index c8bb5d4034..2019d1673b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -919,35 +919,15 @@ public class FragmentMessages extends FragmentEx { bottom_navigation.getMenu().findItem(R.id.action_next).setEnabled(pn[1] != null); bottom_navigation.setVisibility(!nav || (pn[0] == null && pn[1] == null) ? View.GONE : View.VISIBLE); } else { - // Compose FAB - Bundle args = new Bundle(); - args.putLong("account", account); - - new SimpleTask() { - @Override - protected Long onLoad(Context context, Bundle args) { - long account = args.getLong("account", -1); - - if (account < 0) { - EntityFolder primary = DB.getInstance(context).folder().getPrimaryDrafts(); - return (primary == null ? null : primary.account); - } else - return account; - } - + db.account().liveAccountDraft(account < 0 ? null : account).observe(getViewLifecycleOwner(), new Observer() { @Override - protected void onLoaded(Bundle args, Long account) { + public void onChanged(EntityAccount account) { if (account != null) { - fab.setTag(account); + fab.setTag(account.id); fab.show(); } } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getContext(), ex); - } - }.load(this, args); + }); } }