<commit_before>package com.carnivalmobile.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.carnival.sdk.Message;
import com.carnivalmobile.R;

import java.util.ArrayList;

public abstract class CarnivalAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

    private ArrayList<Message> mMessages = new ArrayList<>();
    private int mLastPosition = -1;
    private int mAnimation = R.anim.abc_slide_in_bottom;
    private Context mContext;

    public CarnivalAdapter(Context context) {
        this.mContext = context.getApplicationContext();
        setHasStableIds(true);
    }

    public CarnivalAdapter(Context context, ArrayList<Message> messages) {
        this(context);
        setMessages(messages);
    }

    public void setMessages(ArrayList<Message> messages) {
        mMessages = messages;
    }

    public ArrayList<Message> getMessages() {
        return mMessages;
    }

    @Override
    public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);

    @Override
    public void onBindViewHolder(VH holder, int position) {
        Message message = mMessages.get(position);
        onBindViewHolder(holder, position, message);

        if (holder.itemView != null) {
            applyAnimation(holder.itemView, position);
        }
    }

    @Override
    public void onViewDetachedFromWindow(VH holder) {
        if (holder.itemView != null) {
            holder.itemView.clearAnimation();
        }
    }

    public abstract void onBindViewHolder(VH holder, int position, Message message);

    /**<commit_msg>Register a stream impression for each message displayed<commit_after>package com.carnivalmobile.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;

import com.carnival.sdk.Carnival;
import com.carnival.sdk.CarnivalImpressionType;
import com.carnival.sdk.Message;
import com.carnivalmobile.R;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public abstract class CarnivalAdapter<VH extends RecyclerView.ViewHolder> extends RecyclerView.Adapter<VH> {

    private ArrayList<Message> mMessages = new ArrayList<>();
    private Set<String> sentImpressions = new HashSet<>();
    private int mLastPosition = -1;
    private int mAnimation = R.anim.abc_slide_in_bottom;
    private Context mContext;

    public CarnivalAdapter(Context context) {
        this.mContext = context.getApplicationContext();
        setHasStableIds(true);
    }

    public CarnivalAdapter(Context context, ArrayList<Message> messages) {
        this(context);
        setMessages(messages);
    }

    public void setMessages(ArrayList<Message> messages) {
        mMessages = messages;
    }

    public ArrayList<Message> getMessages() {
        return mMessages;
    }

    private void registerImpression(Message message) {
        if (message != null && !sentImpressions.contains(message.getMessageID())) {
            Carnival.registerMessageImpression(CarnivalImpressionType.IMPRESSION_TYPE_STREAM_VIEW, message);
            sentImpressions.add(message.getMessageID());
        }
    }

    @Override
    public abstract VH onCreateViewHolder(ViewGroup parent, int viewType);

    @Override
    public void onBindViewHolder(VH holder, int position) {
        Message message = mMessages.get(position);
        registerImpression(message);
        onBindViewHolder(holder, position, message);

        if (holder.itemView != null) {
            applyAnimation(holder.itemView, position);
        }
    }

    @Override
    public void onViewDetachedFromWindow(VH holder) {
        if (holder.itemView != null) {
            holder.itemView.clearAnimation();
        }
    }

    public abstract void onBindViewHolder(VH holder, int position, Message message);

    /**
{'fraction_non_alphanumeric': 0.09123910939012585, 'fraction_numerical': 0.000968054211035818, 'mean_word_length': 3.5169398907103826, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3406720', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1114, 'n_words': 256}