<commit_before>package chat.rocket.android.chatrooms.ui

import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.DividerItemDecoration
import android.support.v7.widget.LinearLayoutManager
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter
import chat.rocket.android.chatrooms.presentation.ChatRoomsView
import chat.rocket.core.model.ChatRoom
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_chat_rooms.*
import javax.inject.Inject

class ChatRoomsFragment : Fragment(), ChatRoomsView {
    @Inject lateinit var presenter: ChatRoomsPresenter

    companion object {
        fun newInstance() = ChatRoomsFragment()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        AndroidSupportInjection.inject(this)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_chat_rooms, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        presenter.getChatRooms()
    }

//    // This is just a sample showing 8 chat rooms (aka user subscription). We need to get it rid in a real word. REMARK: remove this comment and this method.
//    private fun createDumpData(): List<Chat> {
//        val filipe = User("1", "<NAME>", "filipe.brito", "online", "https://open.rocket.chat/avatar/filipe.brito")
//        val lucio = User("2", "<NAME>", "<NAME>", "busy", "https://open.rocket.chat/avatar/lucio.maciel")
//        val leonardo = User("3", "<NAME>", "leonardo.aramaki", "busy", "https://open.rocket.chat/avatar/leonardo.aramaki")
//        val sing = User("4", "<NAME>", "filipe.brito", "online", "https://open.rocket.chat/avatar/filipe.brito")
//        val hetal = User("5", "<NAME>", "filipe.brito", "online", "https://open.rocket.chat/avatar/filipe.brito")
//        val matheus = User("6", "<NAME>", "filipe.brito", "online", "https://open.rocket.chat/avatar/filipe.brito")
//        val bestrun = User("7", "<NAME>", "filipe.brito", "online", "https://open.rocket.chat/avatar/filipe.brito")
//        val djc = User("8", "3djc", "3djc", "online", "https://open.rocket.chat/avatar/filipe.brito")
//
//        val dumpChat1 = Chat(leonardo, "<NAME>", "d", "Type something", LocalDateTime.of(2017, 11, 21, 1, 3), 1)
//        val dumpChat2 = Chat(filipe, "<NAME>", "d", "Type something...Type something...Type something", LocalDateTime.of(2017, 11, 22, 1, 3), 150)
//        val dumpChat3 = Chat(lucio, "<NAME>", "d", "Type something", LocalDateTime.of(2017, 11, 17, 1, 3), 0)
//        val dumpChat4 = Chat(sing, "mobile-internal", "p", "@aaron.ogle @rafael.kellermann same problem over here. Although all the servers show up on the selection.", LocalDateTime.of(2017, 11, 15, 1, 3), 0)
//        val dumpChat5 = Chat(hetal, "general", "c", "Has joined the channel.", LocalDateTime.of(2017, 11, 13, 1, 3), 0)
//        val dumpChat6 = Chat(matheus, "androidnativeapp", "c", "Yes @sttyru, but you'll need to implement from the ground up following the docs at docs.rocket.chat where you can see the REST (HTTP) and Real-Time (WebSockets) calls.", LocalDateTime.of(2017, 11, 14, 1, 3), 0)
//        val dumpChat7 = Chat(bestrun, "androidnativeapp-2", "c", "Just downloaded .zip and imported into Android Studio then build the project.", LocalDateTime.of(2017, 11, 4, 12, 47), 0)
//        val dumpChat8 = Chat(djc, "iosnativeapp", "c", "Ok, got confused by the blog announcement that shows a screenshot with github oAuth ! Sorry !", LocalDateTime.of(2017, 11, 4, 12, 43), 0)
//
//        // creates a list of chat sorted by lastMessageDateTime attribute.
//        return listOf(dumpChat1, dumpChat2, dumpChat3, dumpChat4, dumpChat5, dumpChat6, dumpChat7, dumpChat8).sortedByDescending { chat -> chat.lastMessageDateTime }
//    }

    // REMARK: The presenter should call this method. The presenter also need to sort the chat list by latest message (compared by its date).
//    private fun showChatList(dataSet: List<Chat>) {
//        activity?.apply {
//            recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
//            recycler_view.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
//            recycler_view.adapter = ChatRoomsAdapter(dataSet.toMutableList(), this)
//        }
//    }

    override fun showChatRooms(dataSet: MutableList<ChatRoom>) {
        activity?.apply {
            recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
            recycler_view.addItemDecoration(DividerItemDecoration(this, DividerItemDecoration.VERTICAL))
            recycler_view.adapter = ChatRoomsAdapter(dataSet, this)
        }
    }

    override fun showLoading() {
        view_loading.show()
    }

    override fun hideLoading() {
        view_loading.hide()
    }

    override fun showMessage(message: String) {
        Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
    }
}<commit_msg>Add CustomDividerItemDecoration.kt and remove unused codes.<commit_after>package chat.rocket.android.chatrooms.ui

import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import chat.rocket.android.R
import chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter
import chat.rocket.android.chatrooms.presentation.ChatRoomsView
import chat.rocket.core.model.ChatRoom
import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_chat_rooms.*
import javax.inject.Inject

class ChatRoomsFragment : Fragment(), ChatRoomsView {
    @Inject lateinit var presenter: ChatRoomsPresenter

    companion object {
        fun newInstance() = ChatRoomsFragment()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        AndroidSupportInjection.inject(this)
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.fragment_chat_rooms, container, false)

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        presenter.chatRooms()
    }

    override fun showChatRooms(dataSet: MutableList<ChatRoom>) {
        activity?.apply {
            recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
            recycler_view.addItemDecoration(CustomDividerItemDecoration(this, 144, 32))
            recycler_view.adapter = ChatRoomsAdapter(dataSet, this)
        }
    }

    override fun showLoading() = view_loading.show()

    override fun hideLoading() = view_loading.hide()

    override fun showMessage(message: String) = Toast.makeText(activity, message, Toast.LENGTH_SHORT).show()
}

class CustomDividerItemDecoration(context: Context, private var boundStart: Int = 0, private var boundRight: Int = 0) : RecyclerView.ItemDecoration() {
    private val attrs = intArrayOf(android.R.attr.listDivider)
    private var divider: Drawable

    init {
        val styledAttributes = context.obtainStyledAttributes(attrs)
        divider = styledAttributes.getDrawable(0)
        styledAttributes.recycle()
    }

    override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
        val left = parent.paddingLeft + boundStart
        val right = (parent.width - parent.paddingRight) - boundRight

        val childCount = parent.childCount
        for (i in 0 until childCount) {
            val child = parent.getChildAt(i)

            val params = child.layoutParams as RecyclerView.LayoutParams

            val top = child.bottom + params.bottomMargin
            val bottom = top + divider.intrinsicHeight

            divider.setBounds(left, top, right, bottom)
            divider.draw(c)
        }
    }
}
{'fraction_non_alphanumeric': 0.11770233760131564, 'fraction_numerical': 0.015858099377422764, 'mean_word_length': 3.769747899159664, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6542495', 'n_tokens_mistral': 2652, 'n_tokens_neox': 2493, 'n_words': 607}