Scroll after loading images

pull/162/head
M66B 6 years ago
parent 6242348d32
commit da1cf00c57

@ -965,7 +965,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
//tvFrom.setText(info.getDisplayName(name_email)); //tvFrom.setText(info.getDisplayName(name_email));
} }
private void bindExpanded(final TupleMessageEx message, boolean scroll) { private void bindExpanded(final TupleMessageEx message, final boolean scroll) {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
boolean show_addresses = !properties.getValue("addresses", message.id); boolean show_addresses = !properties.getValue("addresses", message.id);
@ -1091,26 +1091,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
// Attachments // Attachments
bindAttachments(message, properties.getAttachments(message.id)); bindAttachments(message, properties.getAttachments(message.id));
cowner.recreate();
db.attachment().liveAttachments(message.id).observe(cowner, new Observer<List<EntityAttachment>>() {
private int lastInlineImages = 0;
@Override
public void onChanged(@Nullable List<EntityAttachment> attachments) {
bindAttachments(message, attachments);
int inlineImages = 0;
if (attachments != null)
for (EntityAttachment attachment : attachments)
if (attachment.available && attachment.isInline() && attachment.isImage())
inlineImages++;
if (inlineImages != lastInlineImages) {
lastInlineImages = inlineImages;
loadText(message, false);
}
}
});
// Setup actions // Setup actions
Bundle sargs = new Bundle(); Bundle sargs = new Bundle();
@ -1193,12 +1173,32 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setMovementMethod(null); tvBody.setMovementMethod(null);
tvBody.setVisibility(View.VISIBLE); tvBody.setVisibility(View.VISIBLE);
if (scroll && body != null) { cowner.recreate();
properties.scrollTo(getAdapterPosition());
scroll = false;
}
loadText(message, scroll); loadText(message);
db.attachment().liveAttachments(message.id).observe(cowner, new Observer<List<EntityAttachment>>() {
private int lastInlineImages = 0;
@Override
public void onChanged(@Nullable List<EntityAttachment> attachments) {
bindAttachments(message, attachments);
int inlineImages = 0;
if (attachments != null)
for (EntityAttachment attachment : attachments)
if (attachment.available && attachment.isInline() && attachment.isImage())
inlineImages++;
if (inlineImages != lastInlineImages) {
lastInlineImages = inlineImages;
loadText(message);
}
if (scroll)
properties.scrollTo(getAdapterPosition());
}
});
} }
private void bindAttachments(final TupleMessageEx message, @Nullable List<EntityAttachment> attachments) { private void bindAttachments(final TupleMessageEx message, @Nullable List<EntityAttachment> attachments) {
@ -2117,7 +2117,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibImages.setVisibility(View.GONE); ibImages.setVisibility(View.GONE);
loadText(message, false); loadText(message);
// Download inline images // Download inline images
Bundle args = new Bundle(); Bundle args = new Bundle();
@ -2501,7 +2501,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.show(); popupMenu.show();
} }
private void loadText(TupleMessageEx message, boolean scroll) { private void loadText(TupleMessageEx message) {
if (message.content) { if (message.content) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
if (message.from != null) if (message.from != null)
@ -2518,7 +2518,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putSerializable("message", message); args.putSerializable("message", message);
args.putBoolean("scroll", scroll);
args.putBoolean("show_images", show_images); args.putBoolean("show_images", show_images);
args.putBoolean("show_quotes", show_quotes); args.putBoolean("show_quotes", show_quotes);
args.putInt("zoom", zoom); args.putInt("zoom", zoom);
@ -2638,7 +2637,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (!show_expanded) if (!show_expanded)
return; return;
boolean scroll = args.getBoolean("scroll");
boolean has_images = args.getBoolean("has_images"); boolean has_images = args.getBoolean("has_images");
boolean show_images = properties.getValue("images", message.id); boolean show_images = properties.getValue("images", message.id);
@ -2650,9 +2648,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
tvBody.setTextIsSelectable(true); tvBody.setTextIsSelectable(true);
tvBody.setMovementMethod(new TouchHandler(message)); tvBody.setMovementMethod(new TouchHandler(message));
if (scroll)
properties.scrollTo(getAdapterPosition());
pbBody.setVisibility(View.GONE); pbBody.setVisibility(View.GONE);
// Show attachments/images // Show attachments/images
@ -2731,7 +2726,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
DynamicDrawableSpan[] ddss = buffer.getSpans(off, off, DynamicDrawableSpan.class); DynamicDrawableSpan[] ddss = buffer.getSpans(off, off, DynamicDrawableSpan.class);
if (ddss.length > 0) { if (ddss.length > 0) {
properties.setValue("quotes", message.id, true); properties.setValue("quotes", message.id, true);
loadText(message, false); loadText(message);
} }
} }

Loading…
Cancel
Save