Delay inflating message body

This commit is contained in:
M66B 2019-05-30 19:46:58 +02:00
parent 35514effd8
commit 0d7332b614
4 changed files with 138 additions and 156 deletions

View File

@ -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,100 +327,105 @@ 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;
inAttachments.setVisibility(attachments_alt ? View.GONE : View.VISIBLE);
inAttachmentsAlt.setVisibility(attachments_alt ? View.VISIBLE : View.GONE);
ConstraintLayout attachments = (attachments_alt ? inAttachmentsAlt : inAttachments);
ivExpanderAddress = itemView.findViewById(R.id.ivExpanderAddress); vsBody = ((ViewStub) itemView.findViewById(R.id.vsBody)).inflate();
ibSearchContact = itemView.findViewById(R.id.ibSearchContact); ConstraintLayout inAttachments = vsBody.findViewById(R.id.inAttachments);
ibNotifyContact = itemView.findViewById(R.id.ibNotifyContact); ConstraintLayout inAttachmentsAlt = vsBody.findViewById(R.id.inAttachmentsAlt);
ibAddContact = itemView.findViewById(R.id.ibAddContact); inAttachments.setVisibility(attachments_alt ? View.GONE : View.VISIBLE);
inAttachmentsAlt.setVisibility(attachments_alt ? View.VISIBLE : View.GONE);
ConstraintLayout attachments = (attachments_alt ? inAttachmentsAlt : inAttachments);
tvFromExTitle = itemView.findViewById(R.id.tvFromExTitle); ivExpanderAddress = vsBody.findViewById(R.id.ivExpanderAddress);
tvToTitle = itemView.findViewById(R.id.tvToTitle);
tvReplyToTitle = itemView.findViewById(R.id.tvReplyToTitle);
tvCcTitle = itemView.findViewById(R.id.tvCcTitle);
tvBccTitle = itemView.findViewById(R.id.tvBccTitle);
tvIdentityTitle = itemView.findViewById(R.id.tvIdentityTitle);
tvTimeExTitle = itemView.findViewById(R.id.tvTimeExTitle);
tvSizeExTitle = itemView.findViewById(R.id.tvSizeExTitle);
tvFromEx = itemView.findViewById(R.id.tvFromEx); ibSearchContact = vsBody.findViewById(R.id.ibSearchContact);
tvTo = itemView.findViewById(R.id.tvTo); ibNotifyContact = vsBody.findViewById(R.id.ibNotifyContact);
tvReplyTo = itemView.findViewById(R.id.tvReplyTo); ibAddContact = vsBody.findViewById(R.id.ibAddContact);
tvCc = itemView.findViewById(R.id.tvCc);
tvBcc = itemView.findViewById(R.id.tvBcc);
tvIdentity = itemView.findViewById(R.id.tvIdentity);
tvTimeEx = itemView.findViewById(R.id.tvTimeEx);
tvSizeEx = itemView.findViewById(R.id.tvSizeEx);
tvSubjectEx = itemView.findViewById(R.id.tvSubjectEx); tvFromExTitle = vsBody.findViewById(R.id.tvFromExTitle);
tvFlags = itemView.findViewById(R.id.tvFlags); tvToTitle = vsBody.findViewById(R.id.tvToTitle);
tvKeywords = itemView.findViewById(R.id.tvKeywords); tvReplyToTitle = vsBody.findViewById(R.id.tvReplyToTitle);
tvCcTitle = vsBody.findViewById(R.id.tvCcTitle);
tvBccTitle = vsBody.findViewById(R.id.tvBccTitle);
tvIdentityTitle = vsBody.findViewById(R.id.tvIdentityTitle);
tvTimeExTitle = vsBody.findViewById(R.id.tvTimeExTitle);
tvSizeExTitle = vsBody.findViewById(R.id.tvSizeExTitle);
tvHeaders = itemView.findViewById(R.id.tvHeaders); tvFromEx = vsBody.findViewById(R.id.tvFromEx);
pbHeaders = itemView.findViewById(R.id.pbHeaders); tvTo = vsBody.findViewById(R.id.tvTo);
tvNoInternetHeaders = itemView.findViewById(R.id.tvNoInternetHeaders); tvReplyTo = vsBody.findViewById(R.id.tvReplyTo);
tvCc = vsBody.findViewById(R.id.tvCc);
tvBcc = vsBody.findViewById(R.id.tvBcc);
tvIdentity = vsBody.findViewById(R.id.tvIdentity);
tvTimeEx = vsBody.findViewById(R.id.tvTimeEx);
tvSizeEx = vsBody.findViewById(R.id.tvSizeEx);
tvCalendarSummary = view.findViewById(R.id.tvCalendarSummary); tvSubjectEx = vsBody.findViewById(R.id.tvSubjectEx);
tvCalendarStart = view.findViewById(R.id.tvCalendarStart); tvFlags = vsBody.findViewById(R.id.tvFlags);
tvCalendarEnd = view.findViewById(R.id.tvCalendarEnd); tvKeywords = vsBody.findViewById(R.id.tvKeywords);
tvAttendees = view.findViewById(R.id.tvAttendees);
btnCalendarAccept = view.findViewById(R.id.btnCalendarAccept);
btnCalendarDecline = view.findViewById(R.id.btnCalendarDecline);
btnCalendarMaybe = view.findViewById(R.id.btnCalendarMaybe);
pbCalendarWait = view.findViewById(R.id.pbCalendarWait);
rvAttachment = attachments.findViewById(R.id.rvAttachment); tvHeaders = vsBody.findViewById(R.id.tvHeaders);
rvAttachment.setHasFixedSize(false); pbHeaders = vsBody.findViewById(R.id.pbHeaders);
LinearLayoutManager llm = new LinearLayoutManager(context); tvNoInternetHeaders = vsBody.findViewById(R.id.tvNoInternetHeaders);
rvAttachment.setLayoutManager(llm);
rvAttachment.setItemAnimator(null);
adapterAttachment = new AdapterAttachment(context, owner, true); tvCalendarSummary = vsBody.findViewById(R.id.tvCalendarSummary);
rvAttachment.setAdapter(adapterAttachment); tvCalendarStart = vsBody.findViewById(R.id.tvCalendarStart);
tvCalendarEnd = vsBody.findViewById(R.id.tvCalendarEnd);
tvAttendees = vsBody.findViewById(R.id.tvAttendees);
btnCalendarAccept = vsBody.findViewById(R.id.btnCalendarAccept);
btnCalendarDecline = vsBody.findViewById(R.id.btnCalendarDecline);
btnCalendarMaybe = vsBody.findViewById(R.id.btnCalendarMaybe);
pbCalendarWait = vsBody.findViewById(R.id.pbCalendarWait);
cbInline = attachments.findViewById(R.id.cbInline); rvAttachment = attachments.findViewById(R.id.rvAttachment);
btnDownloadAttachments = attachments.findViewById(R.id.btnDownloadAttachments); rvAttachment.setHasFixedSize(false);
btnSaveAttachments = attachments.findViewById(R.id.btnSaveAttachments); LinearLayoutManager llm = new LinearLayoutManager(context);
tvNoInternetAttachments = attachments.findViewById(R.id.tvNoInternetAttachments); rvAttachment.setLayoutManager(llm);
rvAttachment.setItemAnimator(null);
bnvActions = itemView.findViewById(R.id.bnvActions); adapterAttachment = new AdapterAttachment(context, owner, true);
if (compact) { rvAttachment.setAdapter(adapterAttachment);
bnvActions.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);
ViewGroup.LayoutParams lparam = bnvActions.getLayoutParams();
lparam.height = dp36;
bnvActions.setLayoutParams(lparam);
}
tbHtml = itemView.findViewById(R.id.tbHtml); cbInline = attachments.findViewById(R.id.cbInline);
ibImages = itemView.findViewById(R.id.ibImages); btnDownloadAttachments = attachments.findViewById(R.id.btnDownloadAttachments);
ibFull = itemView.findViewById(R.id.ibFull); btnSaveAttachments = attachments.findViewById(R.id.btnSaveAttachments);
tvBody = itemView.findViewById(R.id.tvBody); tvNoInternetAttachments = attachments.findViewById(R.id.tvNoInternetAttachments);
vwBody = itemView.findViewById(R.id.vwBody);
pbBody = itemView.findViewById(R.id.pbBody);
tvNoInternetBody = itemView.findViewById(R.id.tvNoInternetBody);
rvImage = itemView.findViewById(R.id.rvImage); bnvActions = vsBody.findViewById(R.id.bnvActions);
rvImage.setHasFixedSize(false); if (compact) {
StaggeredGridLayoutManager sglm = bnvActions.setLabelVisibilityMode(LabelVisibilityMode.LABEL_VISIBILITY_UNLABELED);
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL); ViewGroup.LayoutParams lparam = bnvActions.getLayoutParams();
rvImage.setLayoutManager(sglm); lparam.height = dp36;
adapterImage = new AdapterImage(context, owner); bnvActions.setLayoutParams(lparam);
rvImage.setAdapter(adapterImage);
grpAddresses = itemView.findViewById(R.id.grpAddresses);
grpHeaders = itemView.findViewById(R.id.grpHeaders);
grpCalendar = itemView.findViewById(R.id.grpCalendar);
grpCalendarResponse = itemView.findViewById(R.id.grpCalendarResponse);
grpAttachments = attachments.findViewById(R.id.grpAttachments);
grpImages = itemView.findViewById(R.id.grpImages);
} }
tbHtml = vsBody.findViewById(R.id.tbHtml);
ibImages = vsBody.findViewById(R.id.ibImages);
ibFull = vsBody.findViewById(R.id.ibFull);
tvBody = vsBody.findViewById(R.id.tvBody);
vwBody = vsBody.findViewById(R.id.vwBody);
pbBody = vsBody.findViewById(R.id.pbBody);
tvNoInternetBody = vsBody.findViewById(R.id.tvNoInternetBody);
rvImage = vsBody.findViewById(R.id.rvImage);
rvImage.setHasFixedSize(false);
StaggeredGridLayoutManager sglm =
new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
rvImage.setLayoutManager(sglm);
adapterImage = new AdapterImage(context, owner);
rvImage.setAdapter(adapterImage);
grpAddresses = vsBody.findViewById(R.id.grpAddresses);
grpHeaders = vsBody.findViewById(R.id.grpHeaders);
grpCalendar = vsBody.findViewById(R.id.grpCalendar);
grpCalendarResponse = vsBody.findViewById(R.id.grpCalendarResponse);
grpAttachments = attachments.findViewById(R.id.grpAttachments);
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);

View File

@ -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" />
</androidx.constraintlayout.widget.ConstraintLayout>
<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>

View File

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

View File

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