add a divider between the events

This commit is contained in:
tibbi 2016-11-23 20:13:55 +01:00
parent cb7d83a696
commit 0fb3f20a2b
4 changed files with 41 additions and 3 deletions

View File

@ -21,6 +21,7 @@ import com.simplemobiletools.calendar.helpers.*
import com.simplemobiletools.calendar.helpers.Formatter
import com.simplemobiletools.calendar.interfaces.NavigationListener
import com.simplemobiletools.calendar.models.Event
import com.simplemobiletools.calendar.views.RecyclerViewDivider
import kotlinx.android.synthetic.main.day_fragment.view.*
import kotlinx.android.synthetic.main.top_navigation.view.*
import java.util.*
@ -132,6 +133,7 @@ class DayFragment : Fragment(), DBHelper.EventsListener, AbsListView.MultiChoice
}
mHolder.day_events.apply {
this@apply.adapter = eventsAdapter
addItemDecoration(RecyclerViewDivider(context))
}
}

View File

@ -0,0 +1,33 @@
package com.simplemobiletools.calendar.views
import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import com.simplemobiletools.calendar.R
class RecyclerViewDivider(context: Context) : RecyclerView.ItemDecoration() {
private val mDivider: Drawable
init {
mDivider = context.resources.getDrawable(R.drawable.divider)
}
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
val left = parent.paddingLeft
val right = parent.width - parent.paddingRight
val childCount = parent.childCount
for (i in 0..childCount - 1) {
val child = parent.getChildAt(i)
val params = child.layoutParams as RecyclerView.LayoutParams
val top = child.bottom + params.bottomMargin
val bottom = top + mDivider.intrinsicHeight
mDivider.setBounds(left, top, right, bottom)
mDivider.draw(c)
}
}
}

View File

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="10000dp"
android:width="1dp"
android:height="1dp"/>
<solid android:color="@color/eventListDivider"/>
<solid android:color="@color/divider_grey"/>
</shape>

View File

@ -3,7 +3,8 @@
<color name="colorPrimary">#fff68630</color>
<color name="colorPrimaryDark">#ffe27725</color>
<color name="colorAccent">@color/colorPrimary</color>
<color name="dark_grey_pressed_mask">#11000000</color>
<color name="mediumGrey">#18000000</color>
<color name="eventListDivider">#44aaaaaa</color>
<color name="divider_grey">#44cccccc</color>
</resources>