diff --git a/app/src/main/java/eu/faircode/email/DaoAnswer.java b/app/src/main/java/eu/faircode/email/DaoAnswer.java index b095e26667..34a58f2273 100644 --- a/app/src/main/java/eu/faircode/email/DaoAnswer.java +++ b/app/src/main/java/eu/faircode/email/DaoAnswer.java @@ -38,9 +38,6 @@ public interface DaoAnswer { @Query("SELECT * FROM answer") LiveData> liveAnswers(); - @Query("SELECT * FROM answer WHERE id = :id") - LiveData liveAnswer(long id); - @Insert long insertAnswer(EntityAnswer answer); diff --git a/app/src/main/java/eu/faircode/email/DaoFolder.java b/app/src/main/java/eu/faircode/email/DaoFolder.java index 7930c90294..cfbcb52273 100644 --- a/app/src/main/java/eu/faircode/email/DaoFolder.java +++ b/app/src/main/java/eu/faircode/email/DaoFolder.java @@ -72,9 +72,6 @@ public interface DaoFolder { " GROUP BY folder.id") LiveData> liveUnified(); - @Query("SELECT folder.* FROM folder WHERE folder.id = :id") - LiveData liveFolder(long id); - @Query("SELECT folder.*, account.name AS accountName" + ", COUNT(message.id) AS messages" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + diff --git a/app/src/main/java/eu/faircode/email/DaoIdentity.java b/app/src/main/java/eu/faircode/email/DaoIdentity.java index b14d4424d7..13c353d545 100644 --- a/app/src/main/java/eu/faircode/email/DaoIdentity.java +++ b/app/src/main/java/eu/faircode/email/DaoIdentity.java @@ -52,9 +52,6 @@ public interface DaoIdentity { @Query("SELECT * FROM identity WHERE account = :account AND email = :email") EntityIdentity getIdentity(long account, String email); - @Query("SELECT * FROM identity WHERE id = :id") - LiveData liveIdentity(long id); - @Query("SELECT COUNT(*) FROM identity WHERE synchronize") int getSynchronizingIdentityCount(); diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index af5001177f..9359383d02 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -87,7 +87,6 @@ import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentTransaction; -import androidx.lifecycle.Observer; import static android.accounts.AccountManager.newChooseAccountIntent; @@ -899,18 +898,18 @@ public class FragmentAccount extends FragmentEx { public void onActivityCreated(@Nullable final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - final DB db = DB.getInstance(getContext()); - - // Observe - db.account().liveAccount(id).observe(getViewLifecycleOwner(), new Observer() { - private boolean once = false; + Bundle args = new Bundle(); + args.putLong("id", id); + new SimpleTask() { @Override - public void onChanged(@Nullable EntityAccount account) { - if (once) - return; - once = true; + protected EntityAccount onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + return DB.getInstance(context).account().getAccount(id); + } + @Override + protected void onLoaded(Bundle args, EntityAccount account) { // Get providers List providers = Provider.loadProfiles(getContext()); providers.add(0, new Provider(getString(R.string.title_select))); @@ -986,24 +985,24 @@ public class FragmentAccount extends FragmentEx { ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE); pbWait.setVisibility(View.GONE); - if (account != null) { - db.folder().liveFolders(account.id).observe(getViewLifecycleOwner(), new Observer>() { - @Override - public void onChanged(final List _folders) { - new Handler().post(new Runnable() { - @Override - public void run() { - List folders = new ArrayList<>(); - if (_folders != null) - folders.addAll(_folders); - setFolders(folders); - } - }); - } - }); - } + args.putLong("account", account == null ? -1 : account.id); + + new SimpleTask>() { + @Override + protected List onLoad(Context context, Bundle args) throws Throwable { + long account = args.getLong("account"); + return DB.getInstance(context).folder().getFolders(account); + } + + @Override + protected void onLoaded(Bundle args, List folders) { + if (folders == null) + folders = new ArrayList<>(); + setFolders(folders); + } + }.load(FragmentAccount.this, args); } - }); + }.load(this, args); } private void selectAccount() { diff --git a/app/src/main/java/eu/faircode/email/FragmentAnswer.java b/app/src/main/java/eu/faircode/email/FragmentAnswer.java index f099c68907..779e897259 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAnswer.java +++ b/app/src/main/java/eu/faircode/email/FragmentAnswer.java @@ -36,7 +36,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; import androidx.lifecycle.Lifecycle; -import androidx.lifecycle.Observer; public class FragmentAnswer extends FragmentEx { private ViewGroup view; @@ -104,9 +103,18 @@ public class FragmentAnswer extends FragmentEx { public void onActivityCreated(@Nullable final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - DB.getInstance(getContext()).answer().liveAnswer(id).observe(getViewLifecycleOwner(), new Observer() { + Bundle args = new Bundle(); + args.putLong("id", id); + + new SimpleTask() { @Override - public void onChanged(EntityAnswer answer) { + protected EntityAnswer onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + return DB.getInstance(context).answer().getAnswer(id); + } + + @Override + protected void onLoaded(Bundle args, EntityAnswer answer) { etName.setText(answer == null ? null : answer.name); etText.setText(answer == null ? null : Html.fromHtml(answer.text)); bottom_navigation.findViewById(R.id.action_delete).setVisibility(answer == null ? View.GONE : View.VISIBLE); @@ -114,7 +122,7 @@ public class FragmentAnswer extends FragmentEx { pbWait.setVisibility(View.GONE); grpReady.setVisibility(View.VISIBLE); } - }); + }.load(this, args); } private void onActionTrash() { diff --git a/app/src/main/java/eu/faircode/email/FragmentFolder.java b/app/src/main/java/eu/faircode/email/FragmentFolder.java index 89e53536d1..d7ac97be03 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolder.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolder.java @@ -44,7 +44,6 @@ import javax.mail.Session; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.lifecycle.Observer; public class FragmentFolder extends FragmentEx { private ViewGroup view; @@ -310,16 +309,18 @@ public class FragmentFolder extends FragmentEx { public void onActivityCreated(@Nullable final Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); - // Observe - DB.getInstance(getContext()).folder().liveFolder(id).observe(getViewLifecycleOwner(), new Observer() { - private boolean once = false; + Bundle args = new Bundle(); + args.putLong("id", id); + new SimpleTask() { @Override - public void onChanged(@Nullable final EntityFolder folder) { - if (once) - return; - once = true; + protected EntityFolder onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + return DB.getInstance(context).folder().getFolder(id); + } + @Override + protected void onLoaded(Bundle args, EntityFolder folder) { if (savedInstanceState == null) { etRename.setText(folder == null ? null : folder.name); etDisplay.setText(folder == null ? null : (folder.display == null ? folder.name : folder.display)); @@ -338,6 +339,6 @@ public class FragmentFolder extends FragmentEx { btnSave.setEnabled(true); ibDelete.setVisibility(folder == null || !EntityFolder.USER.equals(folder.type) ? View.GONE : View.VISIBLE); } - }); + }.load(this, args); } } diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index eb95fc7bec..5851555c1d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -72,7 +72,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.Group; import androidx.fragment.app.FragmentTransaction; -import androidx.lifecycle.Observer; public class FragmentIdentity extends FragmentEx { private ViewGroup view; @@ -609,16 +608,18 @@ public class FragmentIdentity extends FragmentEx { final DB db = DB.getInstance(getContext()); - // Observe identity - db.identity().liveIdentity(id).observe(getViewLifecycleOwner(), new Observer() { - private boolean once = false; + Bundle args = new Bundle(); + args.putLong("id", id); + new SimpleTask() { @Override - public void onChanged(@Nullable final EntityIdentity identity) { - if (once) - return; - once = true; + protected EntityIdentity onLoad(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + return DB.getInstance(context).identity().getIdentity(id); + } + @Override + protected void onLoaded(Bundle args, final EntityIdentity identity) { if (savedInstanceState == null) { etName.setText(identity == null ? null : identity.name); etEmail.setText(identity == null ? null : identity.email); @@ -674,16 +675,14 @@ public class FragmentIdentity extends FragmentEx { ibDelete.setVisibility(identity == null ? View.GONE : View.VISIBLE); pbWait.setVisibility(View.GONE); - db.account().liveAccounts().removeObservers(getViewLifecycleOwner()); - db.account().liveAccounts().observe(getViewLifecycleOwner(), new Observer>() { - private boolean once = false; - + new SimpleTask>() { @Override - public void onChanged(List accounts) { - if (once) - return; - once = true; + protected List onLoad(Context context, Bundle args) throws Throwable { + return DB.getInstance(context).account().getAccounts(); + } + @Override + protected void onLoaded(Bundle args, List accounts) { if (accounts == null) accounts = new ArrayList<>(); @@ -742,9 +741,9 @@ public class FragmentIdentity extends FragmentEx { spAccount.setSelection(account); } } - }); + }.load(FragmentIdentity.this, args); } - }); + }.load(this, args); } private void setColor(int color) {