Commit b0e53901 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Adds divider item decorator bounds to dimens.xml (as a value in dp).

parent 45b8b6de
......@@ -103,7 +103,9 @@ class ChatRoomsFragment : Fragment(), ChatRoomsView {
private fun setupRecyclerView() {
activity?.apply {
recycler_view.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
recycler_view.addItemDecoration(DividerItemDecoration(this, 144, 0))
recycler_view.addItemDecoration(DividerItemDecoration(this,
resources.getDimensionPixelSize(R.dimen.divider_item_decorator_bound_start),
resources.getDimensionPixelSize(R.dimen.divider_item_decorator_bound_end)))
recycler_view.itemAnimator = DefaultItemAnimator()
recycler_view.adapter = ChatRoomsAdapter(this) { chatRoom ->
presenter.loadChatRoom(chatRoom)
......
......@@ -14,7 +14,7 @@ import android.support.v7.widget.RecyclerView
class DividerItemDecoration() : RecyclerView.ItemDecoration() {
private lateinit var divider: Drawable
private var boundStart = 0
private var boundRight = 0
private var boundEnd = 0
// Default divider will be used.
constructor(context: Context) : this() {
......@@ -24,15 +24,15 @@ class DividerItemDecoration() : RecyclerView.ItemDecoration() {
styledAttributes.recycle()
}
// Default divider with custom boundaries (start and right) will be used.
constructor(context: Context, boundStart: Int, boundRight: Int) : this() {
// Default divider with custom boundaries (start and end) will be used.
constructor(context: Context, boundStart: Int, boundEnd: Int) : this() {
val attrs = intArrayOf(android.R.attr.listDivider)
val styledAttributes = context.obtainStyledAttributes(attrs)
divider = styledAttributes.getDrawable(0)
styledAttributes.recycle()
this.boundStart = boundStart
this.boundRight = boundRight
this.boundEnd = boundEnd
}
// Custom divider will be used.
......@@ -45,7 +45,7 @@ class DividerItemDecoration() : RecyclerView.ItemDecoration() {
override fun onDraw(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = parent.paddingLeft + boundStart
val right = (parent.width - parent.paddingRight) - boundRight
val right = (parent.width - parent.paddingRight) - boundEnd
val childCount = parent.childCount
for (i in 0 until childCount) {
......
......@@ -9,6 +9,9 @@
<dimen name="fab_elevation">6dp</dimen>
<dimen name="divider_item_decorator_bound_start">72dp</dimen>
<dimen name="divider_item_decorator_bound_end">0dp</dimen>
<dimen name="message_time_text_size">12sp</dimen>
</resources>
\ 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