mirror of https://github.com/KokaKiwi/BarInsta
54 lines
2.2 KiB
Java
54 lines
2.2 KiB
Java
package awais.instagrabber.adapters;
|
|
|
|
import android.view.LayoutInflater;
|
|
import android.view.View;
|
|
import android.view.ViewGroup;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.recyclerview.widget.DiffUtil;
|
|
import androidx.recyclerview.widget.ListAdapter;
|
|
|
|
import awais.instagrabber.adapters.viewholder.TopicClusterViewHolder;
|
|
import awais.instagrabber.databinding.ItemDiscoverTopicBinding;
|
|
import awais.instagrabber.models.TopicCluster;
|
|
|
|
public class DiscoverTopicsAdapter extends ListAdapter<TopicCluster, TopicClusterViewHolder> {
|
|
private static final DiffUtil.ItemCallback<TopicCluster> DIFF_CALLBACK = new DiffUtil.ItemCallback<TopicCluster>() {
|
|
@Override
|
|
public boolean areItemsTheSame(@NonNull final TopicCluster oldItem, @NonNull final TopicCluster newItem) {
|
|
return oldItem.getId().equals(newItem.getId());
|
|
}
|
|
|
|
@Override
|
|
public boolean areContentsTheSame(@NonNull final TopicCluster oldItem, @NonNull final TopicCluster newItem) {
|
|
return oldItem.getCoverMedia().getDisplayUrl().equals(newItem.getCoverMedia().getDisplayUrl())
|
|
&& oldItem.getTitle().equals(newItem.getTitle());
|
|
}
|
|
};
|
|
|
|
private final OnTopicClickListener onTopicClickListener;
|
|
|
|
public DiscoverTopicsAdapter(final OnTopicClickListener onTopicClickListener) {
|
|
super(DIFF_CALLBACK);
|
|
this.onTopicClickListener = onTopicClickListener;
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public TopicClusterViewHolder onCreateViewHolder(@NonNull final ViewGroup parent, final int viewType) {
|
|
final LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
|
|
final ItemDiscoverTopicBinding binding = ItemDiscoverTopicBinding.inflate(layoutInflater, parent, false);
|
|
return new TopicClusterViewHolder(binding, onTopicClickListener);
|
|
}
|
|
|
|
@Override
|
|
public void onBindViewHolder(@NonNull final TopicClusterViewHolder holder, final int position) {
|
|
final TopicCluster topicCluster = getItem(position);
|
|
holder.bind(topicCluster);
|
|
}
|
|
|
|
public interface OnTopicClickListener {
|
|
void onTopicClick(TopicCluster topicCluster, View root, View cover, View title, int titleColor, int backgroundColor);
|
|
}
|
|
}
|