<commit_before>package com.pr0gramm.app.ui;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.pr0gramm.app.R;
import com.pr0gramm.app.api.pr0gramm.response.Message;
import com.pr0gramm.app.ui.views.SenderInfoView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import roboguice.RoboGuice;

import static com.google.common.collect.Lists.newArrayList;

/**
 */
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder> {
    private final List<Message> messages;
    private final Context context;
    private final Picasso picasso;
    private final MessageActionListener actionListener;

    public MessageAdapter(Context context, List<Message> messages) {
        this(context, messages, null);
    }

    public MessageAdapter(Context context, List<Message> messages, MessageActionListener actionListener) {
        this.context = context;
        this.actionListener = actionListener;
        this.messages = new ArrayList<>(messages);
        this.picasso = RoboGuice.getInjector(context).getInstance(Picasso.class);

        setHasStableIds(true);
    }

    /**
     * Replace all the messages with the new messages from the given iterable.
     */
    public void setMessages(Iterable<Message> messages) {
        this.messages.clear();
        Iterables.addAll(this.messages, messages);
        notifyDataSetChanged();
    }

    @Override
    public long getItemId(int position) {
        return messages.get(position).getId();
    }

    @Override
    public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.inbox_message, parent, false);
        return new MessageViewHolder(view);
    }

    @SuppressWarnings("CodeBlock2Expr")
    @Override
    public void onBindViewHolder(MessageViewHolder view, int position) {
        Message message = messages.get(position);

        // set the type. if we have an item, we  have a comment
        boolean isComment = message.getItemId() != 0;
        view.type.setText(isComment ? context.getString(R.string.inbox_message_comment) : context.getString(R.string.inbox_message_private));

        // the text of the message
        view.text.setText(message.getMessage());
        Linkify.addLinks(view.text, Linkify.WEB_URLS);

        // draw the image for this post
        if (isComment) {
            view.image.setVisibility(View.VISIBLE);

            String url = "http://thumb.pr0gramm.com/" + message.getThumb();
            picasso.load(url).into(view.image);
        } else {
            view.image.setVisibility(View.GONE);
            picasso.cancelRequest(view.image);
        }

        // sender info
        view.sender.setSenderName(message.getName(), message.getMark());
        view.sender.setPointsVisible(isComment);
        view.sender.setPoints(message.getScore());
        view.sender.setDate(message.getCreated());

        if (actionListener != null) {
            view.sender.setOnSenderClickedListener(v -> {
                actionListener.onUserClicked(message.getSenderId(), message.getName());
            });

            if (isComment) {
                view.sender.setAnswerClickedListener(v -> {
                    actionListener.onAnswerToCommentClicked(message.getItemId(), message.getId(), message.getName());
                });
<commit_msg>Fixed a bug with answer buttons that send message to the wrong persons<commit_after>package com.pr0gramm.app.ui;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.util.Linkify;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.pr0gramm.app.R;
import com.pr0gramm.app.api.pr0gramm.response.Message;
import com.pr0gramm.app.ui.views.SenderInfoView;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

import roboguice.RoboGuice;

import static com.google.common.collect.Lists.newArrayList;

/**
 */
public class MessageAdapter extends RecyclerView.Adapter<MessageAdapter.MessageViewHolder> {
    private final List<Message> messages;
    private final Context context;
    private final Picasso picasso;
    private final MessageActionListener actionListener;

    public MessageAdapter(Context context, List<Message> messages) {
        this(context, messages, null);
    }

    public MessageAdapter(Context context, List<Message> messages, MessageActionListener actionListener) {
        this.context = context;
        this.actionListener = actionListener;
        this.messages = new ArrayList<>(messages);
        this.picasso = RoboGuice.getInjector(context).getInstance(Picasso.class);

        setHasStableIds(true);
    }

    /**
     * Replace all the messages with the new messages from the given iterable.
     */
    public void setMessages(Iterable<Message> messages) {
        this.messages.clear();
        Iterables.addAll(this.messages, messages);
        notifyDataSetChanged();
    }

    @Override
    public long getItemId(int position) {
        return messages.get(position).getId();
    }

    @Override
    public MessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.inbox_message, parent, false);
        return new MessageViewHolder(view);
    }

    @SuppressWarnings("CodeBlock2Expr")
    @Override
    public void onBindViewHolder(MessageViewHolder view, int position) {
        Message message = messages.get(position);

        // set the type. if we have an item, we  have a comment
        boolean isComment = message.getItemId() != 0;
        view.type.setText(isComment ? context.getString(R.string.inbox_message_comment) : context.getString(R.string.inbox_message_private));

        // the text of the message
        view.text.setText(message.getMessage());
        Linkify.addLinks(view.text, Linkify.WEB_URLS);

        // draw the image for this post
        if (isComment) {
            view.image.setVisibility(View.VISIBLE);

            String url = "http://thumb.pr0gramm.com/" + message.getThumb();
            picasso.load(url).into(view.image);
        } else {
            view.image.setVisibility(View.GONE);
            picasso.cancelRequest(view.image);
        }

        // sender info
        view.sender.setSenderName(message.getName(), message.getMark());
        view.sender.setPointsVisible(isComment);
        view.sender.setPoints(message.getScore());
        view.sender.setDate(message.getCreated());

        // reset the answer click listener
        view.sender.setAnswerClickedListener(null);

        if (actionListener != null) {
            view.sender.setOnSenderClickedListener(v -> {
                actionListener.onUserClicked(message.getSenderId(), message.getName());
            });

            if (isComment) {
                view.sender.setAnswerClickedListener(v -> {
                    actionListener.onAnswerToCommentClicked(message.getItemId(), message.getId(), message.getName());
                });

{'fraction_non_alphanumeric': 0.1048822213449138, 'fraction_numerical': 0.002368732727990525, 'mean_word_length': 3.114780725500812, 'pattern_counts': {'":': 0, '<': 15, '<?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': '2978269', 'n_tokens_mistral': 2125, 'n_tokens_neox': 2074, 'n_words': 420}