Commit 65ed323a authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Remove CustomDividerItemDecoration class inside ChatRoomsFragment file.

parent ffa4c33d
package chat.rocket.android.chatrooms.ui 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.os.Bundle
import android.support.v4.app.Fragment import android.support.v4.app.Fragment
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
...@@ -14,6 +10,7 @@ import android.widget.Toast ...@@ -14,6 +10,7 @@ import android.widget.Toast
import chat.rocket.android.R import chat.rocket.android.R
import chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter import chat.rocket.android.chatrooms.presentation.ChatRoomsPresenter
import chat.rocket.android.chatrooms.presentation.ChatRoomsView import chat.rocket.android.chatrooms.presentation.ChatRoomsView
import chat.rocket.android.widget.DividerItemDecoration
import chat.rocket.core.model.ChatRoom import chat.rocket.core.model.ChatRoom
import dagger.android.support.AndroidSupportInjection import dagger.android.support.AndroidSupportInjection
import kotlinx.android.synthetic.main.fragment_chat_rooms.* import kotlinx.android.synthetic.main.fragment_chat_rooms.*
...@@ -41,7 +38,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -41,7 +38,7 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun showChatRooms(dataSet: MutableList<ChatRoom>) { override fun showChatRooms(dataSet: MutableList<ChatRoom>) {
activity?.apply { activity?.apply {
recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false) recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recycler_view.addItemDecoration(CustomDividerItemDecoration(this, 144, 32)) recycler_view.addItemDecoration(DividerItemDecoration(this, 144, 32))
recycler_view.adapter = ChatRoomsAdapter(dataSet, this) recycler_view.adapter = ChatRoomsAdapter(dataSet, this)
} }
} }
...@@ -51,33 +48,4 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView { ...@@ -51,33 +48,4 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
override fun hideLoading() = view_loading.hide() override fun hideLoading() = view_loading.hide()
override fun showMessage(message: String) = Toast.makeText(activity, message, Toast.LENGTH_SHORT).show() 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)
}
}
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment