Fix issue where search results could flicker.
Shoutout to @clauz9 for the help in researching this bug!
This commit is contained in:
parent
bde4700e87
commit
cb77165b53
2 changed files with 9 additions and 13 deletions
|
@ -71,7 +71,6 @@ import org.thoughtcrime.securesms.recipients.RecipientForeverObserver;
|
|||
import org.thoughtcrime.securesms.recipients.RecipientId;
|
||||
import org.thoughtcrime.securesms.search.MessageResult;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.Debouncer;
|
||||
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
||||
import org.thoughtcrime.securesms.util.MediaUtil;
|
||||
import org.thoughtcrime.securesms.util.SearchUtil;
|
||||
|
@ -122,8 +121,6 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
private int unreadCount;
|
||||
private AvatarImageView contactPhotoImage;
|
||||
|
||||
private final Debouncer subjectViewClearDebouncer = new Debouncer(150);
|
||||
|
||||
private LiveData<SpannableString> displayBody;
|
||||
|
||||
public ConversationListItem(Context context) {
|
||||
|
@ -175,7 +172,6 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
{
|
||||
observeRecipient(thread.getRecipient().live());
|
||||
observeDisplayBody(null);
|
||||
setSubjectViewText(null);
|
||||
|
||||
this.threadId = thread.getThreadId();
|
||||
this.glideRequests = glideRequests;
|
||||
|
@ -188,7 +184,7 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
if (highlightSubstring != null) {
|
||||
String name = recipient.get().isSelf() ? getContext().getString(R.string.note_to_self) : recipient.get().getDisplayName(getContext());
|
||||
|
||||
this.fromView.setText(recipient.get(), SearchUtil.getHighlightedSpan(locale, SpanUtil::getMediumBoldSpan, name, highlightSubstring, SearchUtil.MATCH_ALL), false, null);
|
||||
this.fromView.setText(recipient.get(), SearchUtil.getHighlightedSpan(locale, SpanUtil::getMediumBoldSpan, name, highlightSubstring, SearchUtil.MATCH_ALL), true, null);
|
||||
} else {
|
||||
this.fromView.setText(recipient.get(), false);
|
||||
}
|
||||
|
@ -196,7 +192,9 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
this.typingThreads = typingThreads;
|
||||
updateTypingIndicator(typingThreads);
|
||||
|
||||
observeDisplayBody(getThreadDisplayBody(getContext(), thread, glideRequests, thumbSize, thumbTarget));
|
||||
LiveData<SpannableString> displayBody = getThreadDisplayBody(getContext(), thread, glideRequests, thumbSize, thumbTarget);
|
||||
setSubjectViewText(displayBody.getValue());
|
||||
observeDisplayBody(displayBody);
|
||||
|
||||
if (thread.getDate() > 0) {
|
||||
CharSequence date = DateUtils.getBriefRelativeTimeSpanString(getContext(), locale, thread.getDate());
|
||||
|
@ -382,9 +380,8 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
|
||||
private void setSubjectViewText(@Nullable CharSequence text) {
|
||||
if (text == null) {
|
||||
subjectViewClearDebouncer.publish(() -> subjectView.setText(null));
|
||||
subjectView.setText(null);
|
||||
} else {
|
||||
subjectViewClearDebouncer.clear();
|
||||
subjectView.setText(text);
|
||||
subjectView.setVisibility(VISIBLE);
|
||||
}
|
||||
|
@ -535,11 +532,11 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
return emphasisAdded(context, context.getString(thread.isOutgoing() ? R.string.ThreadRecord_you_deleted_this_message : R.string.ThreadRecord_this_message_was_deleted), defaultTint);
|
||||
} else {
|
||||
String body = removeNewlines(thread.getBody());
|
||||
LiveData<SpannableString> finalBody = LiveDataUtil.mapAsync(createFinalBodyWithMediaIcon(context, body, thread, glideRequests, thumbSize, thumbTarget), updatedBody -> {
|
||||
LiveData<SpannableString> finalBody = Transformations.map(createFinalBodyWithMediaIcon(context, body, thread, glideRequests, thumbSize, thumbTarget), updatedBody -> {
|
||||
if (thread.getRecipient().isGroup()) {
|
||||
RecipientId groupMessageSender = thread.getGroupMessageSender();
|
||||
if (!groupMessageSender.isUnknown()) {
|
||||
return createGroupMessageUpdateString(context, updatedBody, Recipient.resolved(groupMessageSender), thread.isRead());
|
||||
return createGroupMessageUpdateString(context, updatedBody, Recipient.resolved(groupMessageSender));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -605,8 +602,7 @@ public final class ConversationListItem extends ConstraintLayout
|
|||
|
||||
private static SpannableString createGroupMessageUpdateString(@NonNull Context context,
|
||||
@NonNull CharSequence body,
|
||||
@NonNull Recipient recipient,
|
||||
boolean read)
|
||||
@NonNull Recipient recipient)
|
||||
{
|
||||
String sender = (recipient.isSelf() ? context.getString(R.string.MessageRecord_you)
|
||||
: recipient.getShortDisplayName(context)) + ": ";
|
||||
|
|
|
@ -107,7 +107,7 @@ class ConversationListSearchAdapter extends RecyclerView.Adapter<Conversation
|
|||
|
||||
void updateResults(@NonNull SearchResult result) {
|
||||
this.searchResult = result;
|
||||
notifyDataSetChanged();
|
||||
notifyItemRangeChanged(0, getItemCount());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
Loading…
Add table
Reference in a new issue