Esdras Esdras - 16 days ago 14
Android Question

FirebaseRecyclerAdapter blinks my row when it's updated

I'm using Firebase to create a chat app. I'm using a

recycleView
and
FirebaseRecyclerAdapter
from firebase-ui to display all messages. My problem is when someone like a message (as you can see below) the entire layout blinks. It happens if I change the message on Firebase Console as well. In my view holder I only update the heart image view according with my model. I'm using version 0.6.2 but it still happens on 1.0.0.

About my adapter, I extend
FirebaseRecyclerAdapter
and because I'm using
viewTypes
I've overridden the following methods:


  • getItemViewType

  • populateViewHolder

  • onCreateViewHolder



enter image description here

class ChatMessageOutViewHolder extends RecyclerView.ViewHolder {

@BindView(R.id.message_out_content)
TextView messengerView;

@BindView(R.id.message_out_heart)
ImageView heartView;

@BindView(R.id.message_out_heart_likes)
TextView likesView;

@BindView(R.id.message_out_time)
TextView timeView;

ChatMessageOutViewHolder(View v) {
super(v);
ButterKnife.bind(this, v);
}

void apply(final ChatMessage model) {
messengerView.setText(model.content);
likesView.setText(model.likes == null ? "" : String.valueOf(model.likes.size()));

Drawable image = ContextCompat.getDrawable(mContext, R.drawable.ic_fav_1);
if (model.likes != null && model.likes.contains(mUserId)) {
image = ContextCompat.getDrawable(mContext, R.drawable.ic_fav_2);
}

heartView.setImageDrawable(image);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
timeView.setText(simpleDateFormat.format(new Date(model.getTimeStamp())));

heartView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onHeartClick(model);
}
}
});
}
}

Answer

I figured out!! It's not a bug on FirebaseRecyclerAdapter. It's sounds like a default behaviour of RecyclerView. To solve it a just add the following lines after setup my local reference.

RecyclerView.ItemAnimator animator = mRecyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
    ((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}