Added Temperature and Gaseous colic events, removed custom event stub
This commit is contained in:
parent
48017f70f6
commit
b1e26f8a96
@ -17,6 +17,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
|
import com.google.android.material.slider.Slider
|
||||||
import com.thegrizzlylabs.sardineandroid.impl.SardineException
|
import com.thegrizzlylabs.sardineandroid.impl.SardineException
|
||||||
import it.danieleverducci.lunatracker.adapters.LunaEventRecyclerAdapter
|
import it.danieleverducci.lunatracker.adapters.LunaEventRecyclerAdapter
|
||||||
import it.danieleverducci.lunatracker.entities.Logbook
|
import it.danieleverducci.lunatracker.entities.Logbook
|
||||||
@ -207,6 +208,30 @@ class MainActivity : AppCompatActivity() {
|
|||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun askTemperatureValue() {
|
||||||
|
// Show number picker dialog
|
||||||
|
val d = AlertDialog.Builder(this)
|
||||||
|
val dialogView = layoutInflater.inflate(R.layout.temperature_dialog, null)
|
||||||
|
d.setTitle(R.string.log_temperature_dialog_title)
|
||||||
|
d.setMessage(R.string.log_temperature_dialog_description)
|
||||||
|
d.setView(dialogView)
|
||||||
|
val tempSlider = dialogView.findViewById<Slider>(R.id.dialog_temperature_value)
|
||||||
|
val range = NumericUtils(this).getValidEventQuantityRange(LunaEvent.TYPE_TEMPERATURE)!!
|
||||||
|
tempSlider.valueFrom = range.first.toFloat()
|
||||||
|
tempSlider.valueTo = range.second.toFloat()
|
||||||
|
tempSlider.value = range.third.toFloat()
|
||||||
|
val tempTextView = dialogView.findViewById<TextView>(R.id.dialog_temperature_display)
|
||||||
|
tempTextView.text = range.third.toString()
|
||||||
|
tempSlider.addOnChangeListener({s, v, b -> tempTextView.text = v.toString()})
|
||||||
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
|
val temperature = (tempSlider.value * 10).toInt() // In tenth of a grade
|
||||||
|
logEvent(LunaEvent(LunaEvent.TYPE_TEMPERATURE, temperature))
|
||||||
|
}
|
||||||
|
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i -> dialogInterface.dismiss() }
|
||||||
|
val alertDialog = d.create()
|
||||||
|
alertDialog.show()
|
||||||
|
}
|
||||||
|
|
||||||
fun askNotes(lunaEvent: LunaEvent) {
|
fun askNotes(lunaEvent: LunaEvent) {
|
||||||
val d = AlertDialog.Builder(this)
|
val d = AlertDialog.Builder(this)
|
||||||
val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null)
|
val dialogView = layoutInflater.inflate(R.layout.dialog_notes, null)
|
||||||
@ -486,8 +511,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
askNotes(LunaEvent(LunaEvent.TYPE_NOTE))
|
askNotes(LunaEvent(LunaEvent.TYPE_NOTE))
|
||||||
dismiss()
|
dismiss()
|
||||||
})
|
})
|
||||||
contentView.findViewById<View>(R.id.button_custom).setOnClickListener({
|
contentView.findViewById<View>(R.id.button_temperature).setOnClickListener({
|
||||||
Toast.makeText(anchor.context, "TODO: Implement custom events", Toast.LENGTH_SHORT).show()
|
askTemperatureValue()
|
||||||
|
dismiss()
|
||||||
|
})
|
||||||
|
contentView.findViewById<View>(R.id.button_colic).setOnClickListener({
|
||||||
|
logEvent(
|
||||||
|
LunaEvent(LunaEvent.TYPE_COLIC)
|
||||||
|
)
|
||||||
dismiss()
|
dismiss()
|
||||||
})
|
})
|
||||||
}.also { popupWindow ->
|
}.also { popupWindow ->
|
||||||
|
@ -25,6 +25,8 @@ class LunaEvent {
|
|||||||
val TYPE_ENEMA = "ENEMA"
|
val TYPE_ENEMA = "ENEMA"
|
||||||
val TYPE_NOTE = "NOTE"
|
val TYPE_NOTE = "NOTE"
|
||||||
val TYPE_CUSTOM = "CUSTOM"
|
val TYPE_CUSTOM = "CUSTOM"
|
||||||
|
val TYPE_COLIC = "COLIC"
|
||||||
|
val TYPE_TEMPERATURE = "TEMPERATURE"
|
||||||
}
|
}
|
||||||
|
|
||||||
private val jo: JSONObject
|
private val jo: JSONObject
|
||||||
@ -84,6 +86,8 @@ class LunaEvent {
|
|||||||
TYPE_MEDICINE -> R.string.event_medicine_type
|
TYPE_MEDICINE -> R.string.event_medicine_type
|
||||||
TYPE_ENEMA -> R.string.event_enema_type
|
TYPE_ENEMA -> R.string.event_enema_type
|
||||||
TYPE_NOTE -> R.string.event_note_type
|
TYPE_NOTE -> R.string.event_note_type
|
||||||
|
TYPE_TEMPERATURE -> R.string.event_temperature_type
|
||||||
|
TYPE_COLIC -> R.string.event_colic_type
|
||||||
else -> R.string.event_unknown_type
|
else -> R.string.event_unknown_type
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -102,6 +106,8 @@ class LunaEvent {
|
|||||||
TYPE_MEDICINE -> R.string.event_medicine_desc
|
TYPE_MEDICINE -> R.string.event_medicine_desc
|
||||||
TYPE_ENEMA -> R.string.event_enema_desc
|
TYPE_ENEMA -> R.string.event_enema_desc
|
||||||
TYPE_NOTE -> R.string.event_note_desc
|
TYPE_NOTE -> R.string.event_note_desc
|
||||||
|
TYPE_TEMPERATURE -> R.string.event_temperature_desc
|
||||||
|
TYPE_COLIC -> R.string.event_colic_desc
|
||||||
else -> R.string.event_unknown_desc
|
else -> R.string.event_unknown_desc
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -12,6 +12,7 @@ class NumericUtils (val context: Context) {
|
|||||||
val measurement_unit_liquid_base: String
|
val measurement_unit_liquid_base: String
|
||||||
val measurement_unit_weight_base: String
|
val measurement_unit_weight_base: String
|
||||||
val measurement_unit_weight_tiny: String
|
val measurement_unit_weight_tiny: String
|
||||||
|
val measurement_unit_temperature_base: String
|
||||||
|
|
||||||
init {
|
init {
|
||||||
this.numberFormat = NumberFormat.getInstance()
|
this.numberFormat = NumberFormat.getInstance()
|
||||||
@ -34,18 +35,58 @@ class NumericUtils (val context: Context) {
|
|||||||
else
|
else
|
||||||
R.string.measurement_unit_weight_tiny_imperial
|
R.string.measurement_unit_weight_tiny_imperial
|
||||||
)
|
)
|
||||||
|
this.measurement_unit_temperature_base = context.getString(
|
||||||
|
if (measurementSystem == LocaleData. MeasurementSystem.SI)
|
||||||
|
R.string.measurement_unit_temperature_base_metric
|
||||||
|
else
|
||||||
|
R.string.measurement_unit_temperature_base_imperial
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun formatEventQuantity(item: LunaEvent): String {
|
fun formatEventQuantity(item: LunaEvent): String {
|
||||||
return if ((item.quantity ?: 0) > 0) {
|
val formatted = StringBuilder()
|
||||||
numberFormat.format(item.quantity) + " " + when (item.type) {
|
if ((item.quantity ?: 0) > 0) {
|
||||||
LunaEvent.TYPE_BABY_BOTTLE -> measurement_unit_liquid_base
|
if (item.type == LunaEvent.TYPE_TEMPERATURE)
|
||||||
LunaEvent.TYPE_WEIGHT -> measurement_unit_weight_base
|
formatted.append((item.quantity / 10.0f).toString())
|
||||||
LunaEvent.TYPE_MEDICINE -> measurement_unit_weight_tiny
|
else
|
||||||
else -> ""
|
formatted.append(item.quantity)
|
||||||
|
|
||||||
|
formatted.append(" ")
|
||||||
|
formatted.append(
|
||||||
|
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
|
||||||
|
LunaEvent.TYPE_TEMPERATURE -> measurement_unit_temperature_base
|
||||||
|
else -> ""
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return formatted.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a valid quantity range for the event type.
|
||||||
|
* @return min, max, normal
|
||||||
|
*/
|
||||||
|
fun getValidEventQuantityRange(lunaEventType: String): Triple<Int, Int, Int>? {
|
||||||
|
val measurementSystem = LocaleData.getMeasurementSystem(ULocale.getDefault())
|
||||||
|
return when (lunaEventType) {
|
||||||
|
LunaEvent.TYPE_TEMPERATURE -> {
|
||||||
|
if (measurementSystem == LocaleData. MeasurementSystem.SI)
|
||||||
|
Triple(
|
||||||
|
context.resources.getInteger(R.integer.human_body_temp_min_metric),
|
||||||
|
context.resources.getInteger(R.integer.human_body_temp_max_metric),
|
||||||
|
context.resources.getInteger(R.integer.human_body_temp_normal_metric)
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Triple(
|
||||||
|
context.resources.getInteger(R.integer.human_body_temp_min_imperial),
|
||||||
|
context.resources.getInteger(R.integer.human_body_temp_max_imperial),
|
||||||
|
context.resources.getInteger(R.integer.human_body_temp_normal_imperial)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
} else {
|
else -> null
|
||||||
""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -39,23 +39,25 @@
|
|||||||
style="@style/OverflowMenuText"
|
style="@style/OverflowMenuText"
|
||||||
android:text="@string/overflow_event_note"/>
|
android:text="@string/overflow_event_note"/>
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/overflow_event_custom_container"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/button_custom"
|
android:id="@+id/button_temperature"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="10dp"
|
||||||
android:padding="20dp"
|
android:padding="20dp"
|
||||||
android:background="@drawable/button_background"
|
android:background="@drawable/button_background"
|
||||||
style="@style/OverflowMenuText"
|
style="@style/OverflowMenuText"
|
||||||
android:text="@string/overflow_event_custom"/>
|
android:text="@string/overflow_event_temperature"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/button_colic"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_marginTop="10dp"
|
||||||
|
android:padding="20dp"
|
||||||
|
android:background="@drawable/button_background"
|
||||||
|
style="@style/OverflowMenuText"
|
||||||
|
android:text="@string/overflow_event_colic"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
26
app/src/main/res/layout/temperature_dialog.xml
Normal file
26
app/src/main/res/layout/temperature_dialog.xml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<com.google.android.material.slider.Slider
|
||||||
|
android:id="@+id/dialog_temperature_value"
|
||||||
|
android:layout_width="250dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:valueFrom="@integer/human_body_temp_min_metric"
|
||||||
|
android:valueTo="@integer/human_body_temp_max_metric"
|
||||||
|
android:stepSize="0.1"
|
||||||
|
android:value="@integer/human_body_temp_normal_metric"
|
||||||
|
android:theme="@style/LTSlider"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dialog_temperature_display"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textSize="30sp"
|
||||||
|
android:textColor="@color/accent"/>
|
||||||
|
</LinearLayout>
|
@ -10,10 +10,14 @@
|
|||||||
<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="log_temperature_dialog_title">Temperatura</string>
|
||||||
|
<string name="log_temperature_dialog_description">Inserisci la temperatura</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_note">📝 Nota</string>
|
<string name="overflow_event_note">📝 Nota</string>
|
||||||
<string name="overflow_event_custom">➕ Personalizzato</string>
|
<string name="overflow_event_temperature">🌡️ Temperatura</string>
|
||||||
|
<string name="overflow_event_colic">💨 Colichette</string>
|
||||||
|
|
||||||
<string name="event_bottle_desc">Biberon</string>
|
<string name="event_bottle_desc">Biberon</string>
|
||||||
<string name="event_scale_desc">Pesata</string>
|
<string name="event_scale_desc">Pesata</string>
|
||||||
@ -25,6 +29,8 @@
|
|||||||
<string name="event_medicine_desc">Medicina</string>
|
<string name="event_medicine_desc">Medicina</string>
|
||||||
<string name="event_enema_desc">Clistere</string>
|
<string name="event_enema_desc">Clistere</string>
|
||||||
<string name="event_note_desc">Nota</string>
|
<string name="event_note_desc">Nota</string>
|
||||||
|
<string name="event_temperature_desc">Temperatura</string>
|
||||||
|
<string name="event_colic_desc">Colichette</string>
|
||||||
<string name="event_unknown_desc"></string>
|
<string name="event_unknown_desc"></string>
|
||||||
|
|
||||||
<string name="toast_event_added">Evento aggiunto</string>
|
<string name="toast_event_added">Evento aggiunto</string>
|
||||||
|
@ -10,6 +10,9 @@
|
|||||||
<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="log_temperature_dialog_title">Temperature</string>
|
||||||
|
<string name="log_temperature_dialog_description">Insert the temperature</string>
|
||||||
|
|
||||||
<string name="event_bottle_type" translatable="false">🍼</string>
|
<string name="event_bottle_type" translatable="false">🍼</string>
|
||||||
<string name="event_scale_type" translatable="false">⚖️</string>
|
<string name="event_scale_type" translatable="false">⚖️</string>
|
||||||
<string name="event_breastfeeding_left_type" translatable="false">🤱 ←</string>
|
<string name="event_breastfeeding_left_type" translatable="false">🤱 ←</string>
|
||||||
@ -20,6 +23,8 @@
|
|||||||
<string name="event_medicine_type" translatable="false">💊</string>
|
<string name="event_medicine_type" translatable="false">💊</string>
|
||||||
<string name="event_enema_type" translatable="false">🪠</string>
|
<string name="event_enema_type" translatable="false">🪠</string>
|
||||||
<string name="event_note_type" translatable="false">📝</string>
|
<string name="event_note_type" translatable="false">📝</string>
|
||||||
|
<string name="event_temperature_type" translatable="false">🌡️</string>
|
||||||
|
<string name="event_colic_type" translatable="false">💨</string>
|
||||||
<string name="event_unknown_type" translatable="false">\?</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>
|
||||||
@ -32,12 +37,15 @@
|
|||||||
<string name="event_medicine_desc">Medicine</string>
|
<string name="event_medicine_desc">Medicine</string>
|
||||||
<string name="event_enema_desc">Enema</string>
|
<string name="event_enema_desc">Enema</string>
|
||||||
<string name="event_note_desc">Note</string>
|
<string name="event_note_desc">Note</string>
|
||||||
|
<string name="event_temperature_desc">Temperature</string>
|
||||||
|
<string name="event_colic_desc">Gaseous colic</string>
|
||||||
<string name="event_unknown_desc"></string>
|
<string name="event_unknown_desc"></string>
|
||||||
|
|
||||||
<string name="overflow_event_medicine">💊 Medicine</string>
|
<string name="overflow_event_medicine">💊 Medicine</string>
|
||||||
<string name="overflow_event_enema">🪠 Enema</string>
|
<string name="overflow_event_enema">🪠 Enema</string>
|
||||||
<string name="overflow_event_note">📝 Note</string>
|
<string name="overflow_event_note">📝 Note</string>
|
||||||
<string name="overflow_event_custom">➕ Add custom</string>
|
<string name="overflow_event_temperature">🌡️ Temperature</string>
|
||||||
|
<string name="overflow_event_colic">💨 Gaseous colic</string>
|
||||||
|
|
||||||
<string name="toast_event_added">Event logged</string>
|
<string name="toast_event_added">Event logged</string>
|
||||||
<string name="toast_logbook_saved">Logbook saved</string>
|
<string name="toast_logbook_saved">Logbook saved</string>
|
||||||
@ -90,6 +98,8 @@
|
|||||||
<string name="measurement_unit_liquid_base_imperial" translatable="false">fl oz.</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_base_imperial" translatable="false">oz</string>
|
||||||
<string name="measurement_unit_weight_tiny_imperial" translatable="false">gr</string>
|
<string name="measurement_unit_weight_tiny_imperial" translatable="false">gr</string>
|
||||||
|
<string name="measurement_unit_temperature_base_imperial" translatable="false">°F</string>
|
||||||
|
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
||||||
|
|
||||||
<string name="dialog_event_detail_title">Event detail</string>
|
<string name="dialog_event_detail_title">Event detail</string>
|
||||||
|
|
||||||
|
@ -9,4 +9,9 @@
|
|||||||
<style name="OverflowMenuText">
|
<style name="OverflowMenuText">
|
||||||
<item name="android:textSize">20sp</item>
|
<item name="android:textSize">20sp</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<style name="LTSlider" parent="Theme.MaterialComponents.Light.NoActionBar">
|
||||||
|
<item name="colorPrimary">@color/accent</item>
|
||||||
|
</style>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
9
app/src/main/res/values/values.xml
Normal file
9
app/src/main/res/values/values.xml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<integer name="human_body_temp_min_imperial">91</integer>
|
||||||
|
<integer name="human_body_temp_min_metric">33</integer>
|
||||||
|
<integer name="human_body_temp_max_imperial">109</integer>
|
||||||
|
<integer name="human_body_temp_max_metric">43</integer>
|
||||||
|
<integer name="human_body_temp_normal_imperial">98</integer>
|
||||||
|
<integer name="human_body_temp_normal_metric">37</integer>
|
||||||
|
</resources>
|
Loading…
Reference in New Issue
Block a user