forked from penguin86/luna-tracker
		
	Alternate colorized rows in list
This commit is contained in:
		@@ -12,7 +12,6 @@ import androidx.recyclerview.widget.RecyclerView
 | 
			
		||||
import it.danieleverducci.lunatracker.entities.LunaEvent
 | 
			
		||||
import it.danieleverducci.lunatracker.R
 | 
			
		||||
import java.util.Date
 | 
			
		||||
import java.util.Locale
 | 
			
		||||
 | 
			
		||||
class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.LunaEventVH> {
 | 
			
		||||
    private val context: Context
 | 
			
		||||
@@ -58,6 +57,9 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
 | 
			
		||||
        position: Int
 | 
			
		||||
    ) {
 | 
			
		||||
        val item = items.get(position)
 | 
			
		||||
        holder.root.setBackgroundResource(
 | 
			
		||||
            if (position % 2 == 0) R.color.list_background_even else R.color.list_background_odd
 | 
			
		||||
        )
 | 
			
		||||
        holder.type.text = item.getTypeEmoji(context)
 | 
			
		||||
        holder.description.text = when(item.type) {
 | 
			
		||||
            LunaEvent.TYPE_MEDICINE -> item.notes
 | 
			
		||||
@@ -121,12 +123,14 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    class LunaEventVH: RecyclerView.ViewHolder {
 | 
			
		||||
        val root: View
 | 
			
		||||
        val type: TextView
 | 
			
		||||
        val description: TextView
 | 
			
		||||
        val quantity: TextView
 | 
			
		||||
        val time: TextView
 | 
			
		||||
 | 
			
		||||
        constructor(v: View) : super(v) {
 | 
			
		||||
            root = v
 | 
			
		||||
            type = v.findViewById<TextView>(R.id.type)
 | 
			
		||||
            description = v.findViewById<TextView>(R.id.description)
 | 
			
		||||
            quantity = v.findViewById<TextView>(R.id.quantity)
 | 
			
		||||
 
 | 
			
		||||
@@ -3,12 +3,15 @@
 | 
			
		||||
    android:orientation="horizontal"
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="wrap_content"
 | 
			
		||||
    android:paddingTop="10dp"
 | 
			
		||||
    android:paddingBottom="10dp"
 | 
			
		||||
    android:gravity="center_vertical">
 | 
			
		||||
 | 
			
		||||
    <TextView
 | 
			
		||||
        android:id="@+id/type"
 | 
			
		||||
        android:layout_width="80dp"
 | 
			
		||||
        android:layout_width="90dp"
 | 
			
		||||
        android:layout_height="wrap_content"
 | 
			
		||||
        android:paddingLeft="10dp"
 | 
			
		||||
        android:textSize="28sp"
 | 
			
		||||
        android:lines="1"
 | 
			
		||||
        android:maxLines="1"
 | 
			
		||||
 
 | 
			
		||||
@@ -6,4 +6,6 @@
 | 
			
		||||
    <color name="translucent">#c000</color>
 | 
			
		||||
    <color name="transparent">#0000</color>
 | 
			
		||||
    <color name="grey">#ccc</color>
 | 
			
		||||
    <color name="list_background_odd">#423B25</color>
 | 
			
		||||
    <color name="list_background_even">@color/transparent</color>
 | 
			
		||||
</resources>
 | 
			
		||||
		Reference in New Issue
	
	Block a user