Auto expand small messages only

Small = unmetered connection or size below setting
pull/146/head
M66B 6 years ago
parent 41abdc0643
commit 275ac6735c

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

@ -25,6 +25,7 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
@ -1322,12 +1323,22 @@ public class FragmentMessages extends FragmentEx {
if (autoExpand) { if (autoExpand) {
autoExpand = false; 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 count = 0;
int unseen = 0; int unseen = 0;
TupleMessageEx single = null; TupleMessageEx single = null;
TupleMessageEx see = null; TupleMessageEx see = null;
for (TupleMessageEx message : messages) { 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++; count++;
single = message; single = message;
if (!message.ui_seen) { if (!message.ui_seen) {

@ -80,10 +80,22 @@
android:maxLines="1" android:maxLines="1"
android:text="From" android:text="From"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" 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_constraintStart_toEndOf="@id/ivAvatar"
app:layout_constraintTop_toBottomOf="@id/paddingTop" /> 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 <TextView
android:id="@+id/tvTime" android:id="@+id/tvTime"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -393,7 +405,7 @@
app:layout_constraintTop_toBottomOf="@id/tvBcc" /> app:layout_constraintTop_toBottomOf="@id/tvBcc" />
<TextView <TextView
android:id="@+id/tvSizeTitle" android:id="@+id/tvSizeExTitle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -403,7 +415,7 @@
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" /> app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView <TextView
android:id="@+id/tvSize" android:id="@+id/tvSizeEx"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -412,7 +424,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textIsSelectable="true" android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvSizeTitle" app:layout_constraintStart_toEndOf="@id/tvSizeExTitle"
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" /> app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView <TextView
@ -426,7 +438,7 @@
android:textIsSelectable="true" android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSize" /> app:layout_constraintTop_toBottomOf="@id/tvSizeEx" />
<TextView <TextView
android:id="@+id/tvKeywords" android:id="@+id/tvKeywords"
@ -598,7 +610,7 @@
android:id="@+id/grpAddress" android:id="@+id/grpAddress"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="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 <androidx.constraintlayout.widget.Group
android:id="@+id/grpHeaders" android:id="@+id/grpHeaders"

@ -77,10 +77,22 @@
android:ellipsize="end" android:ellipsize="end"
android:text="From" android:text="From"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" 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_constraintStart_toEndOf="@id/ivAvatar"
app:layout_constraintTop_toBottomOf="@id/paddingTop" /> 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 <TextView
android:id="@+id/tvTime" android:id="@+id/tvTime"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -390,7 +402,7 @@
app:layout_constraintTop_toBottomOf="@id/tvBcc" /> app:layout_constraintTop_toBottomOf="@id/tvBcc" />
<TextView <TextView
android:id="@+id/tvSizeTitle" android:id="@+id/tvSizeExTitle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -400,7 +412,7 @@
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" /> app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView <TextView
android:id="@+id/tvSize" android:id="@+id/tvSizeEx"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="6dp" android:layout_marginStart="6dp"
@ -409,7 +421,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textIsSelectable="true" android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/tvSizeTitle" app:layout_constraintStart_toEndOf="@id/tvSizeExTitle"
app:layout_constraintTop_toBottomOf="@id/tvTimeEx" /> app:layout_constraintTop_toBottomOf="@id/tvTimeEx" />
<TextView <TextView
@ -423,7 +435,7 @@
android:textIsSelectable="true" android:textIsSelectable="true"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSize" /> app:layout_constraintTop_toBottomOf="@id/tvSizeEx" />
<TextView <TextView
android:id="@+id/tvKeywords" android:id="@+id/tvKeywords"
@ -595,7 +607,7 @@
android:id="@+id/grpAddress" android:id="@+id/grpAddress"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="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 <androidx.constraintlayout.widget.Group
android:id="@+id/grpHeaders" android:id="@+id/grpHeaders"

Loading…
Cancel
Save