1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Auto expand small messages only

Small = unmetered connection or size below setting
This commit is contained in:
M66B 2018-11-30 08:47:05 +01:00
parent 41abdc0643
commit 275ac6735c
4 changed files with 64 additions and 22 deletions

View file

@ -143,6 +143,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private ImageView ivFlagged;
private ImageView ivAvatar;
private TextView tvFrom;
private TextView tvSize;
private TextView tvTime;
private ImageView ivAnswered;
private ImageView ivAttachments;
@ -162,7 +163,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
private TextView tvCc;
private TextView tvBcc;
private TextView tvTimeEx;
private TextView tvSize;
private TextView tvSizeEx;
private TextView tvSubjectEx;
private TextView tvKeywords;
@ -196,7 +197,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivFlagged = itemView.findViewById(R.id.ivFlagged);
ivAvatar = itemView.findViewById(R.id.ivAvatar);
tvFrom = itemView.findViewById(R.id.tvFrom);
ivAddContact = itemView.findViewById(R.id.ivAddContact);
tvSize = itemView.findViewById(R.id.tvSize);
tvTime = itemView.findViewById(R.id.tvTime);
ivAnswered = itemView.findViewById(R.id.ivAnswered);
ivAttachments = itemView.findViewById(R.id.ivAttachments);
@ -210,12 +211,13 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivExpanderAddress = itemView.findViewById(R.id.ivExpanderAddress);
tvFromEx = itemView.findViewById(R.id.tvFromEx);
ivAddContact = itemView.findViewById(R.id.ivAddContact);
tvTo = itemView.findViewById(R.id.tvTo);
tvReplyTo = itemView.findViewById(R.id.tvReplyTo);
tvCc = itemView.findViewById(R.id.tvCc);
tvBcc = itemView.findViewById(R.id.tvBcc);
tvTimeEx = itemView.findViewById(R.id.tvTimeEx);
tvSize = itemView.findViewById(R.id.tvSize);
tvSizeEx = itemView.findViewById(R.id.tvSizeEx);
tvSubjectEx = itemView.findViewById(R.id.tvSubjectEx);
tvKeywords = itemView.findViewById(R.id.tvKeywords);
@ -276,7 +278,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivFlagged.setVisibility(View.GONE);
ivAvatar.setVisibility(View.GONE);
tvFrom.setText(null);
ivAddContact.setVisibility(View.GONE);
tvSize.setText(null);
tvTime.setText(null);
ivAnswered.setVisibility(View.GONE);
ivAttachments.setVisibility(View.GONE);
@ -315,6 +317,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivFlagged.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
ivAvatar.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
tvFrom.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
tvSize.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
tvTime.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
ivAnswered.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
ivAttachments.setAlpha(message.duplicate ? LOW_LIGHT : 1.0f);
@ -363,6 +366,8 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
ivFlagged.setVisibility(message.count - message.unflagged > 0 ? View.VISIBLE : View.GONE);
tvFrom.setText(MessageHelper.getFormattedAddresses(outgoing ? message.to : message.from, !compact));
tvSize.setText(message.size == null ? null : Helper.humanReadableByteCount(message.size, true));
tvSize.setVisibility(message.size == null || message.content ? View.GONE : View.VISIBLE);
tvTime.setText(DateUtils.getRelativeTimeSpanString(context, message.received));
ivAnswered.setVisibility(message.ui_answered ? View.VISIBLE : View.GONE);
@ -415,6 +420,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
// Unseen
int typeface = (message.unseen > 0 ? Typeface.BOLD : Typeface.NORMAL);
tvFrom.setTypeface(null, typeface);
tvSize.setTypeface(null, typeface);
tvTime.setTypeface(null, typeface);
tvSubject.setTypeface(null, typeface);
tvCount.setTypeface(null, typeface);
@ -422,6 +428,7 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
int colorUnseen = Helper.resolveColor(context, message.unseen > 0
? R.attr.colorUnread : android.R.attr.textColorSecondary);
tvFrom.setTextColor(colorUnseen);
tvSize.setTextColor(colorUnseen);
tvTime.setTextColor(colorUnseen);
grpAddress.setVisibility(viewType == ViewType.THREAD && show_expanded && show_addresses ? View.VISIBLE : View.GONE);
@ -453,10 +460,10 @@ public class AdapterMessage extends PagedListAdapter<TupleMessageEx, AdapterMess
tvTimeEx.setText(df.format(new Date(message.received)));
tvSize.setText(message.size == null ? null : Helper.humanReadableByteCount(message.size, true));
tvSizeEx.setText(message.size == null ? null : Helper.humanReadableByteCount(message.size, true));
if (!message.duplicate)
tvSize.setAlpha(message.content ? 1.0f : LOW_LIGHT);
tvSize.setVisibility(message.size == null ? View.GONE : View.VISIBLE);
tvSizeEx.setAlpha(message.content ? 1.0f : LOW_LIGHT);
tvSizeEx.setVisibility(message.size == null ? View.GONE : View.VISIBLE);
tvSubjectEx.setText(message.subject);
tvKeywords.setText(TextUtils.join(" ", message.keywords));

View file

@ -25,6 +25,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
@ -1322,12 +1323,22 @@ public class FragmentMessages extends FragmentEx {
if (autoExpand) {
autoExpand = false;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
long download = prefs.getInt("download", 32768);
if (download == 0)
download = Long.MAX_VALUE;
ConnectivityManager cm = getContext().getSystemService(ConnectivityManager.class);
boolean metered = (cm == null || cm.isActiveNetworkMetered());
int count = 0;
int unseen = 0;
TupleMessageEx single = null;
TupleMessageEx see = null;
for (TupleMessageEx message : messages) {
if (!message.duplicate && !EntityFolder.TRASH.equals(message.folderType)) {
if (!message.duplicate &&
!EntityFolder.TRASH.equals(message.folderType) &&
(!metered || (message.size != null && message.size < download))) {
count++;
single = message;
if (!message.ui_seen) {

View file

@ -80,10 +80,22 @@
android:maxLines="1"
android:text="From"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@+id/tvTime"
app:layout_constraintEnd_toStartOf="@+id/tvSize"
app:layout_constraintStart_toEndOf="@id/ivAvatar"
app:layout_constraintTop_toBottomOf="@id/paddingTop" />
<TextView
android:id="@+id/tvSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:maxLines="1"
android:text="123 KB"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/tvFrom"
app:layout_constraintEnd_toStartOf="@id/tvTime"
app:layout_constraintTop_toTopOf="@id/tvFrom" />
<TextView
android:id="@+id/tvTime"
android:layout_width="wrap_content"
@ -393,7 +405,7 @@
app:layout_constraintTop_toBottomOf="@id/tvBcc" />
<TextView
android:id="@+id/tvSizeTitle"
android:id="@+id/tvSizeExTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
@ -403,7 +415,7 @@
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView
android:id="@+id/tvSize"
android:id="@+id/tvSizeEx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
@ -412,7 +424,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvSizeTitle"
app:layout_constraintStart_toEndOf="@id/tvSizeExTitle"
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView
@ -426,7 +438,7 @@
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSize" />
app:layout_constraintTop_toBottomOf="@id/tvSizeEx" />
<TextView
android:id="@+id/tvKeywords"
@ -598,7 +610,7 @@
android:id="@+id/grpAddress"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvFromExTitle,tvFromEx,tvToTitle,tvTo,tvReplyToTitle,tvReplyTo,tvCcTitle,tvCc,tvBccTitle,tvBcc,tvTimeExTitle,tvTimeEx,tvSizeTitle,tvSize,tvSubjectEx" />
app:constraint_referenced_ids="tvFromExTitle,tvFromEx,tvToTitle,tvTo,tvReplyToTitle,tvReplyTo,tvCcTitle,tvCc,tvBccTitle,tvBcc,tvTimeExTitle,tvTimeEx,tvSizeExTitle,tvSizeEx,tvSubjectEx" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpHeaders"
@ -618,4 +630,4 @@
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAddress,ivExpanderAddress,tvBody" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</FrameLayout>

View file

@ -77,10 +77,22 @@
android:ellipsize="end"
android:text="From"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toStartOf="@+id/tvTime"
app:layout_constraintEnd_toStartOf="@+id/tvSize"
app:layout_constraintStart_toEndOf="@id/ivAvatar"
app:layout_constraintTop_toBottomOf="@id/paddingTop" />
<TextView
android:id="@+id/tvSize"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:maxLines="1"
android:text="123 KB"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintBottom_toBottomOf="@id/tvFrom"
app:layout_constraintEnd_toStartOf="@id/tvTime"
app:layout_constraintTop_toTopOf="@id/tvFrom" />
<TextView
android:id="@+id/tvTime"
android:layout_width="wrap_content"
@ -390,7 +402,7 @@
app:layout_constraintTop_toBottomOf="@id/tvBcc" />
<TextView
android:id="@+id/tvSizeTitle"
android:id="@+id/tvSizeExTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
@ -400,7 +412,7 @@
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView
android:id="@+id/tvSize"
android:id="@+id/tvSizeEx"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
@ -409,7 +421,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvSizeTitle"
app:layout_constraintStart_toEndOf="@id/tvSizeExTitle"
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView
@ -423,7 +435,7 @@
android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSize" />
app:layout_constraintTop_toBottomOf="@id/tvSizeEx" />
<TextView
android:id="@+id/tvKeywords"
@ -595,7 +607,7 @@
android:id="@+id/grpAddress"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvFromExTitle,tvFromEx,tvToTitle,tvTo,tvReplyToTitle,tvReplyTo,tvCcTitle,tvCc,tvBccTitle,tvBcc,tvTimeExTitle,tvTimeEx,tvSizeTitle,tvSize,tvSubjectEx" />
app:constraint_referenced_ids="tvFromExTitle,tvFromEx,tvToTitle,tvTo,tvReplyToTitle,tvReplyTo,tvCcTitle,tvCc,tvBccTitle,tvBcc,tvTimeExTitle,tvTimeEx,tvSizeExTitle,tvSizeEx,tvSubjectEx" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpHeaders"
@ -615,4 +627,4 @@
android:layout_height="0dp"
app:constraint_referenced_ids="vSeparatorAddress,ivExpanderAddress,tvBody" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>
</FrameLayout>