Compare commits
	
		
			2 Commits
		
	
	
		
			v0.3
			...
			b02a6c9aad
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| b02a6c9aad | |||
| 0d331d90ff | 
@@ -5,6 +5,7 @@ import android.view.LayoutInflater
 | 
				
			|||||||
import android.view.View
 | 
					import android.view.View
 | 
				
			||||||
import android.view.ViewGroup
 | 
					import android.view.ViewGroup
 | 
				
			||||||
import android.widget.TextView
 | 
					import android.widget.TextView
 | 
				
			||||||
 | 
					import androidx.core.content.ContextCompat
 | 
				
			||||||
import androidx.recyclerview.widget.RecyclerView
 | 
					import androidx.recyclerview.widget.RecyclerView
 | 
				
			||||||
import it.danieleverducci.lunatracker.entities.LunaEvent
 | 
					import it.danieleverducci.lunatracker.entities.LunaEvent
 | 
				
			||||||
import it.danieleverducci.lunatracker.R
 | 
					import it.danieleverducci.lunatracker.R
 | 
				
			||||||
@@ -16,18 +17,26 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
 | 
				
			|||||||
    val items = ArrayList<LunaEvent>()
 | 
					    val items = ArrayList<LunaEvent>()
 | 
				
			||||||
    val numericUtils: NumericUtils
 | 
					    val numericUtils: NumericUtils
 | 
				
			||||||
    var onItemClickListener: OnItemClickListener? = null
 | 
					    var onItemClickListener: OnItemClickListener? = null
 | 
				
			||||||
 | 
					    val layoutRes: Int
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    constructor(context: Context) {
 | 
					    constructor(context: Context) {
 | 
				
			||||||
        this.context = context
 | 
					        this.context = context
 | 
				
			||||||
        this.numericUtils = NumericUtils(context)
 | 
					        this.numericUtils = NumericUtils(context)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        val fontScale = context.resources.configuration.fontScale
 | 
				
			||||||
 | 
					        val screenSize = context.resources.configuration.screenWidthDp
 | 
				
			||||||
 | 
					        this.layoutRes =
 | 
				
			||||||
 | 
					            if(fontScale > 1.2 || screenSize < 320 || (fontScale > 1 && screenSize < 400))
 | 
				
			||||||
 | 
					                R.layout.row_luna_event_vertical
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					                R.layout.row_luna_event
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreateViewHolder(
 | 
					    override fun onCreateViewHolder(
 | 
				
			||||||
        parent: ViewGroup,
 | 
					        parent: ViewGroup,
 | 
				
			||||||
        viewType: Int
 | 
					        viewType: Int
 | 
				
			||||||
    ): LunaEventVH {
 | 
					    ): LunaEventVH {
 | 
				
			||||||
 | 
					        val view = LayoutInflater.from(context).inflate(layoutRes, parent, false)
 | 
				
			||||||
        val view = LayoutInflater.from(context).inflate(R.layout.row_luna_event, parent, false)
 | 
					 | 
				
			||||||
        return LunaEventVH(view)
 | 
					        return LunaEventVH(view)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -40,6 +49,7 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
 | 
				
			|||||||
        holder.root.setBackgroundResource(
 | 
					        holder.root.setBackgroundResource(
 | 
				
			||||||
            if (position % 2 == 0) R.color.list_background_even else R.color.list_background_odd
 | 
					            if (position % 2 == 0) R.color.list_background_even else R.color.list_background_odd
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.textColor))
 | 
				
			||||||
        // Contents
 | 
					        // Contents
 | 
				
			||||||
        holder.type.text = item.getTypeEmoji(context)
 | 
					        holder.type.text = item.getTypeEmoji(context)
 | 
				
			||||||
        holder.description.text = when(item.type) {
 | 
					        holder.description.text = when(item.type) {
 | 
				
			||||||
@@ -49,7 +59,23 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
 | 
				
			|||||||
            else -> item.getTypeDescription(context)
 | 
					            else -> item.getTypeDescription(context)
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        holder.time.text = DateUtils.formatTimeAgo(context, item.time)
 | 
					        holder.time.text = DateUtils.formatTimeAgo(context, item.time)
 | 
				
			||||||
        holder.quantity.text = numericUtils.formatEventQuantity(item)
 | 
					        var quantityText = numericUtils.formatEventQuantity(item)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // if the event is weight, show difference with the last one
 | 
				
			||||||
 | 
					        if (item.type == LunaEvent.TYPE_WEIGHT) {
 | 
				
			||||||
 | 
					            val lastWeight = getPreviousWeightEvent(position)
 | 
				
			||||||
 | 
					            if (lastWeight != null) {
 | 
				
			||||||
 | 
					                val differenceInWeight = item.quantity - lastWeight.quantity
 | 
				
			||||||
 | 
					                val sign = if (differenceInWeight > 0) "+" else ""
 | 
				
			||||||
 | 
					                quantityText += "\n($sign$differenceInWeight)"
 | 
				
			||||||
 | 
					                if (differenceInWeight < 0) {
 | 
				
			||||||
 | 
					                    holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.danger))
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        holder.quantity.text = quantityText
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Listeners
 | 
					        // Listeners
 | 
				
			||||||
        if (onItemClickListener != null) {
 | 
					        if (onItemClickListener != null) {
 | 
				
			||||||
            holder.root.setOnClickListener({
 | 
					            holder.root.setOnClickListener({
 | 
				
			||||||
@@ -62,6 +88,18 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
 | 
				
			|||||||
        return items.size
 | 
					        return items.size
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private fun getPreviousWeightEvent(startFromPosition: Int): LunaEvent? {
 | 
				
			||||||
 | 
					        if (startFromPosition == items.size - 1)
 | 
				
			||||||
 | 
					            return null
 | 
				
			||||||
 | 
					        for (pos in startFromPosition + 1 until items.size) {
 | 
				
			||||||
 | 
					            val item = items.get(pos)
 | 
				
			||||||
 | 
					            if (item.type != LunaEvent.TYPE_WEIGHT)
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            return item
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return null
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class LunaEventVH: RecyclerView.ViewHolder {
 | 
					    class LunaEventVH: RecyclerView.ViewHolder {
 | 
				
			||||||
        val root: View
 | 
					        val root: View
 | 
				
			||||||
        val type: TextView
 | 
					        val type: TextView
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,7 +6,6 @@
 | 
				
			|||||||
    <LinearLayout
 | 
					    <LinearLayout
 | 
				
			||||||
        android:layout_width="match_parent"
 | 
					        android:layout_width="match_parent"
 | 
				
			||||||
        android:layout_height="match_parent"
 | 
					        android:layout_height="match_parent"
 | 
				
			||||||
        xmlns:app="http://schemas.android.com/apk/res-auto"
 | 
					 | 
				
			||||||
        android:orientation="vertical"
 | 
					        android:orientation="vertical"
 | 
				
			||||||
        android:paddingTop="30dp"
 | 
					        android:paddingTop="30dp"
 | 
				
			||||||
        android:paddingLeft="15dp"
 | 
					        android:paddingLeft="15dp"
 | 
				
			||||||
@@ -16,7 +15,7 @@
 | 
				
			|||||||
            android:layout_width="match_parent"
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
            android:layout_height="wrap_content"
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
            android:text="@string/title"
 | 
					            android:text="@string/title"
 | 
				
			||||||
            android:textSize="30sp"
 | 
					            android:textSize="30dp"
 | 
				
			||||||
            android:gravity="center_horizontal"/>
 | 
					            android:gravity="center_horizontal"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <TextView
 | 
					        <TextView
 | 
				
			||||||
@@ -152,7 +151,7 @@
 | 
				
			|||||||
        <TextView
 | 
					        <TextView
 | 
				
			||||||
            android:layout_width="match_parent"
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
            android:layout_height="wrap_content"
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
            android:text="Diario di bordo"
 | 
					            android:text="@string/logbook"
 | 
				
			||||||
            android:textColor="@color/accent"
 | 
					            android:textColor="@color/accent"
 | 
				
			||||||
            android:textStyle="bold"/>
 | 
					            android:textStyle="bold"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -122,6 +122,9 @@
 | 
				
			|||||||
                    android:layout_width="0dp"
 | 
					                    android:layout_width="0dp"
 | 
				
			||||||
                    android:layout_height="wrap_content"
 | 
					                    android:layout_height="wrap_content"
 | 
				
			||||||
                    android:layout_weight="1"
 | 
					                    android:layout_weight="1"
 | 
				
			||||||
 | 
					                    android:layout_marginRight="20dp"
 | 
				
			||||||
 | 
					                    android:background="@drawable/button_background"
 | 
				
			||||||
 | 
					                    android:textColor="@color/accent"
 | 
				
			||||||
                    android:text="@android:string/cancel"/>
 | 
					                    android:text="@android:string/cancel"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <Button
 | 
					                <Button
 | 
				
			||||||
@@ -130,6 +133,7 @@
 | 
				
			|||||||
                    android:layout_height="wrap_content"
 | 
					                    android:layout_height="wrap_content"
 | 
				
			||||||
                    android:layout_weight="1"
 | 
					                    android:layout_weight="1"
 | 
				
			||||||
                    android:textColor="@color/accent"
 | 
					                    android:textColor="@color/accent"
 | 
				
			||||||
 | 
					                    android:background="@drawable/button_background"
 | 
				
			||||||
                    android:text="@android:string/ok"/>
 | 
					                    android:text="@android:string/ok"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            </LinearLayout>
 | 
					            </LinearLayout>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -24,6 +24,7 @@
 | 
				
			|||||||
        android:layout_weight="2"
 | 
					        android:layout_weight="2"
 | 
				
			||||||
        android:ellipsize="end"
 | 
					        android:ellipsize="end"
 | 
				
			||||||
        android:maxLines="2"
 | 
					        android:maxLines="2"
 | 
				
			||||||
 | 
					        android:textColor="@color/accent"
 | 
				
			||||||
        android:text="Description"/>
 | 
					        android:text="Description"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <TextView
 | 
					    <TextView
 | 
				
			||||||
@@ -34,8 +35,6 @@
 | 
				
			|||||||
        android:layout_marginLeft="5dp"
 | 
					        android:layout_marginLeft="5dp"
 | 
				
			||||||
        android:layout_marginRight="5dp"
 | 
					        android:layout_marginRight="5dp"
 | 
				
			||||||
        android:gravity="center_horizontal"
 | 
					        android:gravity="center_horizontal"
 | 
				
			||||||
        android:lines="1"
 | 
					 | 
				
			||||||
        android:maxLines="1"
 | 
					 | 
				
			||||||
        android:text="Qty"/>
 | 
					        android:text="Qty"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <TextView
 | 
					    <TextView
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										59
									
								
								app/src/main/res/layout/row_luna_event_vertical.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										59
									
								
								app/src/main/res/layout/row_luna_event_vertical.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,59 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="utf-8"?>
 | 
				
			||||||
 | 
					<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
				
			||||||
 | 
					    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="90dp"
 | 
				
			||||||
 | 
					        android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					        android:textSize="28sp"
 | 
				
			||||||
 | 
					        android:lines="1"
 | 
				
			||||||
 | 
					        android:maxLines="1"
 | 
				
			||||||
 | 
					        android:text="@string/event_diaperchange_pee_type"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <LinearLayout
 | 
				
			||||||
 | 
					        android:layout_width="0dp"
 | 
				
			||||||
 | 
					        android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					        android:layout_weight="1"
 | 
				
			||||||
 | 
					        android:orientation="vertical">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <TextView
 | 
				
			||||||
 | 
					            android:id="@+id/description"
 | 
				
			||||||
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:layout_weight="2"
 | 
				
			||||||
 | 
					            android:ellipsize="end"
 | 
				
			||||||
 | 
					            android:maxLines="2"
 | 
				
			||||||
 | 
					            android:gravity="center_horizontal"
 | 
				
			||||||
 | 
					            android:textColor="@color/accent"
 | 
				
			||||||
 | 
					            android:text="Description"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <TextView
 | 
				
			||||||
 | 
					            android:id="@+id/quantity"
 | 
				
			||||||
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:layout_weight="1"
 | 
				
			||||||
 | 
					            android:layout_marginLeft="5dp"
 | 
				
			||||||
 | 
					            android:layout_marginRight="5dp"
 | 
				
			||||||
 | 
					            android:gravity="center_horizontal"
 | 
				
			||||||
 | 
					            android:text="Qty"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <TextView
 | 
				
			||||||
 | 
					            android:id="@+id/time"
 | 
				
			||||||
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:layout_weight="2"
 | 
				
			||||||
 | 
					            android:gravity="center_horizontal"
 | 
				
			||||||
 | 
					            android:textStyle="bold"
 | 
				
			||||||
 | 
					            android:ellipsize="end"
 | 
				
			||||||
 | 
					            android:maxLines="2"
 | 
				
			||||||
 | 
					            android:text="Time"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    </LinearLayout>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					</LinearLayout>
 | 
				
			||||||
@@ -8,4 +8,6 @@
 | 
				
			|||||||
    <color name="grey">#ccc</color>
 | 
					    <color name="grey">#ccc</color>
 | 
				
			||||||
    <color name="list_background_odd">#423B25</color>
 | 
					    <color name="list_background_odd">#423B25</color>
 | 
				
			||||||
    <color name="list_background_even">@color/transparent</color>
 | 
					    <color name="list_background_even">@color/transparent</color>
 | 
				
			||||||
 | 
					    <color name="danger">#f00</color>
 | 
				
			||||||
 | 
					    <color name="textColor">@color/grey</color>
 | 
				
			||||||
</resources>
 | 
					</resources>
 | 
				
			||||||
@@ -3,6 +3,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <style name="Theme.LunaTracker" parent="Theme.AppCompat.NoActionBar">
 | 
					    <style name="Theme.LunaTracker" parent="Theme.AppCompat.NoActionBar">
 | 
				
			||||||
        <item name="colorAccent">@color/accent</item>
 | 
					        <item name="colorAccent">@color/accent</item>
 | 
				
			||||||
 | 
					        <item name="android:textColor">@color/textColor</item>
 | 
				
			||||||
    </style>
 | 
					    </style>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <style name="OverflowMenuText">
 | 
					    <style name="OverflowMenuText">
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user