Delay inflating message body

pull/156/head
M66B 6 years ago
parent 35514effd8
commit 0d7332b614

@ -63,6 +63,7 @@ import android.view.MotionEvent;
import android.view.TouchDelegate; import android.view.TouchDelegate;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewStub;
import android.webkit.DownloadListener; import android.webkit.DownloadListener;
import android.webkit.WebSettings; import android.webkit.WebSettings;
import android.webkit.WebView; import android.webkit.WebView;
@ -224,6 +225,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private ContentLoadingProgressBar pbLoading; private ContentLoadingProgressBar pbLoading;
private View vwRipple; private View vwRipple;
private View vsBody;
private ImageView ivExpanderAddress; private ImageView ivExpanderAddress;
private ImageButton ibSearchContact; private ImageButton ibSearchContact;
@ -324,54 +327,60 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvError = itemView.findViewById(R.id.tvError); tvError = itemView.findViewById(R.id.tvError);
pbLoading = itemView.findViewById(R.id.pbLoading); pbLoading = itemView.findViewById(R.id.pbLoading);
vwRipple = itemView.findViewById(R.id.vwRipple); vwRipple = itemView.findViewById(R.id.vwRipple);
}
if (viewType == ViewType.THREAD) { private void ensureExpanded() {
ConstraintLayout inAttachments = itemView.findViewById(R.id.inAttachments); if (vsBody != null)
ConstraintLayout inAttachmentsAlt = itemView.findViewById(R.id.inAttachmentsAlt); return;
vsBody = ((ViewStub) itemView.findViewById(R.id.vsBody)).inflate();
ConstraintLayout inAttachments = vsBody.findViewById(R.id.inAttachments);
ConstraintLayout inAttachmentsAlt = vsBody.findViewById(R.id.inAttachmentsAlt);
inAttachments.setVisibility(attachments_alt ? View.GONE : View.VISIBLE); inAttachments.setVisibility(attachments_alt ? View.GONE : View.VISIBLE);
inAttachmentsAlt.setVisibility(attachments_alt ? View.VISIBLE : View.GONE); inAttachmentsAlt.setVisibility(attachments_alt ? View.VISIBLE : View.GONE);
ConstraintLayout attachments = (attachments_alt ? inAttachmentsAlt : inAttachments); ConstraintLayout attachments = (attachments_alt ? inAttachmentsAlt : inAttachments);
ivExpanderAddress = itemView.findViewById(R.id.ivExpanderAddress); ivExpanderAddress = vsBody.findViewById(R.id.ivExpanderAddress);
ibSearchContact = itemView.findViewById(R.id.ibSearchContact); ibSearchContact = vsBody.findViewById(R.id.ibSearchContact);
ibNotifyContact = itemView.findViewById(R.id.ibNotifyContact); ibNotifyContact = vsBody.findViewById(R.id.ibNotifyContact);
ibAddContact = itemView.findViewById(R.id.ibAddContact); ibAddContact = vsBody.findViewById(R.id.ibAddContact);
tvFromExTitle = itemView.findViewById(R.id.tvFromExTitle); tvFromExTitle = vsBody.findViewById(R.id.tvFromExTitle);
tvToTitle = itemView.findViewById(R.id.tvToTitle); tvToTitle = vsBody.findViewById(R.id.tvToTitle);
tvReplyToTitle = itemView.findViewById(R.id.tvReplyToTitle); tvReplyToTitle = vsBody.findViewById(R.id.tvReplyToTitle);
tvCcTitle = itemView.findViewById(R.id.tvCcTitle); tvCcTitle = vsBody.findViewById(R.id.tvCcTitle);
tvBccTitle = itemView.findViewById(R.id.tvBccTitle); tvBccTitle = vsBody.findViewById(R.id.tvBccTitle);
tvIdentityTitle = itemView.findViewById(R.id.tvIdentityTitle); tvIdentityTitle = vsBody.findViewById(R.id.tvIdentityTitle);
tvTimeExTitle = itemView.findViewById(R.id.tvTimeExTitle); tvTimeExTitle = vsBody.findViewById(R.id.tvTimeExTitle);
tvSizeExTitle = itemView.findViewById(R.id.tvSizeExTitle); tvSizeExTitle = vsBody.findViewById(R.id.tvSizeExTitle);
tvFromEx = itemView.findViewById(R.id.tvFromEx); tvFromEx = vsBody.findViewById(R.id.tvFromEx);
tvTo = itemView.findViewById(R.id.tvTo); tvTo = vsBody.findViewById(R.id.tvTo);
tvReplyTo = itemView.findViewById(R.id.tvReplyTo); tvReplyTo = vsBody.findViewById(R.id.tvReplyTo);
tvCc = itemView.findViewById(R.id.tvCc); tvCc = vsBody.findViewById(R.id.tvCc);
tvBcc = itemView.findViewById(R.id.tvBcc); tvBcc = vsBody.findViewById(R.id.tvBcc);
tvIdentity = itemView.findViewById(R.id.tvIdentity); tvIdentity = vsBody.findViewById(R.id.tvIdentity);
tvTimeEx = itemView.findViewById(R.id.tvTimeEx); tvTimeEx = vsBody.findViewById(R.id.tvTimeEx);
tvSizeEx = itemView.findViewById(R.id.tvSizeEx); tvSizeEx = vsBody.findViewById(R.id.tvSizeEx);
tvSubjectEx = itemView.findViewById(R.id.tvSubjectEx); tvSubjectEx = vsBody.findViewById(R.id.tvSubjectEx);
tvFlags = itemView.findViewById(R.id.tvFlags); tvFlags = vsBody.findViewById(R.id.tvFlags);
tvKeywords = itemView.findViewById(R.id.tvKeywords); tvKeywords = vsBody.findViewById(R.id.tvKeywords);
tvHeaders = itemView.findViewById(R.id.tvHeaders); tvHeaders = vsBody.findViewById(R.id.tvHeaders);
pbHeaders = itemView.findViewById(R.id.pbHeaders); pbHeaders = vsBody.findViewById(R.id.pbHeaders);
tvNoInternetHeaders = itemView.findViewById(R.id.tvNoInternetHeaders); tvNoInternetHeaders = vsBody.findViewById(R.id.tvNoInternetHeaders);
tvCalendarSummary = view.findViewById(R.id.tvCalendarSummary); tvCalendarSummary = vsBody.findViewById(R.id.tvCalendarSummary);
tvCalendarStart = view.findViewById(R.id.tvCalendarStart); tvCalendarStart = vsBody.findViewById(R.id.tvCalendarStart);
tvCalendarEnd = view.findViewById(R.id.tvCalendarEnd); tvCalendarEnd = vsBody.findViewById(R.id.tvCalendarEnd);
tvAttendees = view.findViewById(R.id.tvAttendees); tvAttendees = vsBody.findViewById(R.id.tvAttendees);
btnCalendarAccept = view.findViewById(R.id.btnCalendarAccept); btnCalendarAccept = vsBody.findViewById(R.id.btnCalendarAccept);
btnCalendarDecline = view.findViewById(R.id.btnCalendarDecline); btnCalendarDecline = vsBody.findViewById(R.id.btnCalendarDecline);
btnCalendarMaybe = view.findViewById(R.id.btnCalendarMaybe); btnCalendarMaybe = vsBody.findViewById(R.id.btnCalendarMaybe);
pbCalendarWait = view.findViewById(R.id.pbCalendarWait); pbCalendarWait = vsBody.findViewById(R.id.pbCalendarWait);
rvAttachment = attachments.findViewById(R.id.rvAttachment); rvAttachment = attachments.findViewById(R.id.rvAttachment);
rvAttachment.setHasFixedSize(false); rvAttachment.setHasFixedSize(false);
@ -387,7 +396,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
btnSaveAttachments = attachments.findViewById(R.id.btnSaveAttachments); btnSaveAttachments = attachments.findViewById(R.id.btnSaveAttachments);
tvNoInternetAttachments = attachments.findViewById(R.id.tvNoInternetAttachments); tvNoInternetAttachments = attachments.findViewById(R.id.tvNoInternetAttachments);
bnvActions = itemView.findViewById(R.id.bnvActions); bnvActions = vsBody.findViewById(R.id.bnvActions);
if (compact) { if (compact) {
bnvActions.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED); bnvActions.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);
ViewGroup.LayoutParams lparam = bnvActions.getLayoutParams(); ViewGroup.LayoutParams lparam = bnvActions.getLayoutParams();
@ -395,15 +404,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
bnvActions.setLayoutParams(lparam); bnvActions.setLayoutParams(lparam);
} }
tbHtml = itemView.findViewById(R.id.tbHtml); tbHtml = vsBody.findViewById(R.id.tbHtml);
ibImages = itemView.findViewById(R.id.ibImages); ibImages = vsBody.findViewById(R.id.ibImages);
ibFull = itemView.findViewById(R.id.ibFull); ibFull = vsBody.findViewById(R.id.ibFull);
tvBody = itemView.findViewById(R.id.tvBody); tvBody = vsBody.findViewById(R.id.tvBody);
vwBody = itemView.findViewById(R.id.vwBody); vwBody = vsBody.findViewById(R.id.vwBody);
pbBody = itemView.findViewById(R.id.pbBody); pbBody = vsBody.findViewById(R.id.pbBody);
tvNoInternetBody = itemView.findViewById(R.id.tvNoInternetBody); tvNoInternetBody = vsBody.findViewById(R.id.tvNoInternetBody);
rvImage = itemView.findViewById(R.id.rvImage); rvImage = vsBody.findViewById(R.id.rvImage);
rvImage.setHasFixedSize(false); rvImage.setHasFixedSize(false);
StaggeredGridLayoutManager sglm = StaggeredGridLayoutManager sglm =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
@ -411,13 +420,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
adapterImage = new AdapterImage(context, owner); adapterImage = new AdapterImage(context, owner);
rvImage.setAdapter(adapterImage); rvImage.setAdapter(adapterImage);
grpAddresses = itemView.findViewById(R.id.grpAddresses); grpAddresses = vsBody.findViewById(R.id.grpAddresses);
grpHeaders = itemView.findViewById(R.id.grpHeaders); grpHeaders = vsBody.findViewById(R.id.grpHeaders);
grpCalendar = itemView.findViewById(R.id.grpCalendar); grpCalendar = vsBody.findViewById(R.id.grpCalendar);
grpCalendarResponse = itemView.findViewById(R.id.grpCalendarResponse); grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse);
grpAttachments = attachments.findViewById(R.id.grpAttachments); grpAttachments = attachments.findViewById(R.id.grpAttachments);
grpImages = itemView.findViewById(R.id.grpImages); grpImages = vsBody.findViewById(R.id.grpImages);
}
} }
Rect getItemRect() { Rect getItemRect() {
@ -446,7 +454,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivSnoozed.setOnClickListener(this); ivSnoozed.setOnClickListener(this);
ivFlagged.setOnClickListener(this); ivFlagged.setOnClickListener(this);
if (viewType == ViewType.THREAD) { if (vsBody != null) {
ivExpanderAddress.setOnClickListener(this); ivExpanderAddress.setOnClickListener(this);
ibSearchContact.setOnClickListener(this); ibSearchContact.setOnClickListener(this);
ibNotifyContact.setOnClickListener(this); ibNotifyContact.setOnClickListener(this);
@ -477,7 +485,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ivSnoozed.setOnClickListener(null); ivSnoozed.setOnClickListener(null);
ivFlagged.setOnClickListener(null); ivFlagged.setOnClickListener(null);
if (viewType == ViewType.THREAD) { if (vsBody != null) {
ivExpanderAddress.setOnClickListener(null); ivExpanderAddress.setOnClickListener(null);
ibSearchContact.setOnClickListener(null); ibSearchContact.setOnClickListener(null);
ibNotifyContact.setOnClickListener(null); ibNotifyContact.setOnClickListener(null);
@ -537,8 +545,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvFrom.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * (message.unseen > 0 ? 1.1f : 1f)); tvFrom.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * (message.unseen > 0 ? 1.1f : 1f));
tvSubject.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 0.9f); tvSubject.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 0.9f);
tvPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 0.9f); tvPreview.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize * 0.9f);
if (viewType == ViewType.THREAD)
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
int px = Math.round(TypedValue.applyDimension( int px = Math.round(TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_PX, textSize * (compact ? 1.5f : 3.0f), TypedValue.COMPLEX_UNIT_PX, textSize * (compact ? 1.5f : 3.0f),
@ -762,6 +768,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
private void clearExpanded() { private void clearExpanded() {
if (vsBody == null)
return;
cowner.stop(); cowner.stop();
if (compact) { if (compact) {
@ -856,6 +865,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvSubject.setSingleLine(false); tvSubject.setSingleLine(false);
} }
ensureExpanded();
grpAddresses.setVisibility(View.VISIBLE); grpAddresses.setVisibility(View.VISIBLE);
boolean hasFrom = (message.from != null && message.from.length > 0); boolean hasFrom = (message.from != null && message.from.length > 0);
@ -887,6 +898,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibImages.setVisibility(View.INVISIBLE); ibImages.setVisibility(View.INVISIBLE);
ibFull.setVisibility(show_html ? View.INVISIBLE : View.GONE); ibFull.setVisibility(show_html ? View.INVISIBLE : View.GONE);
if (textSize != 0)
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
tvBody.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT); tvBody.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT);
tvBody.setVisibility(!show_html ? View.INVISIBLE : View.GONE); tvBody.setVisibility(!show_html ? View.INVISIBLE : View.GONE);
vwBody.setVisibility(show_html ? View.INVISIBLE : View.GONE); vwBody.setVisibility(show_html ? View.INVISIBLE : View.GONE);

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/clItem"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -73,4 +74,37 @@
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/tvNoInternetBody" /> app:layout_constraintTop_toBottomOf="@id/tvNoInternetBody" />
<View
android:id="@+id/vwBody"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvBody" />
<include
android:id="@+id/InCalendar"
layout="@layout/include_message_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vwBody" />
<include
android:id="@+id/inAttachmentsAlt"
layout="@layout/include_message_attachments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/InCalendar" />
<include
android:id="@+id/inImages"
layout="@layout/include_message_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inAttachmentsAlt" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

@ -21,45 +21,12 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<include <ViewStub
android:id="@+id/inMessage" android:id="@+id/vsBody"
layout="@layout/include_message"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout="@layout/include_message_body"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inHeader" /> app:layout_constraintTop_toBottomOf="@id/inHeader" />
<View
android:id="@+id/vwBody"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inMessage" />
<include
android:id="@+id/InCalendar"
layout="@layout/include_message_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vwBody" />
<include
android:id="@+id/inAttachmentsAlt"
layout="@layout/include_message_attachments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/InCalendar" />
<include
android:id="@+id/inImages"
layout="@layout/include_message_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inAttachmentsAlt" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

@ -21,45 +21,12 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<include <ViewStub
android:id="@+id/inMessage" android:id="@+id/vsBody"
layout="@layout/include_message"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout="@layout/include_message_body"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inHeader" /> app:layout_constraintTop_toBottomOf="@id/inHeader" />
<View
android:id="@+id/vwBody"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="3dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inMessage" />
<include
android:id="@+id/InCalendar"
layout="@layout/include_message_calendar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/vwBody" />
<include
android:id="@+id/inAttachmentsAlt"
layout="@layout/include_message_attachments"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/InCalendar" />
<include
android:id="@+id/inImages"
layout="@layout/include_message_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/inAttachmentsAlt" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout> </FrameLayout>

Loading…
Cancel
Save