forked from penguin86/luna-tracker
Fix time display after manual duration correction
When a timer (sleep/breastfeeding) was forgotten and the duration is manually corrected, the "X minutes ago" display now reflects the adjusted end time instead of the original stop time.
This commit is contained in:
@@ -695,12 +695,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
)
|
)
|
||||||
picker.minValue = 1
|
picker.minValue = 1
|
||||||
picker.maxValue = if (isSleep) 180 else 60
|
picker.maxValue = if (isSleep) 180 else 60
|
||||||
|
val oldQuantity = event.quantity
|
||||||
picker.value = if (event.quantity > 0) Math.min(event.quantity, picker.maxValue) else if (isSleep) 30 else 15
|
picker.value = if (event.quantity > 0) Math.min(event.quantity, picker.maxValue) else if (isSleep) 30 else 15
|
||||||
|
|
||||||
pickerDialog.setTitle(if (isSleep) R.string.sleep_duration_title else R.string.breastfeeding_duration_title)
|
pickerDialog.setTitle(if (isSleep) R.string.sleep_duration_title else R.string.breastfeeding_duration_title)
|
||||||
pickerDialog.setView(pickerView)
|
pickerDialog.setView(pickerView)
|
||||||
pickerDialog.setPositiveButton(android.R.string.ok) { _, _ ->
|
pickerDialog.setPositiveButton(android.R.string.ok) { _, _ ->
|
||||||
event.quantity = picker.value
|
val newQuantity = picker.value
|
||||||
|
if (newQuantity != oldQuantity) {
|
||||||
|
// Adjust end time based on duration change (duration reduced = end time earlier)
|
||||||
|
event.time = event.time - (oldQuantity - newQuantity) * 60L
|
||||||
|
event.quantity = newQuantity
|
||||||
|
}
|
||||||
quantityTextView.text = NumericUtils(this@MainActivity).formatEventQuantity(event)
|
quantityTextView.text = NumericUtils(this@MainActivity).formatEventQuantity(event)
|
||||||
recyclerView.adapter?.notifyDataSetChanged()
|
recyclerView.adapter?.notifyDataSetChanged()
|
||||||
saveLogbook()
|
saveLogbook()
|
||||||
|
|||||||
Reference in New Issue
Block a user