mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 00:53:26 +02:00
Improved download body behavior
This commit is contained in:
@@ -511,6 +511,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
private TextView tvNoInternetBody;
|
||||
private ImageButton ibDownloading;
|
||||
private Group grpDownloading;
|
||||
private ImageButton ibDownload;
|
||||
private ImageButton ibInfrastructure;
|
||||
private ImageButton ibTrashBottom;
|
||||
private ImageButton ibArchiveBottom;
|
||||
@@ -976,6 +977,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
tvNoInternetBody = vsBody.findViewById(R.id.tvNoInternetBody);
|
||||
ibDownloading = vsBody.findViewById(R.id.ibDownloading);
|
||||
grpDownloading = vsBody.findViewById(R.id.grpDownloading);
|
||||
ibDownload = vsBody.findViewById(R.id.ibDownload);
|
||||
ibInfrastructure = vsBody.findViewById(R.id.ibInfrastructure);
|
||||
ibTrashBottom = vsBody.findViewById(R.id.ibTrashBottom);
|
||||
ibArchiveBottom = vsBody.findViewById(R.id.ibArchiveBottom);
|
||||
@@ -1132,6 +1134,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
ibTools.setOnClickListener(this);
|
||||
|
||||
ibDownloading.setOnClickListener(this);
|
||||
ibDownload.setOnClickListener(this);
|
||||
ibInfrastructure.setOnClickListener(this);
|
||||
ibTrashBottom.setOnClickListener(this);
|
||||
ibTrashBottom.setOnLongClickListener(this);
|
||||
@@ -1256,6 +1259,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
ibTools.setOnClickListener(null);
|
||||
|
||||
ibDownloading.setOnClickListener(null);
|
||||
ibDownload.setOnClickListener(null);
|
||||
ibInfrastructure.setOnClickListener(null);
|
||||
ibTrashBottom.setOnClickListener(null);
|
||||
ibTrashBottom.setOnLongClickListener(null);
|
||||
@@ -1879,6 +1883,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
|
||||
tvNoInternetBody.setVisibility(View.GONE);
|
||||
grpDownloading.setVisibility(View.GONE);
|
||||
ibDownload.setVisibility(View.GONE);
|
||||
tvBody.setText(null);
|
||||
tvBody.setVisibility(View.GONE);
|
||||
vwRipple.setVisibility(View.GONE);
|
||||
@@ -2177,7 +2182,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
// Message text
|
||||
boolean content = (message.content || message.error != null);
|
||||
tvNoInternetBody.setVisibility(suitable || content ? View.GONE : View.VISIBLE);
|
||||
grpDownloading.setVisibility(content ? View.GONE : View.VISIBLE);
|
||||
|
||||
db.operation().liveOperations(message.id, EntityOperation.BODY).observe(owner, new Observer<TupleMessageOperation>() {
|
||||
@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<AdapterMessage.ViewHold
|
||||
onActionTools(message);
|
||||
} else if (id == R.id.ibDownloading) {
|
||||
Helper.viewFAQ(context, 15);
|
||||
} else if (id == R.id.ibSeen || id == R.id.ibSeenBottom) {
|
||||
} else if (id == R.id.ibDownload)
|
||||
onActionDownload(message);
|
||||
else if (id == R.id.ibSeen || id == R.id.ibSeenBottom) {
|
||||
onToggleSeen(message);
|
||||
} else if (id == R.id.ibHide) {
|
||||
onMenuHide(message);
|
||||
@@ -5473,6 +5487,42 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||
bindAddresses(message);
|
||||
}
|
||||
|
||||
private void onActionDownload(TupleMessageEx message) {
|
||||
Bundle args = new Bundle();
|
||||
args.putLong("id", message.id);
|
||||
|
||||
new SimpleTask<Void>() {
|
||||
@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;
|
||||
|
||||
@@ -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 &&
|
||||
|
||||
@@ -79,6 +79,12 @@ public interface DaoOperation {
|
||||
" ORDER BY " + priority + ", id")
|
||||
LiveData<List<TupleOperationEx>> 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<TupleMessageOperation> liveOperations(long message, String name);
|
||||
|
||||
@Transaction
|
||||
@Query("SELECT operation.*" +
|
||||
" FROM operation" +
|
||||
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
Copyright 2018-2024 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
public class TupleMessageOperation {
|
||||
public Long id;
|
||||
public boolean content;
|
||||
}
|
||||
Reference in New Issue
Block a user