5 Commits

10 changed files with 132 additions and 15 deletions

View File

@ -30,7 +30,6 @@ import it.danieleverducci.lunatracker.repository.WebDAVLogbookRepository
import kotlinx.coroutines.Runnable
import okio.IOException
import org.json.JSONException
import utils.DateUtils
import utils.NumericUtils
import java.text.DateFormat
import java.util.Date
@ -39,6 +38,7 @@ class MainActivity : AppCompatActivity() {
companion object {
val TAG = "MainActivity"
val UPDATE_EVERY_SECS: Long = 30
val DEBUG_CHECK_LOGBOOK_CONSISTENCY = false
}
lateinit var logbook: Logbook
@ -53,6 +53,7 @@ class MainActivity : AppCompatActivity() {
handler.postDelayed(updateListRunnable, 1000*60)
}
var logbookRepo: LogbookRepository? = null
var showingOverflowPopupWindow = false
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@ -295,6 +296,15 @@ class MainActivity : AppCompatActivity() {
findViewById<View>(R.id.no_connection_screen).visibility = View.GONE
logbook = lb
showLogbook()
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
for (e in logbook.logs) {
val em = e.getTypeEmoji(this@MainActivity)
if (em == getString(R.string.event_unknown_type)) {
Log.e(TAG, "UNKNOWN: ${e.type}")
}
}
}
})
}
@ -457,6 +467,9 @@ class MainActivity : AppCompatActivity() {
}
private fun showOverflowPopupWindow(anchor: View) {
if (showingOverflowPopupWindow)
return
PopupWindow(anchor.context).apply {
isOutsideTouchable = true
val inflater = LayoutInflater.from(anchor.context)
@ -478,7 +491,13 @@ class MainActivity : AppCompatActivity() {
dismiss()
})
}.also { popupWindow ->
popupWindow.setOnDismissListener({
Handler(mainLooper).postDelayed({
showingOverflowPopupWindow = false
}, 500)
})
popupWindow.showAsDropDown(anchor)
showingOverflowPopupWindow = true
}
}
}

View File

@ -5,6 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import it.danieleverducci.lunatracker.entities.LunaEvent
import it.danieleverducci.lunatracker.R
@ -16,18 +17,26 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
val items = ArrayList<LunaEvent>()
val numericUtils: NumericUtils
var onItemClickListener: OnItemClickListener? = null
val layoutRes: Int
constructor(context: Context) {
this.context = 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(
parent: ViewGroup,
viewType: Int
): LunaEventVH {
val view = LayoutInflater.from(context).inflate(R.layout.row_luna_event, parent, false)
val view = LayoutInflater.from(context).inflate(layoutRes, parent, false)
return LunaEventVH(view)
}
@ -40,6 +49,7 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
holder.root.setBackgroundResource(
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
holder.type.text = item.getTypeEmoji(context)
holder.description.text = when(item.type) {
@ -49,7 +59,23 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
else -> item.getTypeDescription(context)
}
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
if (onItemClickListener != null) {
holder.root.setOnClickListener({
@ -62,6 +88,18 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
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 {
val root: View
val type: TextView

View File

@ -6,7 +6,6 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:paddingTop="30dp"
android:paddingLeft="15dp"
@ -16,7 +15,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textSize="30sp"
android:textSize="30dp"
android:gravity="center_horizontal"/>
<TextView
@ -152,7 +151,7 @@
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Diario di bordo"
android:text="@string/logbook"
android:textColor="@color/accent"
android:textStyle="bold"/>

View File

@ -122,6 +122,9 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginRight="20dp"
android:background="@drawable/button_background"
android:textColor="@color/accent"
android:text="@android:string/cancel"/>
<Button
@ -130,6 +133,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColor="@color/accent"
android:background="@drawable/button_background"
android:text="@android:string/ok"/>
</LinearLayout>

View File

@ -24,6 +24,7 @@
android:layout_weight="2"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/accent"
android:text="Description"/>
<TextView
@ -34,8 +35,6 @@
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_horizontal"
android:lines="1"
android:maxLines="1"
android:text="Qty"/>
<TextView
@ -49,4 +48,4 @@
android:maxLines="2"
android:text="Time"/>
</LinearLayout>
</LinearLayout>

View 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>

View File

@ -8,4 +8,6 @@
<color name="grey">#ccc</color>
<color name="list_background_odd">#423B25</color>
<color name="list_background_even">@color/transparent</color>
<color name="danger">#f00</color>
<color name="textColor">@color/grey</color>
</resources>

View File

@ -3,6 +3,7 @@
<style name="Theme.LunaTracker" parent="Theme.AppCompat.NoActionBar">
<item name="colorAccent">@color/accent</item>
<item name="android:textColor">@color/textColor</item>
</style>
<style name="OverflowMenuText">

View File

@ -1,5 +1,3 @@
LunaTracker is a newborn baby tracking app.
Parenting can be tough. You get home from the hospital, exhausted, with this little fragile unknown thingy that has no user manual and a single way to let you know something's not ok: crying.
You have to react fast, event if it's 4 AM and you have no idea why is crying.
@ -10,4 +8,4 @@ Dedicated to my daughter Luna.
NOTE: the content on this app is for informational or educational purposes only and does not substitute professional medical advice or consultations with healthcare professionals.
Feature graphic ("Baby and baby milk bottle. Baby feeding."): © Vyacheslav Argenberg / http://www.vascoplanet.com/, CC BY 4.0 <https://creativecommons.org/licenses/by/4.0>, via Wikimedia Commons
Feature graphic ("Baby and baby milk bottle. Baby feeding."): © Vyacheslav Argenberg / http://www.vascoplanet.com/, CC BY 4.0 <https://creativecommons.org/licenses/by/4.0>, via Wikimedia Commons

View File

@ -1,5 +1,3 @@
LunaTracker è un'app di tracciamento neonatale
Essere genitori può essere dura. Arrivate a casa dall'ospedale, esausti, con questo cosino fragile e sconosciuto che non ha un manuale d'uso, e ha un solo modo per segnalare che c'è qualcosa che non va: piangere.
Dovete essere sempre pronti a reagire, anche se sono le 4 di mattina e non avete idea del perché stia piangendo.