forked from penguin86/luna-tracker
Compare commits
6 Commits
bottle_tim
...
64fde74e2e
| Author | SHA1 | Date | |
|---|---|---|---|
| 64fde74e2e | |||
| d2a71d500d | |||
| 3d893fa7db | |||
| d64f0b9627 | |||
| 2dbfdcf9d5 | |||
| 0c8b7503f0 |
@@ -31,7 +31,7 @@
|
||||
android:label="@string/settings_title"
|
||||
android:theme="@style/Theme.LunaTracker"/>
|
||||
<activity
|
||||
android:name=".LongTermStatisticsActivity"
|
||||
android:name=".StatisticsActivity"
|
||||
android:label="@string/statistics_title"
|
||||
android:theme="@style/Theme.LunaTracker"/>
|
||||
</application>
|
||||
|
||||
@@ -162,55 +162,60 @@ class MainActivity : AppCompatActivity() {
|
||||
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
||||
).filter { it != LunaEvent.Type.UNKNOWN }
|
||||
|
||||
fun setupMenu(maxButtonCount: Int, sortedEventTypes: List<LunaEvent.Type>): Int {
|
||||
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
||||
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
||||
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
||||
|
||||
val row2 = findViewById<View>(R.id.linear_layout_row2)
|
||||
val row2Button1 = findViewById<TextView>(R.id.button1_row2)
|
||||
val row2Button2 = findViewById<TextView>(R.id.button2_row2)
|
||||
val row2Button3 = findViewById<TextView>(R.id.button3_row2)
|
||||
|
||||
val row3 = findViewById<View>(R.id.linear_layout_row3)
|
||||
val row3Button1 = findViewById<TextView>(R.id.button1_row3)
|
||||
val row3Button2 = findViewById<TextView>(R.id.button2_row3)
|
||||
|
||||
// hide all rows/buttons (except row 3)
|
||||
for (view in listOf(row1, row1Button1, row1Button2,
|
||||
row2, row2Button1, row2Button2, row2Button3,
|
||||
row3, row3Button1, row3Button2)) {
|
||||
view.visibility = View.GONE
|
||||
}
|
||||
row3.visibility = View.VISIBLE
|
||||
|
||||
var showCounter = 0
|
||||
|
||||
fun show(vararg tvs: TextView) {
|
||||
for (tv in tvs) {
|
||||
val type = sortedEventTypes[showCounter]
|
||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||
tv.setOnClickListener { showCreateDialog(type) }
|
||||
tv.visibility = View.VISIBLE
|
||||
// show parent row
|
||||
(tv.parent as View).visibility = View.VISIBLE
|
||||
showCounter += 1
|
||||
}
|
||||
}
|
||||
|
||||
when (maxButtonCount) {
|
||||
0 -> { } // ignore - show empty row3
|
||||
1 -> show(row3Button1)
|
||||
2 -> show(row3Button1, row3Button2)
|
||||
3 -> show(row1Button1, row3Button1)
|
||||
4, 5, 6 -> show(row1Button1, row1Button2, row3Button1, row3Button2)
|
||||
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, row3Button1, row3Button2)
|
||||
}
|
||||
|
||||
return showCounter
|
||||
}
|
||||
|
||||
val usedEventCount = eventTypeStats.count { it.value > 0 }
|
||||
val maxButtonCount = if (dynamicMenu) { usedEventCount } else { 7 }
|
||||
|
||||
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
||||
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
||||
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
||||
|
||||
val row2 = findViewById<View>(R.id.linear_layout_row2)
|
||||
val row2Button1 = findViewById<TextView>(R.id.button1_row2)
|
||||
val row2Button2 = findViewById<TextView>(R.id.button2_row2)
|
||||
val row2Button3 = findViewById<TextView>(R.id.button3_row2)
|
||||
|
||||
val row3 = findViewById<View>(R.id.linear_layout_row3)
|
||||
val row3Button1 = findViewById<TextView>(R.id.button1_row3)
|
||||
val row3Button2 = findViewById<TextView>(R.id.button2_row3)
|
||||
|
||||
// hide all rows/buttons (except row 3)
|
||||
for (view in listOf(row1, row1Button1, row1Button2,
|
||||
row2, row2Button1, row2Button2, row2Button3,
|
||||
row3, row3Button1, row3Button2)) {
|
||||
view.visibility = View.GONE
|
||||
}
|
||||
row3.visibility = View.VISIBLE
|
||||
|
||||
var showCounter = 0
|
||||
|
||||
fun show(vararg tvs: TextView) {
|
||||
for (tv in tvs) {
|
||||
val type = eventTypesSorted[showCounter]
|
||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||
tv.setOnClickListener { showCreateDialog(type) }
|
||||
tv.visibility = View.VISIBLE
|
||||
// show parent row
|
||||
(tv.parent as View).visibility = View.VISIBLE
|
||||
showCounter += 1
|
||||
}
|
||||
}
|
||||
|
||||
when (maxButtonCount) {
|
||||
0 -> { } // ignore - show empty row3
|
||||
1 -> show(row3Button1)
|
||||
2 -> show(row3Button1, row3Button2)
|
||||
3 -> show(row1Button1, row3Button1)
|
||||
4, 5, 6 -> show(row1Button1, row1Button2, row3Button1, row3Button2)
|
||||
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, row3Button1, row3Button2)
|
||||
}
|
||||
val eventsShown = setupMenu(maxButtonCount, eventTypesSorted)
|
||||
|
||||
// store left over events for popup menu
|
||||
currentPopupItems = eventTypesSorted.subList(showCounter, eventTypesSorted.size)
|
||||
currentPopupItems = eventTypesSorted.subList(eventsShown, eventTypesSorted.size)
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
@@ -272,9 +277,6 @@ class MainActivity : AppCompatActivity() {
|
||||
numberPicker.wrapSelectorWheel = false
|
||||
numberPicker.value = event.quantity / 10
|
||||
|
||||
val numberPickerUnit = dialogView.findViewById<TextView>(R.id.dialog_number_picker_unit)
|
||||
numberPickerUnit.text = NumericUtils(this).measurement_unit_liquid_base
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
|
||||
@@ -313,9 +315,6 @@ class MainActivity : AppCompatActivity() {
|
||||
val weightET = dialogView.findViewById<EditText>(R.id.dialog_number_edittext)
|
||||
weightET.setText(event.quantity.toString())
|
||||
|
||||
val unitTV = dialogView.findViewById<TextView>(R.id.dialog_number_unit)
|
||||
unitTV.text = NumericUtils(this).measurement_unit_weight_base
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
|
||||
@@ -344,53 +343,6 @@ class MainActivity : AppCompatActivity() {
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
fun addHeightEvent(event: LunaEvent) {
|
||||
setToPreviousQuantity(event)
|
||||
askHeightValue(event, true) { saveEvent(event) }
|
||||
}
|
||||
|
||||
fun askHeightValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
// Show number picker dialog
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_height, null)
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
val heightET = dialogView.findViewById<EditText>(R.id.dialog_number_edittext)
|
||||
heightET.setText(event.quantity.toString())
|
||||
|
||||
val unitTV = dialogView.findViewById<TextView>(R.id.dialog_number_unit)
|
||||
unitTV.text = NumericUtils(this).measurement_unit_height_base
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
}
|
||||
|
||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||
val height = heightET.text.toString().toIntOrNull()
|
||||
if (height != null) {
|
||||
event.time = pickedTime.time.time / 1000
|
||||
event.quantity = height
|
||||
onPositive()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_integer_error, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
d.setNegativeButton(android.R.string.cancel) { dialogInterface, i ->
|
||||
dialogInterface.dismiss()
|
||||
}
|
||||
|
||||
val alertDialog = d.create()
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
fun addTemperatureEvent(event: LunaEvent) {
|
||||
setToPreviousQuantity(event)
|
||||
askTemperatureValue(event, true) { saveEvent(event) }
|
||||
@@ -471,30 +423,32 @@ class MainActivity : AppCompatActivity() {
|
||||
return dateTime
|
||||
}
|
||||
|
||||
fun addDurationEvent(event: LunaEvent) {
|
||||
askDurationEvent(event, true) { saveEvent(event) }
|
||||
fun addSleepEvent(event: LunaEvent) {
|
||||
askSleepValue(event, true) { saveEvent(event) }
|
||||
}
|
||||
|
||||
fun askDurationEvent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
fun askSleepValue(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_duration, null)
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
val durationTV = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
||||
val datePickerBeginTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
|
||||
val datePickerEndTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker_end)
|
||||
val dateDelimiterTV = dialogView.findViewById<TextView>(R.id.dialog_date_range_delimiter)
|
||||
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
||||
val datePickerBegin = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
|
||||
val datePickerEnd = dialogView.findViewById<TextView>(R.id.dialog_date_picker_end)
|
||||
val dateDelimiter = dialogView.findViewById<TextView>(R.id.dialog_date_range_delimiter)
|
||||
val durationButtons = dialogView.findViewById<LinearLayout>(R.id.duration_buttons)
|
||||
val durationNowButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_now)
|
||||
val durationClearButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_clear)
|
||||
val durationAsleepButton = dialogView.findViewById<Button>(R.id.dialog_date_duration_asleep)
|
||||
val durationMinus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_minus5)
|
||||
val durationPlus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_plus5)
|
||||
|
||||
val currentDurationTextColor = durationTV.currentTextColor
|
||||
val currentDurationTextColor = durationTextView.currentTextColor
|
||||
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
||||
|
||||
// in seconds
|
||||
var durationStart = event.getStartTime()
|
||||
var durationEnd = event.getEndTime()
|
||||
var sleepBegin = event.time
|
||||
var sleepEnd = event.time + event.quantity
|
||||
|
||||
fun isValidTime(timeUnix: Long): Boolean {
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
@@ -505,76 +459,85 @@ class MainActivity : AppCompatActivity() {
|
||||
return (timeBeginUnix <= timeEndUnix) && (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
||||
}
|
||||
|
||||
fun updateFields() {
|
||||
datePickerBeginTV.text = DateUtils.formatDateTime(durationStart)
|
||||
datePickerEndTV.text = DateUtils.formatDateTime(durationEnd)
|
||||
|
||||
dateTimePicker(durationStart, datePickerBeginTV) { pickedTime: Long ->
|
||||
durationStart = pickedTime
|
||||
if (datePickerEndTV.visibility == View.GONE) {
|
||||
durationEnd = pickedTime
|
||||
}
|
||||
updateFields()
|
||||
}
|
||||
|
||||
dateTimePicker(durationEnd, datePickerEndTV) { pickedTime: Long ->
|
||||
durationEnd = pickedTime
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationTV.setTextColor(currentDurationTextColor)
|
||||
val duration = durationEnd - durationStart
|
||||
if (duration == 0L) {
|
||||
// event is ongoing
|
||||
durationTV.text = "💤"
|
||||
dateDelimiterTV.visibility = View.GONE
|
||||
datePickerEndTV.visibility = View.GONE
|
||||
} else {
|
||||
durationTV.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
||||
if (!isValidTimeSpan(durationStart, durationEnd)) {
|
||||
durationTV.setTextColor(invalidDurationTextColor)
|
||||
}
|
||||
dateDelimiterTV.visibility = View.VISIBLE
|
||||
datePickerEndTV.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
val colorBegin = if (isValidTime(durationStart)) { currentDurationTextColor } else { invalidDurationTextColor }
|
||||
datePickerBeginTV.setTextColor(colorBegin)
|
||||
|
||||
val colorEnd = if (isValidTime(durationEnd)) { currentDurationTextColor } else { invalidDurationTextColor }
|
||||
datePickerEndTV.setTextColor(colorEnd)
|
||||
// prevent printing of seconds
|
||||
fun adjustToMinute(unixTime: Long): Long {
|
||||
return unixTime - (unixTime % 60)
|
||||
}
|
||||
|
||||
fun updateFields() {
|
||||
datePickerBegin.text = DateUtils.formatDateTime(sleepBegin)
|
||||
datePickerEnd.text = DateUtils.formatDateTime(sleepEnd)
|
||||
|
||||
durationTextView.setTextColor(currentDurationTextColor)
|
||||
val duration = sleepEnd - sleepBegin
|
||||
if (duration == 0L) {
|
||||
// baby is sleeping
|
||||
durationTextView.text = "💤"
|
||||
} else {
|
||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
||||
if (!isValidTimeSpan(sleepBegin, sleepEnd)) {
|
||||
durationTextView.setTextColor(invalidDurationTextColor)
|
||||
}
|
||||
}
|
||||
|
||||
datePickerBegin.setTextColor(if (isValidTime(sleepBegin)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
datePickerEnd.setTextColor(if (isValidTime(sleepEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
}
|
||||
|
||||
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { time: Long ->
|
||||
sleepBegin = adjustToMinute(time)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { time: Long ->
|
||||
sleepEnd = adjustToMinute(time)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
sleepBegin = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
||||
sleepEnd = adjustToMinute(pickedDateTimeEnd.time.time / 1000)
|
||||
|
||||
updateFields()
|
||||
|
||||
if (showTime) {
|
||||
dateDelimiterTV.visibility = View.GONE
|
||||
datePickerEndTV.visibility = View.GONE
|
||||
durationTV.visibility = View.GONE
|
||||
dateDelimiter.visibility = View.GONE
|
||||
datePickerEnd.visibility = View.GONE
|
||||
durationTextView.visibility = View.GONE
|
||||
durationButtons.visibility = View.GONE
|
||||
//d.setMessage("")
|
||||
} else {
|
||||
dateDelimiterTV.visibility = View.VISIBLE
|
||||
datePickerEndTV.visibility = View.VISIBLE
|
||||
durationTV.visibility = View.VISIBLE
|
||||
dateDelimiter.visibility = View.VISIBLE
|
||||
datePickerEnd.visibility = View.VISIBLE
|
||||
durationTextView.visibility = View.VISIBLE
|
||||
durationButtons.visibility = View.VISIBLE
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
}
|
||||
|
||||
updateFields()
|
||||
durationMinus5Button.setOnClickListener {
|
||||
sleepEnd = (sleepEnd - 300).coerceAtLeast(sleepBegin)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationClearButton.setOnClickListener {
|
||||
durationEnd = durationStart
|
||||
durationPlus5Button.setOnClickListener {
|
||||
sleepEnd = (sleepEnd + 300).coerceAtLeast(sleepBegin)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationAsleepButton.setOnClickListener {
|
||||
sleepEnd = sleepBegin
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationNowButton.setOnClickListener {
|
||||
durationEnd = System.currentTimeMillis() / 1000
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
sleepEnd = adjustToMinute(now)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||
if (isValidTime(durationStart) && isValidTime(durationEnd) && isValidTimeSpan(durationStart, durationEnd)) {
|
||||
event.time = durationStart
|
||||
event.quantity = (durationEnd - durationStart).toInt()
|
||||
if (isValidTime(sleepBegin) && isValidTime(sleepEnd) && isValidTimeSpan(sleepBegin, sleepEnd)) {
|
||||
event.time = sleepBegin
|
||||
event.quantity = (sleepEnd - sleepBegin).toInt()
|
||||
onPositive()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
||||
@@ -695,6 +658,9 @@ class MainActivity : AppCompatActivity() {
|
||||
var nextEvent = getNextSameEvent(current, templates)
|
||||
|
||||
notesET.setText(current.notes)
|
||||
if (useQuantity) {
|
||||
qtyET.setText(current.quantity.toString())
|
||||
}
|
||||
|
||||
if (nextEvent == null && current != event) {
|
||||
nextEvent = event
|
||||
@@ -703,6 +669,9 @@ class MainActivity : AppCompatActivity() {
|
||||
if (nextEvent != null) {
|
||||
nextTextView.setOnClickListener {
|
||||
notesET.setText(nextEvent.notes)
|
||||
if (useQuantity) {
|
||||
qtyET.setText(nextEvent.quantity.toString())
|
||||
}
|
||||
updateContent(nextEvent)
|
||||
}
|
||||
nextTextView.alpha = 1.0f
|
||||
@@ -714,6 +683,9 @@ class MainActivity : AppCompatActivity() {
|
||||
if (prevEvent != null) {
|
||||
prevTextView.setOnClickListener {
|
||||
notesET.setText(prevEvent.notes)
|
||||
if (useQuantity) {
|
||||
qtyET.setText(prevEvent.quantity.toString())
|
||||
}
|
||||
updateContent(prevEvent)
|
||||
}
|
||||
prevTextView.alpha = 1.0f
|
||||
@@ -906,15 +878,12 @@ class MainActivity : AppCompatActivity() {
|
||||
when (event.type) {
|
||||
LunaEvent.Type.BABY_BOTTLE -> askBabyBottleContent(event, false, updateValues)
|
||||
LunaEvent.Type.WEIGHT -> askWeightValue(event, false, updateValues)
|
||||
LunaEvent.Type.HEIGHT -> askHeightValue(event, false, updateValues)
|
||||
LunaEvent.Type.DIAPERCHANGE_POO,
|
||||
LunaEvent.Type.DIAPERCHANGE_PEE,
|
||||
LunaEvent.Type.PUKE -> askAmountValue(event, false, updateValues)
|
||||
LunaEvent.Type.TEMPERATURE -> askTemperatureValue(event, false, updateValues)
|
||||
LunaEvent.Type.FOOD,
|
||||
LunaEvent.Type.MEDICINE,
|
||||
LunaEvent.Type.NOTE -> askNotes(event, false, updateValues)
|
||||
LunaEvent.Type.SLEEP -> askDurationEvent(event, false, updateValues)
|
||||
LunaEvent.Type.SLEEP -> askSleepValue(event, false, updateValues)
|
||||
else -> {
|
||||
Log.w(TAG, "Unexpected type: ${event.type}")
|
||||
}
|
||||
@@ -1328,7 +1297,6 @@ class MainActivity : AppCompatActivity() {
|
||||
when (type) {
|
||||
LunaEvent.Type.BABY_BOTTLE -> addBabyBottleEvent(event)
|
||||
LunaEvent.Type.WEIGHT -> addWeightEvent(event)
|
||||
LunaEvent.Type.HEIGHT -> addHeightEvent(event)
|
||||
LunaEvent.Type.BREASTFEEDING_LEFT_NIPPLE -> addPlainEvent(event)
|
||||
LunaEvent.Type.BREASTFEEDING_BOTH_NIPPLE -> addPlainEvent(event)
|
||||
LunaEvent.Type.BREASTFEEDING_RIGHT_NIPPLE -> addPlainEvent(event)
|
||||
@@ -1342,7 +1310,7 @@ class MainActivity : AppCompatActivity() {
|
||||
LunaEvent.Type.FOOD -> addNoteEvent(event)
|
||||
LunaEvent.Type.PUKE -> addAmountEvent(event)
|
||||
LunaEvent.Type.BATH -> addPlainEvent(event)
|
||||
LunaEvent.Type.SLEEP -> addDurationEvent(event)
|
||||
LunaEvent.Type.SLEEP -> addSleepEvent(event)
|
||||
LunaEvent.Type.UNKNOWN -> {} // ignore
|
||||
}
|
||||
}
|
||||
@@ -1359,7 +1327,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// Add statistics (hard coded)
|
||||
contentView.findViewById<View>(R.id.button_statistics).setOnClickListener {
|
||||
if (logbook != null && !pauseLogbookUpdate) {
|
||||
val i = Intent(applicationContext, LongTermStatisticsActivity::class.java)
|
||||
val i = Intent(applicationContext, StatisticsActivity::class.java)
|
||||
i.putExtra("LOOGBOOK_NAME", logbook!!.name)
|
||||
startActivity(i)
|
||||
} else {
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.Locale
|
||||
import kotlin.math.max
|
||||
import kotlin.math.min
|
||||
|
||||
class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
class StatisticsActivity : AppCompatActivity() {
|
||||
var lastToastShown = 0L
|
||||
|
||||
lateinit var barChart: BarChart
|
||||
@@ -181,11 +181,14 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val values = ArrayList<BarEntry>()
|
||||
val stack = ArrayList(List(state.endSpan - state.startSpan + 1) { IntArray(24 * 60 * 60 / SLEEP_PATTERN_GRANULARITY) })
|
||||
|
||||
Log.d(TAG, "stack.size: ${stack.size}, array.size: ${stack[0].size}, dayCounter.daysWithData.size: ${state.dayCounter.daysWithData.size}")
|
||||
|
||||
fun stackValuePattern(index: Int, spanBegin: Long, spanEnd: Long, begin: Long, end: Long) {
|
||||
val beginDays = unixToDays(begin)
|
||||
val endDays = unixToDays(end)
|
||||
var mid = begin
|
||||
|
||||
//Log.d(TAG, "stackValuePattern: ${beginDays}..${endDays}")
|
||||
for (i in beginDays..endDays) {
|
||||
// i is the days/weeks/months since unix epoch
|
||||
val dayBegin = daysToUnix(i)
|
||||
@@ -198,6 +201,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
assert(sleepBegin <= sleepEnd)
|
||||
val iBegin = (sleepBegin - dayBegin) / SLEEP_PATTERN_GRANULARITY
|
||||
val iEnd = iBegin + (sleepEnd - sleepBegin) / SLEEP_PATTERN_GRANULARITY
|
||||
//Log.d(TAG, "index: $index, iBegin: $iBegin, iEnd: $iEnd, dayBegin: ${Date(dayBegin * 1000)}, dayEnd: ${Date(dayEnd * 1000)}, sleepBegin: ${Date(sleepBegin * 1000)}, sleepEnd: ${Date(sleepEnd * 1000)}")
|
||||
for (j in iBegin..<iEnd) {
|
||||
stack[index][j.toInt()] += 1
|
||||
}
|
||||
@@ -215,14 +219,17 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val endIndex = unixToSpan(endUnix)
|
||||
var mid = startUnix
|
||||
|
||||
//Log.d(TAG, "startUnix: ${Date(startUnix * 1000)}, endUnix: ${Date(endUnix * 1000)}, begIndex: $begIndex, endIndex: $endIndex (index diff: ${endIndex - begIndex})")
|
||||
for (i in begIndex..endIndex) {
|
||||
// i is the days/weeks/months since unix epoch
|
||||
val spanBegin = spanToUnix(i)
|
||||
val spanEnd = spanToUnix(i + 1)
|
||||
//Log.d(TAG, "mid: ${Date(mid * 1000)}, spanBegin: ${Date(spanBegin * 1000)}, spanEnd: ${Date(spanEnd * 1000)}, beginUnix: ${Date(startUnix * 1000)} endUnix: ${Date(endUnix * 1000)}")
|
||||
val sleepBegin = max(mid, spanBegin)
|
||||
val sleepEnd = min(endUnix, spanEnd)
|
||||
val index = i - state.startSpan
|
||||
val duration = sleepEnd - sleepBegin
|
||||
//Log.d(TAG, "[$index] sleepBegin: ${Date(sleepBegin * 1000)}, sleepEnd: ${Date(sleepEnd * 1000)}, ${DateUtils.formatTimeDuration(this, duration)}")
|
||||
|
||||
state.dayCounter.setDaysWithData(sleepBegin, sleepEnd)
|
||||
stackValuePattern(index, spanBegin, spanEnd, sleepBegin, sleepEnd)
|
||||
@@ -249,6 +256,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
for ((index, dayArray) in stack.withIndex()) {
|
||||
val daysWithData = state.dayCounter.countDaysWithData(spanToUnix(state.startSpan + index), spanToUnix(state.startSpan + index + 1))
|
||||
|
||||
//Log.d(TAG, "index: $index: daysWithData: $daysWithData, dayArray: ${dayArray.joinToString { it.toString() }}")
|
||||
val vals = ArrayList<Float>()
|
||||
|
||||
var prevIndex = -1 // time slot index
|
||||
@@ -270,10 +278,14 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
allColors.add(mapColor(prevValue, daysWithData))
|
||||
}
|
||||
|
||||
//Log.d(TAG, "Range $index, vals: ${vals.joinToString { it.toInt().toString() }}") //, allColors: ${allColors.joinToString { it.toString() }}")
|
||||
|
||||
assert(values.size == index)
|
||||
values.add(BarEntry(values.size.toFloat(), vals.toFloatArray()))
|
||||
}
|
||||
|
||||
//Log.d(TAG, "daysWithData: ${state.dayCounter.daysWithData.joinToString()}")
|
||||
|
||||
barChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener {
|
||||
override fun onValueSelected(e: Entry?, h: Highlight?) {
|
||||
if (e == null || h == null) {
|
||||
@@ -297,6 +309,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
|
||||
val dayStartUnix = daysToUnix(unixToDays(state.startUnix) + index)
|
||||
|
||||
//Log.d(TAG, "startUnix: ${Date(startUnix * 1000)}, x: ${e.x.toInt()}, dayStartUnix: ${Date(dayStartUnix * 1000)}")
|
||||
val startSeconds =
|
||||
SLEEP_PATTERN_GRANULARITY * value.yVals.sliceArray(0..<h.stackIndex)
|
||||
.fold(0) { acc, y -> acc + y.toInt() }
|
||||
@@ -343,9 +356,15 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
set1.isHighlightEnabled = true
|
||||
set1.setDrawIcons(false)
|
||||
|
||||
//Log.d(TAG, "showSleepPatternBarGraphSlotted; barChart.xAxis.labelCount: ${barChart.xAxis.labelCount}, barChart.visibleXRange: ${barChart.visibleXRange}, barChart.xAxis.isCenterAxisLabelsEnabled: ${barChart.xAxis.isCenterAxisLabelsEnabled}, barChart.isAutoScaleMinMaxEnabled: ${barChart.isAutoScaleMinMaxEnabled}, barChart.isScaleXEnabled: ${barChart.isScaleXEnabled}, barChart.isScaleYEnabled: ${barChart.isScaleYEnabled}")
|
||||
|
||||
val data = BarData(set1)
|
||||
data.setValueTextSize(12f)
|
||||
|
||||
// does not work quite right yet
|
||||
//Log.d(TAG, "xChartMax: ${barChart.xChartMax}")
|
||||
//barChart.centerViewTo(barChart.xChartMax, 0F, YAxis.AxisDependency.LEFT)
|
||||
|
||||
val valueCount = min(values.size, 24)
|
||||
barChart.setData(data)
|
||||
barChart.legend.isEnabled = false
|
||||
@@ -396,14 +415,17 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val endIndex = unixToSpan(endUnix)
|
||||
var mid = startUnix
|
||||
|
||||
//Log.d(TAG, "startUnix: ${Date(startUnix * 1000)}, endUnix: ${Date(endUnix * 1000)}, begIndex: $begIndex, endIndex: $endIndex (index diff: ${endIndex - begIndex})")
|
||||
for (i in begIndex..endIndex) {
|
||||
// i is the days/weeks/months since unix epoch
|
||||
val spanBegin = spanToUnix(i)
|
||||
val spanEnd = spanToUnix(i + 1)
|
||||
//Log.d(TAG, "mid: ${Date(mid * 1000)}, spanBegin: ${Date(spanBegin * 1000)}, spanEnd: ${Date(spanEnd * 1000)}, beginUnix: ${Date(startUnix * 1000)} endUnix: ${Date(endUnix * 1000)}")
|
||||
val sleepBegin = max(mid, spanBegin)
|
||||
val sleepEnd = min(endUnix, spanEnd)
|
||||
val index = i - state.startSpan
|
||||
val duration = sleepEnd - sleepBegin
|
||||
//Log.d(TAG, "[$index] sleepBegin: ${Date(sleepBegin * 1000)}, sleepEnd: ${Date(sleepEnd * 1000)}, ${DateUtils.formatTimeDuration(this, duration)}")
|
||||
|
||||
state.dayCounter.setDaysWithData(sleepBegin, sleepEnd)
|
||||
stackValuePattern(index, spanBegin, spanEnd, sleepBegin, sleepEnd)
|
||||
@@ -456,10 +478,13 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onNothingSelected() {}
|
||||
})
|
||||
//Log.d(TAG, "showSleepPatternBarGraphDaily: values.size: ${values.size}, barChart.xAxis.labelCount: ${barChart.xAxis.labelCount}")
|
||||
|
||||
val data = BarData(set1)
|
||||
data.setValueTextSize(12f)
|
||||
|
||||
//Log.d(TAG, "showSleepPatternBarGraphDaily: new barChart.xAxis.labelCount: ${barChart.xAxis.labelCount}")
|
||||
|
||||
val valueCount = min(values.size, 24)
|
||||
barChart.setData(data)
|
||||
barChart.legend.isEnabled = false
|
||||
@@ -487,6 +512,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
fun showSleepBarGraph(state: GraphState) {
|
||||
val ranges = toSleepRanges(state.events)
|
||||
val values = ArrayList(List(state.endSpan - state.startSpan + 1) { BarEntry(it.toFloat(), 0F) })
|
||||
//Log.d(TAG, "startUnix: ${Date(state.startUnix * 1000)}, endUnix: ${Date(state.endUnix * 1000)}")
|
||||
|
||||
for (range in ranges) {
|
||||
// a sleep event can span to another day
|
||||
@@ -497,14 +523,18 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val endIndex = unixToSpan(endUnix)
|
||||
var mid = startUnix
|
||||
|
||||
//Log.d(TAG, "beginIndex: $begIndex, endIndex: $endIndex, startUnix: ${Date(startUnix * 1000)} ($startUnix), endUnix: ${Date(endUnix * 1000)} ($endUnix)")
|
||||
//Log.d(TAG, "startUnix: ${Date(startUnix * 1000)}, endUnix: ${Date(endUnix * 1000)}, begIndex: $begIndex, endIndex: $endIndex (index diff: ${endIndex - begIndex})")
|
||||
for (i in begIndex..endIndex) {
|
||||
// i is the days/weeks/months since unix epoch
|
||||
val spanBegin = spanToUnix(i)
|
||||
val spanEnd = spanToUnix(i + 1)
|
||||
//Log.d(TAG, "i: $i, mid: ${Date(mid * 1000)}, spanBegin: ${Date(spanBegin * 1000)}, spanEnd: ${Date(spanEnd * 1000)}, beginUnix: ${Date(startUnix * 1000)} endUnix: ${Date(endUnix * 1000)}")
|
||||
val sleepBegin = max(mid, spanBegin)
|
||||
val sleepEnd = min(endUnix, spanEnd)
|
||||
val index = i - state.startSpan
|
||||
val duration = sleepEnd - sleepBegin
|
||||
//Log.d(TAG, "[$index] sleepBegin: ${Date(sleepBegin * 1000)}, sleepEnd: ${Date(sleepEnd * 1000)}, ${DateUtils.formatTimeDuration(this, duration)}")
|
||||
|
||||
state.dayCounter.setDaysWithData(sleepBegin, sleepEnd)
|
||||
|
||||
@@ -587,6 +617,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
|
||||
for (index in values.indices) {
|
||||
val daysWithData = state.dayCounter.countDaysWithData(spanToUnix(state.startSpan + index), spanToUnix(state.startSpan + index + 1))
|
||||
//Log.d(TAG, "values[$index].y: ${values[index].y}, daysWithData: $daysWithData")
|
||||
if (daysWithData == 0) {
|
||||
assert(values[index].y == 0F)
|
||||
} else {
|
||||
@@ -603,6 +634,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
data.setValueFormatter(object : ValueFormatter() {
|
||||
override fun getFormattedValue(value: Float): String {
|
||||
val prefix = if (timeRangeSelection == TimeRange.DAY) { "" } else { "⌀ " }
|
||||
//Log.d(TAG, "getFormattedValue ${dataTypeSelectionValue} ${eventTypeSelectionValue}")
|
||||
return when (graphTypeSelection) {
|
||||
GraphType.BOTTLE_EVENTS -> {
|
||||
prefix + value.toInt().toString()
|
||||
@@ -636,8 +668,10 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
fun countDaysWithData(beginUnix: Long, endUnix: Long): Int {
|
||||
val beginDays = unixToDays(beginUnix)
|
||||
val endDays = unixToDays(endUnix)
|
||||
//Log.d(TAG, "countDaysWithData: beginDays: $beginDays, endDays: $endDays, ${Date(beginUnix * 1000)} - ${Date(endUnix * 1000)}")
|
||||
var count = 0
|
||||
for (i in (beginDays - startDays)..<(endDays - startDays)) {
|
||||
//Log.d(TAG, "countDaysWithData: i: $i, size: ${daysWithData.size}")
|
||||
count += if (daysWithData[i]) { 1 } else { 0 }
|
||||
}
|
||||
return count
|
||||
@@ -657,12 +691,14 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
data class GraphState(val events: List<LunaEvent>, val dayCounter: DayCounter, val startUnix: Long, val endUnix: Long, val startSpan: Int, val endSpan: Int)
|
||||
|
||||
fun showGraph() {
|
||||
//Log.d(TAG, "showGraph: graphTypeSelection: $graphTypeSelection, timeRangeSelection: $timeRangeSelection")
|
||||
barChart.fitScreen()
|
||||
barChart.data?.clearValues()
|
||||
barChart.xAxis.valueFormatter = null
|
||||
barChart.notifyDataSetChanged()
|
||||
barChart.clear()
|
||||
barChart.invalidate()
|
||||
//Log.d(TAG, "resetBarChart; barChart.xAxis.labelCount: ${barChart.xAxis.labelCount}, barChart.visibleXRange: ${barChart.visibleXRange}, barChart.xAxis.isCenterAxisLabelsEnabled: ${barChart.xAxis.isCenterAxisLabelsEnabled}, barChart.isAutoScaleMinMaxEnabled: ${barChart.isAutoScaleMinMaxEnabled}, barChart.isScaleXEnabled: ${barChart.isScaleXEnabled}, barChart.isScaleYEnabled: ${barChart.isScaleYEnabled}")
|
||||
|
||||
val type = when (graphTypeSelection) {
|
||||
GraphType.BOTTLE_EVENTS,
|
||||
@@ -672,6 +708,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
GraphType.SLEEP_PATTERN -> LunaEvent.Type.SLEEP
|
||||
}
|
||||
|
||||
|
||||
val events = MainActivity.allEvents.filter { it.type == type }.sortedBy { it.time }
|
||||
|
||||
if (events.isEmpty()) {
|
||||
@@ -696,6 +733,8 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val endDays = unixToDays(spanToUnix(endSpan + 1)) // until end of next span
|
||||
val dayCounter = DayCounter(startDays, endDays)
|
||||
|
||||
//Log.d(TAG, "startUnix: ${Date(1000 * startUnix)}, endUnix: ${Date(1000 * endUnix)}, startSpan: ${Date(1000 * spanToUnix(startSpan))}, endSpan: ${Date(1000 * spanToUnix(endSpan))}, startDaysUnix: ${Date(daysToUnix(startDays) * 1000)}. endDaysUnix: ${Date(daysToUnix(endDays) * 1000)}")
|
||||
|
||||
// print dates
|
||||
barChart.xAxis.valueFormatter = object: ValueFormatter() {
|
||||
override fun getFormattedValue(value: Float): String {
|
||||
@@ -709,6 +748,8 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val week = dateTime.get(Calendar.WEEK_OF_YEAR)
|
||||
val day = dateTime.get(Calendar.DAY_OF_MONTH)
|
||||
|
||||
//Log.d(TAG, "index: $index, unixSeconds: ${Date(1000 * unixSeconds)}, day: $day, week: $week, month: $month, year: $year")
|
||||
|
||||
// Adjust years if the first week of a year starts in the previous year.
|
||||
val years = if (month == 12 && week == 1) {
|
||||
year + 1
|
||||
@@ -760,6 +801,8 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
val spinnerAdapter =
|
||||
ArrayAdapter.createFromResource(this, arrayId, R.layout.statistics_spinner_item)
|
||||
|
||||
//Log.d(TAG, "spinner ${arrayValues.indexOf(currentValue)} (${arrayValues.joinToString { it }})")
|
||||
|
||||
spinner.adapter = spinnerAdapter
|
||||
spinner.setSelection(arrayValues.indexOf(currentValue))
|
||||
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
@@ -767,7 +810,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, pos: Int, id: Long) {
|
||||
if (pos >= arrayValues.size) {
|
||||
Toast.makeText(
|
||||
this@LongTermStatisticsActivity,
|
||||
this@StatisticsActivity,
|
||||
"pos out of bounds: $arrayValues", Toast.LENGTH_SHORT
|
||||
).show()
|
||||
return
|
||||
@@ -784,7 +827,7 @@ class LongTermStatisticsActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TAG = "LongTermStatisticsActivity"
|
||||
const val TAG = "StatisticsActivity"
|
||||
|
||||
// 15 min steps
|
||||
const val SLEEP_PATTERN_GRANULARITY = 15 * 60
|
||||
@@ -63,7 +63,7 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
|
||||
// if the event is weight, show difference with the last one
|
||||
if (item.type == LunaEvent.Type.WEIGHT) {
|
||||
val lastWeight = getPreviousEvent(position, LunaEvent.Type.WEIGHT)
|
||||
val lastWeight = getPreviousWeightEvent(position)
|
||||
if (lastWeight != null) {
|
||||
val differenceInWeight = item.quantity - lastWeight.quantity
|
||||
val sign = if (differenceInWeight > 0) "+" else ""
|
||||
@@ -74,19 +74,6 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
}
|
||||
}
|
||||
|
||||
// if the event is height, show difference with the last one
|
||||
if (item.type == LunaEvent.Type.HEIGHT) {
|
||||
val lastHeight = getPreviousEvent(position, LunaEvent.Type.HEIGHT)
|
||||
if (lastHeight != null) {
|
||||
val differenceInHeight = item.quantity - lastHeight.quantity
|
||||
val sign = if (differenceInHeight > 0) "+" else ""
|
||||
quantityText += "\n($sign$differenceInHeight)"
|
||||
if (differenceInHeight < 0) {
|
||||
holder.quantity.setTextColor(ContextCompat.getColor(context, R.color.danger))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.quantity.text = quantityText
|
||||
|
||||
// Listeners
|
||||
@@ -101,12 +88,12 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
return items.size
|
||||
}
|
||||
|
||||
private fun getPreviousEvent(startFromPosition: Int, type: LunaEvent.Type): LunaEvent? {
|
||||
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 != type)
|
||||
if (item.type != LunaEvent.Type.WEIGHT)
|
||||
continue
|
||||
return item
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
DIAPERCHANGE_PEE,
|
||||
SLEEP,
|
||||
WEIGHT,
|
||||
HEIGHT,
|
||||
MEDICINE,
|
||||
ENEMA,
|
||||
NOTE,
|
||||
@@ -146,7 +145,6 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_bottle_type
|
||||
Type.WEIGHT -> R.string.event_weight_type
|
||||
Type.HEIGHT -> R.string.event_height_type
|
||||
Type.BREASTFEEDING_LEFT_NIPPLE -> R.string.event_breastfeeding_left_type
|
||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_type
|
||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_type
|
||||
@@ -176,8 +174,7 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
Type.DIAPERCHANGE_PEE,
|
||||
Type.PUKE -> R.string.log_amount_dialog_description
|
||||
Type.WEIGHT -> R.string.log_weight_dialog_description
|
||||
Type.HEIGHT -> R.string.log_height_dialog_description
|
||||
Type.SLEEP -> R.string.log_duration_dialog_description
|
||||
Type.SLEEP -> R.string.log_sleep_dialog_description
|
||||
else -> R.string.log_unknown_dialog_description
|
||||
}
|
||||
)
|
||||
@@ -188,7 +185,6 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_bottle_desc
|
||||
Type.WEIGHT -> R.string.event_weight_desc
|
||||
Type.HEIGHT -> R.string.event_height_desc
|
||||
Type.BREASTFEEDING_LEFT_NIPPLE -> R.string.event_breastfeeding_left_desc
|
||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_breastfeeding_both_desc
|
||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_breastfeeding_right_desc
|
||||
@@ -214,7 +210,6 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
when (type) {
|
||||
Type.BABY_BOTTLE -> R.string.event_type_item_bottle
|
||||
Type.WEIGHT -> R.string.event_type_item_weight
|
||||
Type.HEIGHT -> R.string.event_type_item_height
|
||||
Type.BREASTFEEDING_LEFT_NIPPLE -> R.string.event_type_item_breastfeeding_left
|
||||
Type.BREASTFEEDING_BOTH_NIPPLE -> R.string.event_type_item_breastfeeding_both
|
||||
Type.BREASTFEEDING_RIGHT_NIPPLE -> R.string.event_type_item_breastfeeding_right
|
||||
|
||||
@@ -9,15 +9,10 @@ import java.util.Date
|
||||
class DateUtils {
|
||||
companion object {
|
||||
/**
|
||||
* Format time duration in seconds as e.g. "2 hours, 1 min", rounded to minutes.
|
||||
* Format time duration in seconds as e.g. "2 hours, 1 min".
|
||||
* Used for the duration to the next/previous event in the event details dialog.
|
||||
*/
|
||||
fun formatTimeDuration(context: Context, secondsDiff: Long): String {
|
||||
val adjusted = (secondsDiff + 30) - (secondsDiff + 30) % 60
|
||||
return formatTimeDurationExact(context, adjusted)
|
||||
}
|
||||
|
||||
fun formatTimeDurationExact(context: Context, secondsDiff: Long): String {
|
||||
var seconds = secondsDiff
|
||||
|
||||
val years = (seconds / (365 * 24 * 60 * 60F)).toLong()
|
||||
|
||||
@@ -11,10 +11,10 @@ import utils.DateUtils.Companion.formatTimeDuration
|
||||
import java.text.NumberFormat
|
||||
|
||||
class NumericUtils (val context: Context) {
|
||||
val numberFormat: NumberFormat
|
||||
val measurement_unit_liquid_base: String
|
||||
val measurement_unit_weight_base: String
|
||||
val measurement_unit_weight_tiny: String
|
||||
val measurement_unit_height_base: String
|
||||
val measurement_unit_temperature_base: String
|
||||
|
||||
private fun isMetricSystem(): Boolean {
|
||||
@@ -35,6 +35,7 @@ class NumericUtils (val context: Context) {
|
||||
}
|
||||
|
||||
init {
|
||||
this.numberFormat = NumberFormat.getInstance()
|
||||
this.measurement_unit_liquid_base = context.getString(
|
||||
if (isMetricSystem())
|
||||
R.string.measurement_unit_liquid_base_metric
|
||||
@@ -53,12 +54,6 @@ class NumericUtils (val context: Context) {
|
||||
else
|
||||
R.string.measurement_unit_weight_tiny_imperial
|
||||
)
|
||||
this.measurement_unit_height_base = context.getString(
|
||||
if (isMetricSystem())
|
||||
R.string.measurement_unit_height_base_metric
|
||||
else
|
||||
R.string.measurement_unit_height_base_imperial
|
||||
)
|
||||
this.measurement_unit_temperature_base = context.getString(
|
||||
if (isMetricSystem())
|
||||
R.string.measurement_unit_temperature_base_metric
|
||||
@@ -95,7 +90,6 @@ class NumericUtils (val context: Context) {
|
||||
when (type) {
|
||||
LunaEvent.Type.BABY_BOTTLE -> measurement_unit_liquid_base
|
||||
LunaEvent.Type.WEIGHT -> measurement_unit_weight_base
|
||||
LunaEvent.Type.HEIGHT -> measurement_unit_height_base
|
||||
LunaEvent.Type.MEDICINE -> measurement_unit_weight_tiny
|
||||
LunaEvent.Type.TEMPERATURE -> measurement_unit_temperature_base
|
||||
else -> ""
|
||||
|
||||
@@ -259,7 +259,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/no_connection_explain"/>
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_number_picker_unit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
|
||||
@@ -24,6 +24,13 @@
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_minus5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_minus_5"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_now"
|
||||
android:layout_width="wrap_content"
|
||||
@@ -32,11 +39,18 @@
|
||||
android:text="@string/dialog_duration_button_now"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_clear"
|
||||
android:id="@+id/dialog_date_duration_asleep"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_clear"/>
|
||||
android:text="@string/dialog_duration_button_asleep"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_plus5"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_plus_5"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?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:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/dialog_number_edittext"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="number"
|
||||
android:hint="0"
|
||||
android:background="@drawable/textview_background"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_number_unit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:text="cm"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -21,7 +21,6 @@
|
||||
android:background="@drawable/textview_background"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_number_unit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
<string name="event_bottle_type" translatable="false">🍼</string>
|
||||
<string name="event_food_type" translatable="false">🥣</string>
|
||||
<string name="event_weight_type" translatable="false">⚖️</string>
|
||||
<string name="event_height_type" translatable="false">📏</string>
|
||||
<string name="event_breastfeeding_left_type" translatable="false">🤱⬅️</string>
|
||||
<string name="event_breastfeeding_both_type" translatable="false">🤱↔️</string>
|
||||
<string name="event_breastfeeding_right_type" translatable="false">🤱➡️️</string>
|
||||
@@ -27,7 +26,6 @@
|
||||
<string name="event_type_item_bottle">🍼 Bottle</string>
|
||||
<string name="event_type_item_food">🥣 Food</string>
|
||||
<string name="event_type_item_weight">⚖️ Weight</string>
|
||||
<string name="event_type_item_height">📏 Height</string>
|
||||
<string name="event_type_item_breastfeeding_left">🤱⬅️ Nursing</string>
|
||||
<string name="event_type_item_breastfeeding_both">🤱↔️ Nursing</string>
|
||||
<string name="event_type_item_breastfeeding_right">🤱➡️️ Nursing</string>
|
||||
@@ -47,7 +45,6 @@
|
||||
<string name="event_bottle_desc">Milk Bottle</string>
|
||||
<string name="event_food_desc">Food</string>
|
||||
<string name="event_weight_desc">Weight</string>
|
||||
<string name="event_height_desc">Height</string>
|
||||
<string name="event_breastfeeding_left_desc">Nursing (left)</string>
|
||||
<string name="event_breastfeeding_both_desc">Nursing (both)</string>
|
||||
<string name="event_breastfeeding_right_desc">Nursing (right)</string>
|
||||
@@ -133,17 +130,14 @@
|
||||
<string name="log_temperature_dialog_description">Select the temperature:</string>
|
||||
<string name="log_unknown_dialog_description"></string>
|
||||
<string name="log_weight_dialog_description">Insert the weight:</string>
|
||||
<string name="log_height_dialog_description">Insert the height:</string>
|
||||
<string name="log_duration_dialog_description">Set duration:</string>
|
||||
<string name="log_sleep_dialog_description">Set sleep duration:</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_height_base_metric" translatable="false">cm</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>
|
||||
<string name="measurement_unit_height_base_imperial" translatable="false">in</string>
|
||||
<string name="measurement_unit_temperature_base_imperial" translatable="false">°F</string>
|
||||
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
||||
|
||||
@@ -166,9 +160,9 @@
|
||||
<string name="dialog_event_detail_notes">Notes</string>
|
||||
<string name="dialog_event_detail_signature">by %s</string>
|
||||
|
||||
<string name="dialog_duration_button_clear">Clear</string>
|
||||
<string name="dialog_duration_button_asleep">asleep</string>
|
||||
<string name="dialog_duration_button_minus_5">-5 min</string>
|
||||
<string name="dialog_duration_button_now">Now</string>
|
||||
<string name="dialog_duration_button_now">now</string>
|
||||
<string name="dialog_duration_button_plus_5">+5 min</string>
|
||||
|
||||
<string name="dialog_add_logbook_title">Add logbook</string>
|
||||
|
||||
Reference in New Issue
Block a user