<commit_before>package fi.bitrite.android.ws.ui.listadapter;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import fi.bitrite.android.ws.R;
import fi.bitrite.android.ws.model.Message;
import fi.bitrite.android.ws.model.MessageThread;
import fi.bitrite.android.ws.model.User;
import fi.bitrite.android.ws.repository.MessageRepository;
import fi.bitrite.android.ws.repository.Repository;
import fi.bitrite.android.ws.repository.UserRepository;
import fi.bitrite.android.ws.ui.util.NavigationController;
import fi.bitrite.android.ws.ui.widget.UserCircleImageView;
import fi.bitrite.android.ws.util.LoggedInUserHelper;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;

public class MessageThreadListAdapter extends
        DataBoundListAdapter<MessageThread, MessageThreadListAdapter.ItemBinding> {

    private final LoggedInUserHelper mLoggedInUserHelper;
    private final MessageRepository mMessageRepository;
    private final NavigationController mNavigationController;
    private final UserRepository mUserRepository;

    public MessageThreadListAdapter(
            LoggedInUserHelper loggedInUserHelper, MessageRepository messageRepository,
            NavigationController navigationController, UserRepository userRepository) {
        mUserRepository = userRepository;
        mMessageRepository = messageRepository;
        mLoggedInUserHelper = loggedInUserHelper;
        mNavigationController = navigationController;
    }

    @Override
    protected ItemBinding createBinding(ViewGroup parent) {
        return new ItemBinding(parent);
    }

    @Override
    protected void sort(List<MessageThread> threads) {
        Collections.sort(threads, (left, right) -> right.lastUpdated.compareTo(left.lastUpdated));
    }

    @Override
    protected boolean areItemsTheSame(MessageThread left, MessageThread right) {
        return left.id == right.id;
    }

    @Override
    protected boolean areContentsTheSame(MessageThread left, MessageThread right) {
        return left.id == right.id
               && left.subject.equals(right.subject)
               && left.started.equals(right.started)
               && left.isRead() == right.isRead()
               && left.lastUpdated.equals(right.lastUpdated);
    }

    class ItemBinding implements DataBoundListAdapter.ViewDataBinding<MessageThread> {

        @BindView(R.id.thread_icon) UserCircleImageView mIcon;
        @BindView(R.id.thread_lbl_participants) TextView mLblParticipants;
        @BindView(R.id.thread_lbl_last_updated) TextView mLblLastUpdated;
        @BindView(R.id.thread_lbl_subject) TextView mLblSubject;
        @BindView(R.id.thread_lbl_preview) TextView mLblPreview;

        private final View mRoot;
        private MessageThread mThread;
        private CompositeDisposable mDisposables = new CompositeDisposable();

        ItemBinding(ViewGroup parent) {
            mRoot = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_message_thread, parent, false);
            ButterKnife.bind(this, mRoot);

            mRoot.setOnCreateContextMenuListener(this::onCreateContextMenu);
        }

        @Override
        public View getRoot() {
            return mRoot;
        }

        @Override<commit_msg>Fix thread list not being refreshed upon new message<commit_after>package fi.bitrite.android.ws.ui.listadapter;

import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;
import fi.bitrite.android.ws.R;
import fi.bitrite.android.ws.model.Message;
import fi.bitrite.android.ws.model.MessageThread;
import fi.bitrite.android.ws.model.User;
import fi.bitrite.android.ws.repository.MessageRepository;
import fi.bitrite.android.ws.repository.Repository;
import fi.bitrite.android.ws.repository.UserRepository;
import fi.bitrite.android.ws.ui.util.NavigationController;
import fi.bitrite.android.ws.ui.widget.UserCircleImageView;
import fi.bitrite.android.ws.util.LoggedInUserHelper;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;

public class MessageThreadListAdapter extends
        DataBoundListAdapter<MessageThread, MessageThreadListAdapter.ItemBinding> {

    private final LoggedInUserHelper mLoggedInUserHelper;
    private final MessageRepository mMessageRepository;
    private final NavigationController mNavigationController;
    private final UserRepository mUserRepository;

    public MessageThreadListAdapter(
            LoggedInUserHelper loggedInUserHelper, MessageRepository messageRepository,
            NavigationController navigationController, UserRepository userRepository) {
        mUserRepository = userRepository;
        mMessageRepository = messageRepository;
        mLoggedInUserHelper = loggedInUserHelper;
        mNavigationController = navigationController;
    }

    @Override
    protected ItemBinding createBinding(ViewGroup parent) {
        return new ItemBinding(parent);
    }

    @Override
    protected void sort(List<MessageThread> threads) {
        Collections.sort(threads, (left, right) -> right.lastUpdated.compareTo(left.lastUpdated));
    }

    @Override
    protected boolean areItemsTheSame(MessageThread left, MessageThread right) {
        return left.id == right.id;
    }

    @Override
    protected boolean areContentsTheSame(MessageThread left, MessageThread right) {
        return left.id == right.id
               && left.subject.equals(right.subject)
               && left.started.equals(right.started)
               && left.isRead() == right.isRead()
               && left.lastUpdated.equals(right.lastUpdated)
               && left.messages.size() == right.messages.size();
    }

    class ItemBinding implements DataBoundListAdapter.ViewDataBinding<MessageThread> {

        @BindView(R.id.thread_icon) UserCircleImageView mIcon;
        @BindView(R.id.thread_lbl_participants) TextView mLblParticipants;
        @BindView(R.id.thread_lbl_last_updated) TextView mLblLastUpdated;
        @BindView(R.id.thread_lbl_subject) TextView mLblSubject;
        @BindView(R.id.thread_lbl_preview) TextView mLblPreview;

        private final View mRoot;
        private MessageThread mThread;
        private CompositeDisposable mDisposables = new CompositeDisposable();

        ItemBinding(ViewGroup parent) {
            mRoot = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_message_thread, parent, false);
            ButterKnife.bind(this, mRoot);

            mRoot.setOnCreateContextMenuListener(this::onCreateContextMenu);
        }

        @Override
        public View getRoot() {
            return mRoot;
        }

        @Override
{'fraction_non_alphanumeric': 0.08453169938727023, 'fraction_numerical': 0.0, 'mean_word_length': 3.8531553398058254, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '7063288', 'n_tokens_mistral': 2214, 'n_tokens_neox': 2153, 'n_words': 413}