Measurement units
This commit is contained in:
parent
35a3b42a32
commit
876c68ce81
@ -1,6 +1,8 @@
|
|||||||
package it.danieleverducci.lunatracker.adapters
|
package it.danieleverducci.lunatracker.adapters
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.icu.util.LocaleData
|
||||||
|
import android.icu.util.ULocale
|
||||||
import android.text.format.DateFormat
|
import android.text.format.DateFormat
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
@ -10,13 +12,36 @@ 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
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
|
||||||
class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.LunaEventVH> {
|
class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.LunaEventVH> {
|
||||||
private val context: Context
|
private val context: Context
|
||||||
val items = ArrayList<LunaEvent>()
|
val items = ArrayList<LunaEvent>()
|
||||||
|
val measurement_unit_liquid_base: String
|
||||||
|
val measurement_unit_weight_base: String
|
||||||
|
val measurement_unit_weight_tiny: String
|
||||||
|
|
||||||
constructor(context: Context) {
|
constructor(context: Context) {
|
||||||
this.context = context
|
this.context = context
|
||||||
|
val measurementSystem = LocaleData.getMeasurementSystem(ULocale.getDefault())
|
||||||
|
this.measurement_unit_liquid_base = context.getString(
|
||||||
|
if (measurementSystem == LocaleData. MeasurementSystem.SI)
|
||||||
|
R.string.measurement_unit_liquid_base_metric
|
||||||
|
else
|
||||||
|
R.string.measurement_unit_liquid_base_imperial
|
||||||
|
)
|
||||||
|
this.measurement_unit_weight_base = context.getString(
|
||||||
|
if (measurementSystem == LocaleData. MeasurementSystem.SI)
|
||||||
|
R.string.measurement_unit_weight_base_metric
|
||||||
|
else
|
||||||
|
R.string.measurement_unit_weight_base_imperial
|
||||||
|
)
|
||||||
|
this.measurement_unit_weight_tiny = context.getString(
|
||||||
|
if (measurementSystem == LocaleData. MeasurementSystem.SI)
|
||||||
|
R.string.measurement_unit_weight_tiny_metric
|
||||||
|
else
|
||||||
|
R.string.measurement_unit_weight_tiny_imperial
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateViewHolder(
|
override fun onCreateViewHolder(
|
||||||
@ -35,8 +60,18 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
|||||||
val item = items.get(position)
|
val item = items.get(position)
|
||||||
holder.type.text = item.getTypeEmoji(context)
|
holder.type.text = item.getTypeEmoji(context)
|
||||||
holder.description.text = item.getTypeDescription(context)
|
holder.description.text = item.getTypeDescription(context)
|
||||||
holder.quantity.text = if ((item.quantity ?: 0) > 0) item.quantity.toString() else ""
|
|
||||||
holder.time.text = formatTimeAgo(context, item.time)
|
holder.time.text = formatTimeAgo(context, item.time)
|
||||||
|
val qtyText = if ((item.quantity ?: 0) > 0) {
|
||||||
|
item.quantity.toString() + " " + when (item.type) {
|
||||||
|
LunaEvent.TYPE_BABY_BOTTLE -> measurement_unit_liquid_base
|
||||||
|
LunaEvent.TYPE_WEIGHT -> measurement_unit_weight_base
|
||||||
|
LunaEvent.TYPE_MEDICINE -> measurement_unit_weight_tiny
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
""
|
||||||
|
}
|
||||||
|
holder.quantity.text = qtyText
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int {
|
||||||
@ -68,9 +103,9 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
|||||||
else
|
else
|
||||||
formattedTime.append(context.getString(R.string.hours_ago))
|
formattedTime.append(context.getString(R.string.hours_ago))
|
||||||
}
|
}
|
||||||
if (formattedTime.isNotEmpty())
|
|
||||||
formattedTime.append(", ")
|
|
||||||
if (minutesAgo > 0) {
|
if (minutesAgo > 0) {
|
||||||
|
if (formattedTime.isNotEmpty())
|
||||||
|
formattedTime.append(", ")
|
||||||
formattedTime.append(minutesAgo).append(" ")
|
formattedTime.append(minutesAgo).append(" ")
|
||||||
if (minutesAgo.toInt() == 1)
|
if (minutesAgo.toInt() == 1)
|
||||||
formattedTime.append(context.getString(R.string.minute_ago))
|
formattedTime.append(context.getString(R.string.minute_ago))
|
||||||
|
@ -10,17 +10,6 @@
|
|||||||
<string name="log_weight_dialog_title">Pesata</string>
|
<string name="log_weight_dialog_title">Pesata</string>
|
||||||
<string name="log_weight_dialog_description">Inserisci il peso rilevato</string>
|
<string name="log_weight_dialog_description">Inserisci il peso rilevato</string>
|
||||||
|
|
||||||
<string name="event_bottle_type">🍼</string>
|
|
||||||
<string name="event_scale_type">⚖️</string>
|
|
||||||
<string name="event_breastfeeding_left_type">🤱 ←</string>
|
|
||||||
<string name="event_breastfeeding_both_type">🤱 ↔</string>
|
|
||||||
<string name="event_breastfeeding_right_type">🤱 →</string>
|
|
||||||
<string name="event_diaperchange_poo_type">🚼 💩</string>
|
|
||||||
<string name="event_diaperchange_pee_type">🚼 💧</string>
|
|
||||||
<string name="event_medicine_type">💊</string>
|
|
||||||
<string name="event_enema_type">🪠</string>
|
|
||||||
<string name="event_unknown_type">-</string>
|
|
||||||
|
|
||||||
<string name="overflow_event_medicine">💊 Medicina</string>
|
<string name="overflow_event_medicine">💊 Medicina</string>
|
||||||
<string name="overflow_event_enema">🪠 Clistere</string>
|
<string name="overflow_event_enema">🪠 Clistere</string>
|
||||||
<string name="overflow_event_custom">➕ Aggiungi evento personalizzato</string>
|
<string name="overflow_event_custom">➕ Aggiungi evento personalizzato</string>
|
||||||
|
@ -10,16 +10,16 @@
|
|||||||
<string name="log_weight_dialog_title">Weight</string>
|
<string name="log_weight_dialog_title">Weight</string>
|
||||||
<string name="log_weight_dialog_description">Insert the weight</string>
|
<string name="log_weight_dialog_description">Insert the weight</string>
|
||||||
|
|
||||||
<string name="event_bottle_type">🍼</string>
|
<string name="event_bottle_type" translatable="false">🍼</string>
|
||||||
<string name="event_scale_type">⚖️</string>
|
<string name="event_scale_type" translatable="false">⚖️</string>
|
||||||
<string name="event_breastfeeding_left_type">🤱 ←</string>
|
<string name="event_breastfeeding_left_type" translatable="false">🤱 ←</string>
|
||||||
<string name="event_breastfeeding_both_type">🤱 ↔</string>
|
<string name="event_breastfeeding_both_type" translatable="false">🤱 ↔</string>
|
||||||
<string name="event_breastfeeding_right_type">🤱 →</string>
|
<string name="event_breastfeeding_right_type" translatable="false">🤱 →</string>
|
||||||
<string name="event_diaperchange_poo_type">🚼 💩</string>
|
<string name="event_diaperchange_poo_type" translatable="false">🚼 💩</string>
|
||||||
<string name="event_diaperchange_pee_type">🚼 💧</string>
|
<string name="event_diaperchange_pee_type" translatable="false">🚼 💧</string>
|
||||||
<string name="event_medicine_type">💊</string>
|
<string name="event_medicine_type" translatable="false">💊</string>
|
||||||
<string name="event_enema_type">🪠</string>
|
<string name="event_enema_type" translatable="false">🪠</string>
|
||||||
<string name="event_unknown_type">\?</string>
|
<string name="event_unknown_type" translatable="false">\?</string>
|
||||||
|
|
||||||
<string name="event_bottle_desc">Baby bottle</string>
|
<string name="event_bottle_desc">Baby bottle</string>
|
||||||
<string name="event_scale_desc">Weight</string>
|
<string name="event_scale_desc">Weight</string>
|
||||||
@ -80,4 +80,11 @@
|
|||||||
<string name="log_medicine_dialog_description">Medicine name, quantity, type, notes…:</string>
|
<string name="log_medicine_dialog_description">Medicine name, quantity, type, notes…:</string>
|
||||||
<string name="log_notes_dialog_qty_hint">Integer quantity, or leave blank</string>
|
<string name="log_notes_dialog_qty_hint">Integer quantity, or leave blank</string>
|
||||||
|
|
||||||
|
<string name="measurement_unit_liquid_base_metric" translatable="false">ml</string>
|
||||||
|
<string name="measurement_unit_weight_base_metric" translatable="false">g</string>
|
||||||
|
<string name="measurement_unit_weight_tiny_metric" translatable="false">mg</string>
|
||||||
|
<string name="measurement_unit_liquid_base_imperial" translatable="false">fl oz.</string>
|
||||||
|
<string name="measurement_unit_weight_base_imperial" translatable="false">oz</string>
|
||||||
|
<string name="measurement_unit_weight_tiny_imperial" translatable="false">gr</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user