From 53cbae149e9ace4d16d1fe141752aa9187b2c693 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 7 Jun 2024 20:08:56 +0200 Subject: [PATCH] Improved download body behavior --- .../eu/faircode/email/AdapterMessage.java | 54 ++++++++++++++++++- app/src/main/java/eu/faircode/email/Core.java | 2 +- .../java/eu/faircode/email/DaoOperation.java | 6 +++ .../faircode/email/TupleMessageOperation.java | 25 +++++++++ .../main/res/layout/include_message_body.xml | 26 +++++++-- 5 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 app/src/main/java/eu/faircode/email/TupleMessageOperation.java diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 4bc6bc7f90..dc24357603 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -511,6 +511,7 @@ public class AdapterMessage extends RecyclerView.Adapter() { + @Override + public void onChanged(TupleMessageOperation operation) { + grpDownloading.setVisibility(operation == null || operation.id == null ? View.GONE : View.VISIBLE); + ibDownload.setVisibility(operation != null && operation.id == null && !operation.content ? View.VISIBLE : View.GONE); + } + }); boolean show_full = properties.getValue("full", message.id); if (show_full) @@ -4606,7 +4618,9 @@ public class AdapterMessage extends RecyclerView.Adapter() { + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + try { + db.beginTransaction(); + + EntityMessage message = db.message().getMessage(id); + if (message == null) + return null; + + db.message().setMessageError(message.id, null); + + EntityOperation.queue(context, message, EntityOperation.BODY); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(parentFragment.getParentFragment(), ex); + } + }.execute(context, owner, args, "message:downlaod"); + } + private boolean getShowAddressesDefault(TupleMessageEx message) { if (show_addresses_default) return true; diff --git a/app/src/main/java/eu/faircode/email/Core.java b/app/src/main/java/eu/faircode/email/Core.java index b806df5c18..1711fe3333 100644 --- a/app/src/main/java/eu/faircode/email/Core.java +++ b/app/src/main/java/eu/faircode/email/Core.java @@ -576,7 +576,7 @@ class Core { db.operation().setOperationTries(op.id, op.tries); - op.error = Log.formatThrowable(ex); + op.error = Log.formatThrowable(ex, !EntityOperation.BODY.equals(op.name)); db.operation().setOperationError(op.id, op.error); if (message != null && diff --git a/app/src/main/java/eu/faircode/email/DaoOperation.java b/app/src/main/java/eu/faircode/email/DaoOperation.java index 7bdc9aeb42..bc258dbaa8 100644 --- a/app/src/main/java/eu/faircode/email/DaoOperation.java +++ b/app/src/main/java/eu/faircode/email/DaoOperation.java @@ -79,6 +79,12 @@ public interface DaoOperation { " ORDER BY " + priority + ", id") LiveData> liveOperations(long account); + @Query("SELECT operation.id, message.content" + + " FROM message" + + " LEFT JOIN operation ON operation.message = message.id AND operation.name = :name" + + " WHERE message.id = :message") + LiveData liveOperations(long message, String name); + @Transaction @Query("SELECT operation.*" + " FROM operation" + diff --git a/app/src/main/java/eu/faircode/email/TupleMessageOperation.java b/app/src/main/java/eu/faircode/email/TupleMessageOperation.java new file mode 100644 index 0000000000..451aafe7cb --- /dev/null +++ b/app/src/main/java/eu/faircode/email/TupleMessageOperation.java @@ -0,0 +1,25 @@ +package eu.faircode.email; + +/* + This file is part of FairEmail. + + FairEmail is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + FairEmail is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with FairEmail. If not, see . + + Copyright 2018-2024 by Marcel Bokhorst (M66B) +*/ + +public class TupleMessageOperation { + public Long id; + public boolean content; +} diff --git a/app/src/main/res/layout/include_message_body.xml b/app/src/main/res/layout/include_message_body.xml index 9bb6c43d38..f390ede4bd 100644 --- a/app/src/main/res/layout/include_message_body.xml +++ b/app/src/main/res/layout/include_message_body.xml @@ -56,8 +56,9 @@ + + + app:layout_constraintTop_toBottomOf="@id/ibDownload" />