<commit_before>package com.tristanwiley.chatse.chat.adapters

import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintSet
import android.support.transition.AutoTransition
import android.support.transition.Transition
import android.support.transition.TransitionManager
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.support.v7.graphics.Palette
import android.support.v7.widget.RecyclerView
import android.text.Html
import android.text.util.Linkify
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.squareup.okhttp.FormEncodingBuilder
import com.squareup.okhttp.Request
import com.tristanwiley.chatse.R
import com.tristanwiley.chatse.chat.ChatMessageCallback
import com.tristanwiley.chatse.chat.ChatRoom
import com.tristanwiley.chatse.event.EventList
import com.tristanwiley.chatse.event.presenter.message.MessageEvent
import com.tristanwiley.chatse.extensions.loadUrl
import com.tristanwiley.chatse.network.Client
import com.tristanwiley.chatse.network.ClientManager
import kotlinx.android.synthetic.main.list_item_message.view.*
import me.saket.bettermovementmethod.BetterLinkMovementMethod
import org.jetbrains.anko.defaultSharedPreferences
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.json.JSONObject
import org.jsoup.Jsoup
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet

/**
 * The beautiful adapter that handles all new messages in the chat
 */
class MessageAdapter(
        private val mContext: Context,
        private val events: EventList,
        private val chatFkey: String?,
        val room: ChatRoom?,
        private var messages: ArrayList<MessageEvent> = ArrayList(),
        private val messageCallback: ChatMessageCallback) : RecyclerView.Adapter<MessageAdapter.MessageViewHolder>(), SelectedMessagesListener {

    init {
        setHasStableIds(true)
    }
    
    private val selectedMessages: HashSet<Int> = HashSet()

    override fun selectMessage(mId: Int) {
        selectedMessages.add(mId)
    }

    override fun deselectMessage(mId: Int) {
        selectedMessages.remove(mId)
    }

    override fun isSelected(mId: Int): Boolean = selectedMessages.contains(mId)

    override fun onBindViewHolder(holder: MessageViewHolder, pos: Int) {
        val message = messages[pos]
        holder.bindMessage(message)
    }

    /**
     * Called when we want to update the messages (there's a new message)
     */
    fun update() {
        messages.clear()
        messages.addAll(events.messagePresenter.getEventsList())
        this.notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item_message, parent, false)
        return MessageAdapter.MessageViewHolder(mContext, view, chatFkey, room, messageCallback, this)
    }

    override fun getItemCount() = messages.size

    override fun getItemId(position: Int) = messages[position].id

    /**
     * ViewHolder that handles setting all content in itemView
     */
    class MessageViewHolder(private val mContext: Context,
                            itemView: View, private val chatFkey: String?,
                            val room: ChatRoom?, private val messageCallback: ChatMessageCallback,
                            private val selectionListener: SelectedMessagesListener) : RecyclerView.ViewHolder(itemView) {

        private val root: LinearLayout = itemView.findViewById(R.id.message_root)
        private val rootMessageLayout = itemView.findViewById<ConstraintLayout>(R.id.message_root_container)
        private val timestampFormat = SimpleDateFormat("hh:mm aa", Locale.getDefault())
        private val messageView = itemView.findViewById<TextView>(R.id.message_content)
        private val userNameView = itemView.findViewById<TextView>(R.id.message_user_name)
        private val messageTimestamp = itemView.findViewById<TextView>(R.id.message_timestamp)
        private val editIndicator = itemView.findViewById<ImageView>(R.id.message_edit_indicator)
        private val starIndicator = itemView.findViewById<ImageView>(R.id.message_star_indicator)
        private val starCount = itemView.findViewById<TextView>(R.id.message_star_count)
        private val oneboxImage = itemView.findViewById<ImageView>(R.id.message_image)<commit_msg>Changed how the MessageAdapter unique ID is retrieved<commit_after>package com.tristanwiley.chatse.chat.adapters

import android.content.Context
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintSet
import android.support.transition.AutoTransition
import android.support.transition.Transition
import android.support.transition.TransitionManager
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.support.v7.graphics.Palette
import android.support.v7.widget.RecyclerView
import android.text.Html
import android.text.util.Linkify
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.*
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.SimpleTarget
import com.squareup.okhttp.FormEncodingBuilder
import com.squareup.okhttp.Request
import com.tristanwiley.chatse.R
import com.tristanwiley.chatse.chat.ChatMessageCallback
import com.tristanwiley.chatse.chat.ChatRoom
import com.tristanwiley.chatse.event.EventList
import com.tristanwiley.chatse.event.presenter.message.MessageEvent
import com.tristanwiley.chatse.extensions.loadUrl
import com.tristanwiley.chatse.network.Client
import com.tristanwiley.chatse.network.ClientManager
import kotlinx.android.synthetic.main.list_item_message.view.*
import me.saket.bettermovementmethod.BetterLinkMovementMethod
import org.jetbrains.anko.defaultSharedPreferences
import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import org.json.JSONObject
import org.jsoup.Jsoup
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet

/**
 * The beautiful adapter that handles all new messages in the chat
 */
class MessageAdapter(
        private val mContext: Context,
        private val events: EventList,
        private val chatFkey: String?,
        val room: ChatRoom?,
        private var messages: ArrayList<MessageEvent> = ArrayList(),
        private val messageCallback: ChatMessageCallback) : RecyclerView.Adapter<MessageAdapter.MessageViewHolder>(), SelectedMessagesListener {

    init {
        setHasStableIds(true)
    }
    
    private val selectedMessages: HashSet<Int> = HashSet()

    override fun selectMessage(mId: Int) {
        selectedMessages.add(mId)
    }

    override fun deselectMessage(mId: Int) {
        selectedMessages.remove(mId)
    }

    override fun isSelected(mId: Int): Boolean = selectedMessages.contains(mId)

    override fun onBindViewHolder(holder: MessageViewHolder, pos: Int) {
        val message = messages[pos]
        holder.bindMessage(message)
    }

    /**
     * Called when we want to update the messages (there's a new message)
     */
    fun update() {
        messages.clear()
        messages.addAll(events.messagePresenter.getEventsList())
        this.notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MessageViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.list_item_message, parent, false)
        return MessageAdapter.MessageViewHolder(mContext, view, chatFkey, room, messageCallback, this)
    }

    override fun getItemCount() = messages.size

    override fun getItemId(position: Int) = messages[position].hashCode().toLong()

    /**
     * ViewHolder that handles setting all content in itemView
     */
    class MessageViewHolder(private val mContext: Context,
                            itemView: View, private val chatFkey: String?,
                            val room: ChatRoom?, private val messageCallback: ChatMessageCallback,
                            private val selectionListener: SelectedMessagesListener) : RecyclerView.ViewHolder(itemView) {

        private val root: LinearLayout = itemView.findViewById(R.id.message_root)
        private val rootMessageLayout = itemView.findViewById<ConstraintLayout>(R.id.message_root_container)
        private val timestampFormat = SimpleDateFormat("hh:mm aa", Locale.getDefault())
        private val messageView = itemView.findViewById<TextView>(R.id.message_content)
        private val userNameView = itemView.findViewById<TextView>(R.id.message_user_name)
        private val messageTimestamp = itemView.findViewById<TextView>(R.id.message_timestamp)
        private val editIndicator = itemView.findViewById<ImageView>(R.id.message_edit_indicator)
        private val starIndicator = itemView.findViewById<ImageView>(R.id.message_star_indicator)
        private val starCount = itemView.findViewById<TextView>(R.id.message_star_count)
        private val oneboxImage = itemView.findViewById<ImageView>(R.id.message_image)
{'fraction_non_alphanumeric': 0.08222380323203578, 'fraction_numerical': 0.0008130907612562252, 'mean_word_length': 4.264847512038523, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '5453522', 'n_tokens_mistral': 2705, 'n_tokens_neox': 2624, 'n_words': 576}