forked from penguin86/luna-tracker
Compare commits
15 Commits
bottle_tim
...
8e4a5b89c0
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e4a5b89c0 | |||
| 469666cd0f | |||
| 0e980a8c68 | |||
| b1fc3ce890 | |||
| b88b88623e | |||
| 2709050496 | |||
| 5fe383e488 | |||
| 7d480d6e1c | |||
| bbf3b0ce8e | |||
| 38f2a27c38 | |||
| 6d63ad54f2 | |||
| 553e1c351f | |||
| f8f5d68bb6 | |||
| 280d4558ad | |||
| d74310fad5 |
@@ -148,23 +148,19 @@ class MainActivity : AppCompatActivity() {
|
||||
val eventTypeStats = mutableMapOf<LunaEvent.Type, Int>()
|
||||
|
||||
if (dynamicMenu) {
|
||||
// populate frequency map from all events of the last two weeks
|
||||
val lastWeekTime = (System.currentTimeMillis() / 1000) - (14 * 24 * 60 * 60)
|
||||
allEvents.forEach {
|
||||
if (it.time > lastWeekTime) {
|
||||
val sampleSize = 100
|
||||
// populate frequency map from first 100 events
|
||||
allEvents.take(sampleSize.coerceAtMost(allEvents.size)).forEach {
|
||||
eventTypeStats[it.type] = 1 + (eventTypeStats[it.type] ?: 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sort all event types by frequency and ordinal
|
||||
// sort all event types by frequency or ordinal
|
||||
val eventTypesSorted = LunaEvent.Type.entries.toList().sortedWith(
|
||||
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
||||
).filter { it != LunaEvent.Type.UNKNOWN }
|
||||
|
||||
val usedEventCount = eventTypeStats.count { it.value > 0 }
|
||||
val maxButtonCount = if (dynamicMenu) { usedEventCount } else { 7 }
|
||||
|
||||
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)
|
||||
@@ -190,7 +186,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
fun show(vararg tvs: TextView) {
|
||||
for (tv in tvs) {
|
||||
val type = eventTypesSorted[showCounter]
|
||||
val type = sortedEventTypes[showCounter]
|
||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||
tv.setOnClickListener { showCreateDialog(type) }
|
||||
tv.visibility = View.VISIBLE
|
||||
@@ -209,8 +205,15 @@ class MainActivity : AppCompatActivity() {
|
||||
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 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,11 +275,8 @@ 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)
|
||||
val pickedTime = datePickerHelper(event.time, dateTV)
|
||||
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
@@ -314,7 +314,7 @@ class MainActivity : AppCompatActivity() {
|
||||
weightET.setText(event.quantity.toString())
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
val pickedTime = datePickerHelper(event.time, dateTV)
|
||||
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
@@ -365,7 +365,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
val pickedTime = datePickerHelper(event.time, dateTV)
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
}
|
||||
@@ -389,8 +389,7 @@ class MainActivity : AppCompatActivity() {
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
// Pick a date/time.
|
||||
fun dateTimePicker(time: Long, dateTextView: TextView, onChange: (Long) -> Unit = {}): Calendar {
|
||||
fun datePickerHelper(time: Long, dateTextView: TextView, onChange: (Long) -> Unit = {}): Calendar {
|
||||
dateTextView.text = DateUtils.formatDateTime(time)
|
||||
|
||||
val dateTime = Calendar.getInstance()
|
||||
@@ -421,122 +420,89 @@ class MainActivity : AppCompatActivity() {
|
||||
return dateTime
|
||||
}
|
||||
|
||||
fun addDurationEvent(event: LunaEvent) {
|
||||
askDurationEvent(event, true) { saveEvent(event) }
|
||||
fun saveEvent(event: LunaEvent) {
|
||||
if (!allEvents.contains(event)) {
|
||||
// new event
|
||||
logEvent(event)
|
||||
}
|
||||
|
||||
fun askDurationEvent(event: LunaEvent, showTime: Boolean, onPositive: () -> Unit) {
|
||||
logbook?.sort()
|
||||
recyclerView.adapter?.notifyDataSetChanged()
|
||||
saveLogbook()
|
||||
}
|
||||
|
||||
fun addSleepEvent(event: LunaEvent) {
|
||||
askSleepValue(event) { saveEvent(event) }
|
||||
}
|
||||
|
||||
fun askSleepValue(event: LunaEvent, onPositive: () -> Unit) {
|
||||
val d = AlertDialog.Builder(this)
|
||||
val dialogView = layoutInflater.inflate(R.layout.dialog_edit_duration, null)
|
||||
d.setTitle(event.getDialogTitle(this))
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
d.setView(dialogView)
|
||||
|
||||
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 datePicker = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val durationMinus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_minus5)
|
||||
val durationPlus5Button = dialogView.findViewById<Button>(R.id.dialog_date_duration_plus5)
|
||||
|
||||
val currentDurationTextColor = durationTextView.currentTextColor
|
||||
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
||||
|
||||
// in seconds
|
||||
var durationStart = event.getStartTime()
|
||||
var durationEnd = event.getEndTime()
|
||||
var duration = event.quantity
|
||||
|
||||
fun isValidTime(timeUnix: Long): Boolean {
|
||||
fun isValidTime(timeSeconds: Long, durationSeconds: Int): Boolean {
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
return timeUnix in 1..now
|
||||
return (timeSeconds + durationSeconds) <= now && durationSeconds < (12 * 60 * 60)
|
||||
}
|
||||
|
||||
fun isValidTimeSpan(timeBeginUnix: Long, timeEndUnix: Long): Boolean {
|
||||
return (timeBeginUnix <= timeEndUnix) && (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
||||
}
|
||||
|
||||
fun updateFields() {
|
||||
datePickerBegin.text = DateUtils.formatDateTime(durationStart)
|
||||
datePickerEnd.text = DateUtils.formatDateTime(durationEnd)
|
||||
|
||||
val onDateChange = { time: Long ->
|
||||
durationTextView.setTextColor(currentDurationTextColor)
|
||||
val duration = durationEnd - durationStart
|
||||
if (duration == 0L) {
|
||||
// event is ongoing
|
||||
|
||||
if (duration == 0) {
|
||||
// baby is sleeping
|
||||
durationTextView.text = "💤"
|
||||
dateDelimiter.visibility = View.GONE
|
||||
datePickerEnd.visibility = View.GONE
|
||||
} else {
|
||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
||||
if (!isValidTimeSpan(durationStart, durationEnd)) {
|
||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration.toLong())
|
||||
if (!isValidTime(time, duration)) {
|
||||
durationTextView.setTextColor(invalidDurationTextColor)
|
||||
}
|
||||
dateDelimiter.visibility = View.VISIBLE
|
||||
datePickerEnd.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
|
||||
datePickerBegin.setTextColor(if (isValidTime(durationStart)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
datePickerEnd.setTextColor(if (isValidTime(durationEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||
val pickedDateTime = datePickerHelper(event.time, datePicker, onDateChange)
|
||||
|
||||
onDateChange(pickedDateTime.time.time / 1000)
|
||||
|
||||
fun adjust(minutes: Int) {
|
||||
duration += minutes * 60
|
||||
if (duration < 0) {
|
||||
duration = 0
|
||||
}
|
||||
onDateChange(pickedDateTime.time.time / 1000)
|
||||
}
|
||||
|
||||
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { pickedTime: Long ->
|
||||
durationStart = pickedTime
|
||||
if (datePickerEnd.visibility == View.GONE) {
|
||||
durationEnd = pickedTime
|
||||
}
|
||||
updateFields()
|
||||
}
|
||||
|
||||
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { pickedTime: Long ->
|
||||
durationEnd = pickedTime
|
||||
updateFields()
|
||||
}
|
||||
|
||||
if (showTime) {
|
||||
dateDelimiter.visibility = View.GONE
|
||||
datePickerEnd.visibility = View.GONE
|
||||
durationTextView.visibility = View.GONE
|
||||
durationButtons.visibility = View.GONE
|
||||
//d.setMessage("")
|
||||
} else {
|
||||
dateDelimiter.visibility = View.VISIBLE
|
||||
datePickerEnd.visibility = View.VISIBLE
|
||||
durationTextView.visibility = View.VISIBLE
|
||||
durationButtons.visibility = View.VISIBLE
|
||||
d.setMessage(event.getDialogMessage(this))
|
||||
}
|
||||
|
||||
durationStart = pickedDateTimeBegin.time.time / 1000
|
||||
durationEnd = pickedDateTimeEnd.time.time / 1000
|
||||
|
||||
updateFields()
|
||||
|
||||
durationMinus5Button.setOnClickListener {
|
||||
durationEnd = (durationEnd - 300).coerceAtLeast(durationStart)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationPlus5Button.setOnClickListener {
|
||||
durationEnd = (durationEnd + 300).coerceAtLeast(durationStart)
|
||||
updateFields()
|
||||
}
|
||||
|
||||
durationClearButton.setOnClickListener {
|
||||
durationEnd = durationStart
|
||||
updateFields()
|
||||
}
|
||||
durationMinus5Button.setOnClickListener { adjust(-5) }
|
||||
durationPlus5Button.setOnClickListener { adjust(5) }
|
||||
|
||||
durationNowButton.setOnClickListener {
|
||||
durationEnd = System.currentTimeMillis() / 1000
|
||||
updateFields()
|
||||
val now = System.currentTimeMillis() / 1000
|
||||
val start = pickedDateTime.time.time / 1000
|
||||
if (now > start) {
|
||||
duration = (now - start).toInt()
|
||||
duration -= duration % 60 // prevent printing of seconds
|
||||
onDateChange(pickedDateTime.time.time / 1000)
|
||||
}
|
||||
}
|
||||
|
||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||
if (isValidTime(durationStart) && isValidTime(durationEnd) && isValidTimeSpan(durationStart, durationEnd)) {
|
||||
event.time = durationStart
|
||||
event.quantity = (durationEnd - durationStart).toInt()
|
||||
val time = pickedDateTime.time.time / 1000
|
||||
|
||||
if (isValidTime(time, duration)) {
|
||||
event.time = time
|
||||
event.quantity = duration
|
||||
onPositive()
|
||||
} else {
|
||||
Toast.makeText(this, R.string.toast_date_error, Toast.LENGTH_SHORT).show()
|
||||
@@ -553,7 +519,6 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
fun addAmountEvent(event: LunaEvent) {
|
||||
setToPreviousQuantity(event)
|
||||
askAmountValue(event, true) { saveEvent(event) }
|
||||
}
|
||||
|
||||
@@ -570,11 +535,11 @@ class MainActivity : AppCompatActivity() {
|
||||
R.array.AmountLabels,
|
||||
android.R.layout.simple_spinner_dropdown_item
|
||||
)
|
||||
|
||||
// set pre-selected item and ensure the quantity to index is in bounds
|
||||
spinner.setSelection(event.quantity.coerceIn(0, spinner.count - 1))
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
val pickedTime = datePickerHelper(event.time, dateTV)
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
}
|
||||
@@ -607,7 +572,7 @@ class MainActivity : AppCompatActivity() {
|
||||
d.setView(dialogView)
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedDateTime = dateTimePicker(event.time, dateTV)
|
||||
val pickedDateTime = datePickerHelper(event.time, dateTV)
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
}
|
||||
@@ -642,7 +607,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val qtyET = dialogView.findViewById<EditText>(R.id.notes_qty_edittext)
|
||||
|
||||
val dateTV = dialogView.findViewById<TextView>(R.id.dialog_date_picker)
|
||||
val pickedTime = dateTimePicker(event.time, dateTV)
|
||||
val pickedTime = datePickerHelper(event.time, dateTV)
|
||||
|
||||
if (!showTime) {
|
||||
dateTV.visibility = View.GONE
|
||||
@@ -854,7 +819,7 @@ class MainActivity : AppCompatActivity() {
|
||||
quantityTextView.text = NumericUtils(this).formatEventQuantity(event)
|
||||
notesTextView.text = event.notes
|
||||
if (event.type == LunaEvent.Type.SLEEP && event.quantity > 0) {
|
||||
dateEndTextView.text = DateUtils.formatDateTime(event.getEndTime())
|
||||
dateEndTextView.text = DateUtils.formatDateTime(event.time + event.quantity)
|
||||
dateEndTextView.visibility = View.VISIBLE
|
||||
} else {
|
||||
dateEndTextView.visibility = View.GONE
|
||||
@@ -868,7 +833,7 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
updateValues()
|
||||
|
||||
dateTimePicker(event.time, dateTextView, { newTime: Long ->
|
||||
datePickerHelper(event.time, dateTextView, { newTime: Long ->
|
||||
event.time = newTime
|
||||
updateValues()
|
||||
})
|
||||
@@ -882,7 +847,7 @@ class MainActivity : AppCompatActivity() {
|
||||
LunaEvent.Type.PUKE -> askAmountValue(event, false, updateValues)
|
||||
LunaEvent.Type.TEMPERATURE -> askTemperatureValue(event, false, updateValues)
|
||||
LunaEvent.Type.NOTE -> askNotes(event, false, updateValues)
|
||||
LunaEvent.Type.SLEEP -> askDurationEvent(event, false, updateValues)
|
||||
LunaEvent.Type.SLEEP -> askSleepValue(event, updateValues)
|
||||
else -> {
|
||||
Log.w(TAG, "Unexpected type: ${event.type}")
|
||||
}
|
||||
@@ -912,7 +877,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val previousEvent = getPreviousSameEvent(event, allEvents)
|
||||
if (previousEvent != null) {
|
||||
val emoji = previousEvent.getHeaderEmoji(applicationContext)
|
||||
val time = DateUtils.formatTimeDuration(applicationContext, event.getStartTime() - previousEvent.getEndTime())
|
||||
val time = DateUtils.formatTimeDuration(applicationContext, event.time - previousEvent.time)
|
||||
previousTextView.text = String.format("⬅️ %s %s", emoji, time)
|
||||
previousTextView.setOnClickListener {
|
||||
alertDialog.cancel()
|
||||
@@ -927,7 +892,7 @@ class MainActivity : AppCompatActivity() {
|
||||
val nextEvent = getNextSameEvent(event, allEvents)
|
||||
if (nextEvent != null) {
|
||||
val emoji = nextEvent.getHeaderEmoji(applicationContext)
|
||||
val time = DateUtils.formatTimeDuration(applicationContext, nextEvent.getStartTime() - event.getEndTime())
|
||||
val time = DateUtils.formatTimeDuration(applicationContext, nextEvent.time - event.time)
|
||||
nextTextView.text = String.format("%s %s ➡️", time, emoji)
|
||||
nextTextView.setOnClickListener {
|
||||
alertDialog.cancel()
|
||||
@@ -1152,6 +1117,23 @@ class MainActivity : AppCompatActivity() {
|
||||
})
|
||||
}
|
||||
|
||||
fun logEvent(event: LunaEvent) {
|
||||
savingEvent(true)
|
||||
|
||||
event.signature = signature
|
||||
|
||||
setLoading(true)
|
||||
logbook?.logs?.add(0, event)
|
||||
recyclerView.adapter?.notifyItemInserted(0)
|
||||
recyclerView.smoothScrollToPosition(0)
|
||||
saveLogbook(event)
|
||||
|
||||
// Check logbook size to avoid OOM errors
|
||||
if (logbook?.isTooBig() == true) {
|
||||
askToTrimLogbook()
|
||||
}
|
||||
}
|
||||
|
||||
fun deleteEvent(event: LunaEvent) {
|
||||
// Update view
|
||||
savingEvent(true)
|
||||
@@ -1163,32 +1145,6 @@ class MainActivity : AppCompatActivity() {
|
||||
saveLogbook()
|
||||
}
|
||||
|
||||
fun saveEvent(event: LunaEvent) {
|
||||
if (allEvents.contains(event)) {
|
||||
// event was modified
|
||||
logbook?.sort()
|
||||
recyclerView.adapter?.notifyDataSetChanged()
|
||||
saveLogbook()
|
||||
} else {
|
||||
// add new event
|
||||
savingEvent(true)
|
||||
setLoading(true)
|
||||
if (signature.isNotEmpty()) {
|
||||
event.signature = signature
|
||||
}
|
||||
logbook?.logs?.add(0, event)
|
||||
logbook?.sort()
|
||||
recyclerView.adapter?.notifyDataSetChanged()
|
||||
recyclerView.smoothScrollToPosition(0)
|
||||
saveLogbook(event)
|
||||
|
||||
// Check logbook size to avoid OOM errors
|
||||
if (logbook?.isTooBig() == true) {
|
||||
askToTrimLogbook()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the logbook. If saving while adding an event, please specify the event so in case
|
||||
* of error can be removed from the list.
|
||||
@@ -1309,7 +1265,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
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -58,7 +58,12 @@ class LunaEventRecyclerAdapter: RecyclerView.Adapter<LunaEventRecyclerAdapter.Lu
|
||||
LunaEvent.Type.NOTE -> item.notes
|
||||
else -> item.getRowItemTitle(context)
|
||||
}
|
||||
holder.time.text = DateUtils.formatTimeAgo(context, item.getEndTime())
|
||||
val endTime = if (item.type == LunaEvent.Type.SLEEP) {
|
||||
item.quantity + item.time
|
||||
} else {
|
||||
item.time
|
||||
}
|
||||
holder.time.text = DateUtils.formatTimeAgo(context, endTime)
|
||||
var quantityText = numericUtils.formatEventQuantity(item)
|
||||
|
||||
// if the event is weight, show difference with the last one
|
||||
|
||||
@@ -115,18 +115,6 @@ class LunaEvent: Comparable<LunaEvent> {
|
||||
return getDialogMessage(context, type)
|
||||
}
|
||||
|
||||
fun getStartTime(): Long {
|
||||
return time
|
||||
}
|
||||
|
||||
fun getEndTime(): Long {
|
||||
return if (type == Type.SLEEP) {
|
||||
time + quantity
|
||||
} else {
|
||||
time
|
||||
}
|
||||
}
|
||||
|
||||
fun toJson(): JSONObject {
|
||||
return jo
|
||||
}
|
||||
@@ -174,7 +162,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.SLEEP -> R.string.log_duration_dialog_description
|
||||
Type.SLEEP -> R.string.log_sleep_dialog_description
|
||||
else -> R.string.log_unknown_dialog_description
|
||||
}
|
||||
)
|
||||
|
||||
@@ -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()
|
||||
@@ -61,11 +56,11 @@ class DateUtils {
|
||||
return builder.toString()
|
||||
}
|
||||
|
||||
if (years != 0L) {
|
||||
if (years > 0) {
|
||||
return format(years, days, R.string.year_ago, R.string.years_ago, R.string.day_ago, R.string.days_ago)
|
||||
} else if (days != 0L) {
|
||||
} else if (days > 0) {
|
||||
return format(days, hours, R.string.day_ago, R.string.days_ago, R.string.hour_ago, R.string.hours_ago)
|
||||
} else if (hours != 0L) {
|
||||
} else if (hours > 0) {
|
||||
return format(hours, minutes, R.string.hour_ago, R.string.hours_ago, R.string.minute_ago, R.string.minutes_ago)
|
||||
} else {
|
||||
return format(minutes, seconds, R.string.minute_ago, R.string.minute_ago, R.string.second_ago, R.string.seconds_ago)
|
||||
|
||||
5
app/src/main/res/drawable/ic_more.xml
Normal file
5
app/src/main/res/drawable/ic_more.xml
Normal file
@@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M12,8c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,16c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
|
||||
|
||||
</vector>
|
||||
@@ -177,16 +177,15 @@
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="30sp"/>
|
||||
|
||||
<TextView
|
||||
<ImageView
|
||||
android:id="@+id/button_more"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="5dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_weight="0"
|
||||
android:background="@drawable/button_background"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="30sp"
|
||||
android:text="☰"
|
||||
android:src="@drawable/ic_more"
|
||||
app:tint="@android:color/darker_gray"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="gone"
|
||||
android:gravity="center"
|
||||
android:text="@string/statistics_no_data"/>
|
||||
android:text="No Data"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
@@ -32,18 +32,25 @@
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/graph_type_selection"
|
||||
android:id="@+id/type_selection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"/>
|
||||
|
||||
android:gravity="center"
|
||||
android:layout_weight="1" />
|
||||
<!--
|
||||
<Spinner
|
||||
android:id="@+id/time_range_selection"
|
||||
android:id="@+id/data_selection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:gravity="center"/>
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"/>
|
||||
-->
|
||||
<Spinner
|
||||
android:id="@+id/time_selection"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -11,14 +11,12 @@
|
||||
android:id="@+id/dialog_date_duration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textSize="20sp"
|
||||
android:text="💤"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/duration_buttons"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
@@ -29,61 +27,29 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_minus_5"/>
|
||||
android:text="-5"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_now"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_now"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/dialog_date_duration_clear"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/dialog_duration_button_clear"/>
|
||||
android:text="@string/now"/>
|
||||
|
||||
<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"/>
|
||||
android:text="+5"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginHorizontal="10dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker_begin"
|
||||
android:id="@+id/dialog_date_picker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_range_delimiter"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:text="-"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/dialog_date_picker_end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_weight="1"/>
|
||||
|
||||
</LinearLayout>
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="20dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
<string name="event_colic_desc">Blähungskolik</string>
|
||||
<string name="event_unknown_desc"></string>
|
||||
|
||||
<string name="overflow_event_weight">⚖️ Gewicht</string>
|
||||
<string name="overflow_event_medicine">💊 Medikament</string>
|
||||
<string name="overflow_event_enema">🪠 Einlauf</string>
|
||||
<string name="overflow_event_note">📝 Notiz</string>
|
||||
<string name="overflow_event_temperature">🌡️ Temperatur</string>
|
||||
<string name="overflow_event_colic">💨 Blähungskolik</string>
|
||||
|
||||
<string name="toast_event_added">Ereignis gespeichert</string>
|
||||
<string name="toast_logbook_saved">Logbuch gespeichert</string>
|
||||
<string name="toast_event_add_error">Ereignis konnte nicht protokolliert werden</string>
|
||||
@@ -35,6 +42,7 @@
|
||||
<string name="no_connection_retry">Erneut versuchen</string>
|
||||
|
||||
<string name="settings_title">Einstellungen</string>
|
||||
<string name="settings_no_breastfeeding">Kein Stillen</string>
|
||||
<string name="settings_storage">Speicherort für Daten auswählen</string>
|
||||
<string name="settings_storage_local">Auf dem Gerät</string>
|
||||
<string name="settings_storage_local_desc">Datenschutzfreundlichste Lösung: Deine Daten verlassen dein Gerät nicht</string>
|
||||
|
||||
@@ -18,6 +18,13 @@
|
||||
<string name="event_colic_desc">Colique gazeuse</string>
|
||||
<string name="event_unknown_desc"></string>
|
||||
|
||||
<string name="overflow_event_weight">⚖️ Poids</string>
|
||||
<string name="overflow_event_medicine">💊 Médicament</string>
|
||||
<string name="overflow_event_enema">🪠 Lavement</string>
|
||||
<string name="overflow_event_note">📝 Note</string>
|
||||
<string name="overflow_event_temperature">🌡️ Température</string>
|
||||
<string name="overflow_event_colic">💨 Colique gazeuse</string>
|
||||
|
||||
<string name="toast_event_added">Entrée ajoutée</string>
|
||||
<string name="toast_logbook_saved">Journal ajouté</string>
|
||||
<string name="toast_event_add_error">Impossible d\'enregistrer cette entrée</string>
|
||||
|
||||
@@ -3,6 +3,13 @@
|
||||
<string name="title">🌜 LunaTracker 🌛</string>
|
||||
<string name="logbook">Diario di bordo</string>
|
||||
|
||||
<string name="overflow_event_weight">⚖️ Peso</string>
|
||||
<string name="overflow_event_medicine">💊 Medicina</string>
|
||||
<string name="overflow_event_enema">🪠 Clistere</string>
|
||||
<string name="overflow_event_note">📝 Nota</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_food_desc">Cibo</string>
|
||||
<string name="event_weight_desc">Pesata</string>
|
||||
|
||||
@@ -8,21 +8,33 @@
|
||||
</string-array>
|
||||
|
||||
<string-array name="StatisticsTypeLabels">
|
||||
<item>@string/statistics_bottle_sum</item>
|
||||
<item>@string/statistics_bottle_events</item>
|
||||
<item>@string/statistics_sleep_sum</item>
|
||||
<item>@string/statistics_sleep_events</item>
|
||||
<item>@string/statistics_sleep_pattern</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="StatisticsTypeValues">
|
||||
<item>BOTTLE_SUM</item>
|
||||
<item>BOTTLE_EVENTS</item>
|
||||
<item>SLEEP_SUM</item>
|
||||
<item>BOTTLE_SUM</item>
|
||||
<item>BOTTLE_SUM_AVERAGE</item>
|
||||
<item>SLEEP_SUM_AVERAGE</item>
|
||||
<item>SLEEP_EVENTS</item>
|
||||
<item>SLEEP_PATTERN</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="StatisticsTypeValues">
|
||||
<item>BOTTLE_EVENTS</item>
|
||||
<item>BOTTLE_SUM</item>
|
||||
<item>BOTTLE_SUM_AVERAGE</item>
|
||||
<item>SLEEP_SUM_AVERAGE</item>
|
||||
<item>SLEEP_EVENTS</item>
|
||||
<item>SLEEP_PATTERN</item>
|
||||
</string-array>
|
||||
<!--
|
||||
<string-array name="StatisticsDataLabels">
|
||||
<item>Event</item>
|
||||
<item>Amount</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="StatisticsDataValues">
|
||||
<item>EVENT</item>
|
||||
<item>AMOUNT</item>
|
||||
</string-array>
|
||||
-->
|
||||
<string-array name="StatisticsTimeLabels">
|
||||
<item>Day</item>
|
||||
<item>Week</item>
|
||||
@@ -34,4 +46,5 @@
|
||||
<item>WEEK</item>
|
||||
<item>MONTH</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -89,7 +89,6 @@
|
||||
<string name="no_connection_retry">Retry</string>
|
||||
|
||||
<string name="statistics_title">Statistics</string>
|
||||
<string name="statistics_no_data">No Data</string>
|
||||
|
||||
<string name="settings_dynamic_menu">Dynamic Menu</string>
|
||||
<string name="settings_dynamic_menu_desc">Populate the header menu with the most used events.</string>
|
||||
@@ -130,7 +129,7 @@
|
||||
<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_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>
|
||||
@@ -141,13 +140,6 @@
|
||||
<string name="measurement_unit_temperature_base_imperial" translatable="false">°F</string>
|
||||
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
||||
|
||||
<string name="statistics_bottle_events">Bottle Events</string>
|
||||
<string name="statistics_bottle_sum">Bottle Per Day</string>
|
||||
<string name="statistics_medicine_events">Medicine Events</string>
|
||||
<string name="statistics_sleep_sum">Sleep Per Day</string>
|
||||
<string name="statistics_sleep_events">Sleep Events</string>
|
||||
<string name="statistics_sleep_pattern">Sleep Pattern</string>
|
||||
|
||||
<string name="row_luna_event_description">Description</string>
|
||||
<string name="row_luna_event_quantity">Qty</string>
|
||||
<string name="row_luna_event_time">Time</string>
|
||||
@@ -160,11 +152,6 @@
|
||||
<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_minus_5">-5 min</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>
|
||||
<string name="dialog_add_logbook_logbookname">👶 Logbook name</string>
|
||||
<string name="dialog_add_logbook_message">Write a name to identify this logbook. This name will appear on top of the screen and, if you use WebDAV, will be in the save file name as well.</string>
|
||||
|
||||
Reference in New Issue
Block a user