Utilize ItemCallback for ReactWithAnyAdapter.

Fixes #9918
This commit is contained in:
Alex Hart 2020-08-18 11:48:46 -03:00 committed by Greyson Parrelli
parent 065cbcf0f9
commit e006306036
3 changed files with 46 additions and 1 deletions

View file

@ -9,6 +9,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.widget.NestedScrollView;
import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;
@ -35,7 +36,7 @@ final class ReactWithAnyEmojiAdapter extends ListAdapter<ReactWithAnyEmojiPage,
@NonNull EmojiPageViewGridAdapter.VariationSelectorListener variationSelectorListener,
@NonNull Callbacks callbacks)
{
super(new AlwaysChangedDiffUtil<>());
super(new PageChangedCallback());
this.emojiEventListener = emojiEventListener;
this.variationSelectorListener = variationSelectorListener;
@ -169,4 +170,17 @@ final class ReactWithAnyEmojiAdapter extends ListAdapter<ReactWithAnyEmojiPage,
interface ScrollableChild {
void setNestedScrollingEnabled(boolean isEnabled);
}
private static class PageChangedCallback extends DiffUtil.ItemCallback<ReactWithAnyEmojiPage> {
@Override
public boolean areItemsTheSame(@NonNull ReactWithAnyEmojiPage oldItem, @NonNull ReactWithAnyEmojiPage newItem) {
return oldItem.getLabel() == newItem.getLabel();
}
@Override
public boolean areContentsTheSame(@NonNull ReactWithAnyEmojiPage oldItem, @NonNull ReactWithAnyEmojiPage newItem) {
return oldItem.equals(newItem);
}
}
}

View file

@ -7,6 +7,7 @@ import androidx.annotation.StringRes;
import org.whispersystems.libsignal.util.guava.Preconditions;
import java.util.List;
import java.util.Objects;
/**
* Represents a swipeable page in the ReactWithAnyEmoji dialog fragment, encapsulating any
@ -41,4 +42,17 @@ class ReactWithAnyEmojiPage {
public @AttrRes int getIconAttr() {
return pageBlocks.get(0).getPageModel().getIconAttr();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ReactWithAnyEmojiPage that = (ReactWithAnyEmojiPage) o;
return pageBlocks.equals(that.pageBlocks);
}
@Override
public int hashCode() {
return Objects.hash(pageBlocks);
}
}

View file

@ -5,6 +5,8 @@ import androidx.annotation.StringRes;
import org.thoughtcrime.securesms.components.emoji.EmojiPageModel;
import java.util.Objects;
/**
* Wraps a single "class" of Emojis, be it a predefined category, recents, etc. and provides
* a label for that "class".
@ -26,4 +28,19 @@ class ReactWithAnyEmojiPageBlock {
public EmojiPageModel getPageModel() {
return pageModel;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ReactWithAnyEmojiPageBlock that = (ReactWithAnyEmojiPageBlock) o;
return label == that.label &&
pageModel.getIconAttr() == that.pageModel.getIconAttr() &&
Objects.equals(pageModel.getEmoji(), that.pageModel.getEmoji());
}
@Override
public int hashCode() {
return Objects.hash(label, pageModel.getEmoji());
}
}