Improved download body behavior

pull/215/head
M66B 4 months ago
parent 058ea181ea
commit 53cbae149e

@ -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;
}

@ -56,8 +56,9 @@
<TextView
android:id="@+id/tvDownloading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="12dp"
android:layout_height="60dp"
android:gravity="center"
android:paddingHorizontal="12dp"
android:text="@string/title_download_message"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintEnd_toEndOf="parent"
@ -67,8 +68,8 @@
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbDownloading"
style="@style/Base.Widget.AppCompat.ProgressBar"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_width="36dp"
android:layout_height="36dp"
android:indeterminate="true"
app:layout_constraintBottom_toBottomOf="@id/tvDownloading"
app:layout_constraintEnd_toEndOf="@id/tvDownloading"
@ -86,6 +87,21 @@
app:layout_constraintTop_toTopOf="@+id/tvDownloading"
app:srcCompat="@drawable/twotone_info_24" />
<ImageButton
android:id="@+id/ibDownload"
android:layout_width="60dp"
android:layout_height="60dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_download"
android:padding="12dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_download"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownloading"
app:srcCompat="@drawable/twotone_cloud_download_24"
app:tint="?attr/colorAccent" />
<TextView
android:id="@+id/tvBody"
android:layout_width="0dp"
@ -100,7 +116,7 @@
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvDownloading" />
app:layout_constraintTop_toBottomOf="@id/ibDownload" />
<View
android:id="@+id/vwRipple"

Loading…
Cancel
Save