forked from penguin86/luna-tracker
Compare commits
7 Commits
remove_sta
...
c58c68b78a
| Author | SHA1 | Date | |
|---|---|---|---|
| c58c68b78a | |||
| 4e5c160298 | |||
| da16a50142 | |||
| dd4be8dcd7 | |||
| cb91922e2a | |||
| 24f48cb533 | |||
| 08022541f1 |
@@ -65,4 +65,5 @@ dependencies {
|
|||||||
androidTestImplementation(libs.androidx.ui.test.junit4)
|
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||||
debugImplementation(libs.androidx.ui.tooling)
|
debugImplementation(libs.androidx.ui.tooling)
|
||||||
debugImplementation(libs.androidx.ui.test.manifest)
|
debugImplementation(libs.androidx.ui.test.manifest)
|
||||||
|
implementation(libs.mpandroidchart.vv310)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,10 @@
|
|||||||
android:name=".SettingsActivity"
|
android:name=".SettingsActivity"
|
||||||
android:label="@string/settings_title"
|
android:label="@string/settings_title"
|
||||||
android:theme="@style/Theme.LunaTracker"/>
|
android:theme="@style/Theme.LunaTracker"/>
|
||||||
|
<activity
|
||||||
|
android:name=".StatisticsActivity"
|
||||||
|
android:label="@string/statistics_title"
|
||||||
|
android:theme="@style/Theme.LunaTracker"/>
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -148,19 +148,23 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val eventTypeStats = mutableMapOf<LunaEvent.Type, Int>()
|
val eventTypeStats = mutableMapOf<LunaEvent.Type, Int>()
|
||||||
|
|
||||||
if (dynamicMenu) {
|
if (dynamicMenu) {
|
||||||
val sampleSize = 100
|
// populate frequency map from all events of the last two weeks
|
||||||
// populate frequency map from first 100 events
|
val lastWeekTime = (System.currentTimeMillis() / 1000) - (14 * 24 * 60 * 60)
|
||||||
allEvents.take(sampleSize.coerceAtMost(allEvents.size)).forEach {
|
allEvents.forEach {
|
||||||
|
if (it.time > lastWeekTime) {
|
||||||
eventTypeStats[it.type] = 1 + (eventTypeStats[it.type] ?: 0)
|
eventTypeStats[it.type] = 1 + (eventTypeStats[it.type] ?: 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// sort all event types by frequency and ordinal
|
// sort all event types by frequency and ordinal
|
||||||
val eventTypesSorted = LunaEvent.Type.entries.toList().sortedWith(
|
val eventTypesSorted = LunaEvent.Type.entries.toList().sortedWith(
|
||||||
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
compareBy({ -1 * (eventTypeStats[it] ?: 0) }, { it.ordinal })
|
||||||
).filter { it != LunaEvent.Type.UNKNOWN }
|
).filter { it != LunaEvent.Type.UNKNOWN }
|
||||||
|
|
||||||
fun setupMenu(maxButtonCount: Int, sortedEventTypes: List<LunaEvent.Type>): Int {
|
val usedEventCount = eventTypeStats.count { it.value > 0 }
|
||||||
|
val maxButtonCount = if (dynamicMenu) { usedEventCount } else { 7 }
|
||||||
|
|
||||||
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
val row1 = findViewById<View>(R.id.linear_layout_row1)
|
||||||
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
val row1Button1 = findViewById<TextView>(R.id.button1_row1)
|
||||||
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
val row1Button2 = findViewById<TextView>(R.id.button2_row1)
|
||||||
@@ -186,7 +190,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun show(vararg tvs: TextView) {
|
fun show(vararg tvs: TextView) {
|
||||||
for (tv in tvs) {
|
for (tv in tvs) {
|
||||||
val type = sortedEventTypes[showCounter]
|
val type = eventTypesSorted[showCounter]
|
||||||
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
tv.text = LunaEvent.getHeaderEmoji(applicationContext, type)
|
||||||
tv.setOnClickListener { showCreateDialog(type) }
|
tv.setOnClickListener { showCreateDialog(type) }
|
||||||
tv.visibility = View.VISIBLE
|
tv.visibility = View.VISIBLE
|
||||||
@@ -205,15 +209,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
else -> show(row1Button1, row1Button2, row2Button1, row2Button2, row2Button3, 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 eventsShown = setupMenu(maxButtonCount, eventTypesSorted)
|
|
||||||
|
|
||||||
// store left over events for popup menu
|
// store left over events for popup menu
|
||||||
currentPopupItems = eventTypesSorted.subList(eventsShown, eventTypesSorted.size)
|
currentPopupItems = eventTypesSorted.subList(showCounter, eventTypesSorted.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@@ -434,68 +431,107 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
val durationTextView = dialogView.findViewById<TextView>(R.id.dialog_date_duration)
|
||||||
val datePickerBegin = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
|
val datePickerBegin = dialogView.findViewById<TextView>(R.id.dialog_date_picker_begin)
|
||||||
val datePickerEnd = dialogView.findViewById<TextView>(R.id.dialog_date_picker_end)
|
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 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 = durationTextView.currentTextColor
|
val currentDurationTextColor = durationTextView.currentTextColor
|
||||||
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
val invalidDurationTextColor = ContextCompat.getColor(this, R.color.danger)
|
||||||
|
|
||||||
// in seconds
|
// in seconds
|
||||||
var sleepStart = event.time
|
var sleepStart = event.getStartTime()
|
||||||
var sleepEnd = event.time + event.quantity
|
var sleepEnd = event.getEndTime()
|
||||||
|
|
||||||
|
fun isValidTime(timeUnix: Long): Boolean {
|
||||||
|
val now = System.currentTimeMillis() / 1000
|
||||||
|
return timeUnix in 1..now
|
||||||
|
}
|
||||||
|
|
||||||
fun isValidTimeSpan(timeBeginUnix: Long, timeEndUnix: Long): Boolean {
|
fun isValidTimeSpan(timeBeginUnix: Long, timeEndUnix: Long): Boolean {
|
||||||
val now = System.currentTimeMillis() / 1000
|
return (timeBeginUnix <= timeEndUnix) && (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
||||||
return (timeBeginUnix > 0)
|
|
||||||
&& (timeEndUnix > 0)
|
|
||||||
&& (timeBeginUnix <= timeEndUnix)
|
|
||||||
&& (timeBeginUnix <= now)
|
|
||||||
&& (timeEndUnix <= now)
|
|
||||||
&& (timeEndUnix - timeBeginUnix) < (24 * 60 * 60)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevent printing of seconds
|
fun updateFields() {
|
||||||
fun adjustToMinute(unixTime: Long): Long {
|
datePickerBegin.text = DateUtils.formatDateTime(sleepStart)
|
||||||
return unixTime - (unixTime % 60)
|
datePickerEnd.text = DateUtils.formatDateTime(sleepEnd)
|
||||||
}
|
|
||||||
|
|
||||||
fun updateDuration() {
|
|
||||||
durationTextView.setTextColor(currentDurationTextColor)
|
durationTextView.setTextColor(currentDurationTextColor)
|
||||||
val duration = sleepEnd - sleepStart
|
val duration = sleepEnd - sleepStart
|
||||||
if (duration == 0L) {
|
if (duration == 0L) {
|
||||||
// baby is sleeping
|
// baby is sleeping
|
||||||
durationTextView.text = "💤"
|
durationTextView.text = "💤"
|
||||||
|
dateDelimiter.visibility = View.GONE
|
||||||
|
datePickerEnd.visibility = View.GONE
|
||||||
} else {
|
} else {
|
||||||
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
durationTextView.text = DateUtils.formatTimeDuration(applicationContext, duration)
|
||||||
if (!isValidTimeSpan(sleepStart, sleepEnd)) {
|
if (!isValidTimeSpan(sleepStart, sleepEnd)) {
|
||||||
durationTextView.setTextColor(invalidDurationTextColor)
|
durationTextView.setTextColor(invalidDurationTextColor)
|
||||||
}
|
}
|
||||||
}
|
dateDelimiter.visibility = View.VISIBLE
|
||||||
|
datePickerEnd.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
|
|
||||||
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { time: Long ->
|
datePickerBegin.setTextColor(if (isValidTime(sleepStart)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||||
sleepStart = adjustToMinute(time)
|
datePickerEnd.setTextColor(if (isValidTime(sleepEnd)) { currentDurationTextColor } else { invalidDurationTextColor })
|
||||||
updateDuration()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { time: Long ->
|
val pickedDateTimeBegin = dateTimePicker(event.time, datePickerBegin) { pickedTime: Long ->
|
||||||
sleepEnd = adjustToMinute(time)
|
sleepStart = pickedTime
|
||||||
updateDuration()
|
if (datePickerEnd.visibility == View.GONE) {
|
||||||
|
sleepEnd = pickedTime
|
||||||
|
}
|
||||||
|
updateFields()
|
||||||
}
|
}
|
||||||
|
|
||||||
sleepStart = adjustToMinute(pickedDateTimeBegin.time.time / 1000)
|
val pickedDateTimeEnd = dateTimePicker(event.time + event.quantity, datePickerEnd) { pickedTime: Long ->
|
||||||
sleepEnd = adjustToMinute(pickedDateTimeEnd.time.time / 1000)
|
sleepEnd = pickedTime
|
||||||
updateDuration()
|
updateFields()
|
||||||
|
}
|
||||||
|
|
||||||
if (showTime) {
|
if (showTime) {
|
||||||
|
dateDelimiter.visibility = View.GONE
|
||||||
datePickerEnd.visibility = View.GONE
|
datePickerEnd.visibility = View.GONE
|
||||||
durationTextView.visibility = View.GONE
|
durationTextView.visibility = View.GONE
|
||||||
|
durationButtons.visibility = View.GONE
|
||||||
//d.setMessage("")
|
//d.setMessage("")
|
||||||
} else {
|
} else {
|
||||||
|
dateDelimiter.visibility = View.VISIBLE
|
||||||
|
datePickerEnd.visibility = View.VISIBLE
|
||||||
durationTextView.visibility = View.VISIBLE
|
durationTextView.visibility = View.VISIBLE
|
||||||
|
durationButtons.visibility = View.VISIBLE
|
||||||
d.setMessage(event.getDialogMessage(this))
|
d.setMessage(event.getDialogMessage(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sleepStart = pickedDateTimeBegin.time.time / 1000
|
||||||
|
sleepEnd = pickedDateTimeEnd.time.time / 1000
|
||||||
|
|
||||||
|
updateFields()
|
||||||
|
|
||||||
|
durationMinus5Button.setOnClickListener {
|
||||||
|
sleepEnd = (sleepEnd - 300).coerceAtLeast(sleepStart)
|
||||||
|
updateFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
durationPlus5Button.setOnClickListener {
|
||||||
|
sleepEnd = (sleepEnd + 300).coerceAtLeast(sleepStart)
|
||||||
|
updateFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
durationAsleepButton.setOnClickListener {
|
||||||
|
sleepEnd = sleepStart
|
||||||
|
updateFields()
|
||||||
|
}
|
||||||
|
|
||||||
|
durationNowButton.setOnClickListener {
|
||||||
|
sleepEnd = System.currentTimeMillis() / 1000
|
||||||
|
updateFields()
|
||||||
|
}
|
||||||
|
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i ->
|
||||||
if (isValidTimeSpan(sleepStart, sleepEnd)) {
|
if (isValidTime(sleepStart) && isValidTime(sleepEnd) && isValidTimeSpan(sleepStart, sleepEnd)) {
|
||||||
event.time = sleepStart
|
event.time = sleepStart
|
||||||
event.quantity = (sleepEnd - sleepStart).toInt()
|
event.quantity = (sleepEnd - sleepStart).toInt()
|
||||||
onPositive()
|
onPositive()
|
||||||
@@ -1284,6 +1320,18 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val inflater = LayoutInflater.from(anchor.context)
|
val inflater = LayoutInflater.from(anchor.context)
|
||||||
contentView = inflater.inflate(R.layout.more_events_popup, null)
|
contentView = inflater.inflate(R.layout.more_events_popup, null)
|
||||||
|
|
||||||
|
// Add statistics (hard coded)
|
||||||
|
contentView.findViewById<View>(R.id.button_statistics).setOnClickListener {
|
||||||
|
if (logbook != null && !pauseLogbookUpdate) {
|
||||||
|
val i = Intent(applicationContext, StatisticsActivity::class.java)
|
||||||
|
i.putExtra("LOOGBOOK_NAME", logbook!!.name)
|
||||||
|
startActivity(i)
|
||||||
|
} else {
|
||||||
|
Toast.makeText(applicationContext, "No logbook selected!", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
val linearLayout = contentView.findViewById<LinearLayout>(R.id.layout_list)
|
val linearLayout = contentView.findViewById<LinearLayout>(R.id.layout_list)
|
||||||
|
|
||||||
// Add buttons to create other events
|
// Add buttons to create other events
|
||||||
|
|||||||
@@ -0,0 +1,901 @@
|
|||||||
|
package it.danieleverducci.lunatracker
|
||||||
|
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.View
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.Spinner
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.graphics.toColorInt
|
||||||
|
import com.github.mikephil.charting.animation.ChartAnimator
|
||||||
|
import com.github.mikephil.charting.charts.BarChart
|
||||||
|
import com.github.mikephil.charting.components.YAxis
|
||||||
|
import com.github.mikephil.charting.data.BarData
|
||||||
|
import com.github.mikephil.charting.data.BarDataSet
|
||||||
|
import com.github.mikephil.charting.data.BarEntry
|
||||||
|
import com.github.mikephil.charting.data.Entry
|
||||||
|
import com.github.mikephil.charting.formatter.ValueFormatter
|
||||||
|
import com.github.mikephil.charting.highlight.Highlight
|
||||||
|
import com.github.mikephil.charting.interfaces.dataprovider.BarDataProvider
|
||||||
|
import com.github.mikephil.charting.listener.OnChartValueSelectedListener
|
||||||
|
import com.github.mikephil.charting.renderer.HorizontalBarChartRenderer
|
||||||
|
import com.github.mikephil.charting.utils.ViewPortHandler
|
||||||
|
import it.danieleverducci.lunatracker.entities.LunaEvent
|
||||||
|
import utils.DateUtils
|
||||||
|
import utils.NumericUtils
|
||||||
|
import java.text.SimpleDateFormat
|
||||||
|
import java.util.Calendar
|
||||||
|
import java.util.Date
|
||||||
|
import java.util.Locale
|
||||||
|
import kotlin.math.max
|
||||||
|
import kotlin.math.min
|
||||||
|
|
||||||
|
class StatisticsActivity : AppCompatActivity() {
|
||||||
|
var lastToastShown = 0L
|
||||||
|
|
||||||
|
lateinit var barChart: BarChart
|
||||||
|
lateinit var noDataTextView: TextView
|
||||||
|
lateinit var graphTypeSpinner: Spinner
|
||||||
|
lateinit var timeRangeSpinner: Spinner
|
||||||
|
|
||||||
|
lateinit var unixToSpan: (Long) -> Int
|
||||||
|
lateinit var spanToUnix: (Int) -> Long
|
||||||
|
|
||||||
|
enum class GraphType {
|
||||||
|
BOTTLE_EVENTS,
|
||||||
|
BOTTLE_SUM,
|
||||||
|
SLEEP_SUM,
|
||||||
|
SLEEP_EVENTS,
|
||||||
|
SLEEP_PATTERN
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class TimeRange {
|
||||||
|
DAY,
|
||||||
|
WEEK,
|
||||||
|
MONTH
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
setContentView(R.layout.activity_statistics)
|
||||||
|
|
||||||
|
val logbookName = intent.getStringExtra("LOOGBOOK_NAME")
|
||||||
|
if (logbookName == null) {
|
||||||
|
finish()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
noDataTextView = findViewById(R.id.no_data)
|
||||||
|
|
||||||
|
barChart = findViewById(R.id.bar_chart)
|
||||||
|
barChart.setBackgroundColor(Color.WHITE)
|
||||||
|
barChart.description.text = logbookName
|
||||||
|
barChart.setDrawValueAboveBar(false)
|
||||||
|
|
||||||
|
barChart.axisLeft.setAxisMinimum(0F)
|
||||||
|
barChart.axisLeft.setDrawGridLines(false)
|
||||||
|
barChart.axisLeft.setDrawLabels(false)
|
||||||
|
|
||||||
|
barChart.axisRight.setDrawGridLines(false)
|
||||||
|
barChart.axisRight.setDrawLabels(false)
|
||||||
|
|
||||||
|
barChart.xAxis.setDrawLabels(true)
|
||||||
|
barChart.xAxis.setDrawAxisLine(false)
|
||||||
|
|
||||||
|
barChart.isScaleXEnabled = false
|
||||||
|
barChart.isScaleYEnabled = true
|
||||||
|
|
||||||
|
graphTypeSpinner = findViewById(R.id.graph_type_selection)
|
||||||
|
timeRangeSpinner = findViewById(R.id.time_range_selection)
|
||||||
|
|
||||||
|
setupSpinner(graphTypeSelection.name,
|
||||||
|
R.id.graph_type_selection,
|
||||||
|
R.array.StatisticsTypeLabels,
|
||||||
|
R.array.StatisticsTypeValues,
|
||||||
|
object : SpinnerItemSelected {
|
||||||
|
override fun call(newValue: String?) {
|
||||||
|
//Log.d("event", "new value: $newValue")
|
||||||
|
newValue ?: return
|
||||||
|
graphTypeSelection = GraphType.valueOf(newValue)
|
||||||
|
showGraph()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
setupSpinner(timeRangeSelection.name,
|
||||||
|
R.id.time_range_selection,
|
||||||
|
R.array.StatisticsTimeLabels,
|
||||||
|
R.array.StatisticsTimeValues,
|
||||||
|
object : SpinnerItemSelected {
|
||||||
|
override fun call(newValue: String?) {
|
||||||
|
//Log.d("event", "new value: $newValue")
|
||||||
|
newValue ?: return
|
||||||
|
timeRangeSelection = TimeRange.valueOf(newValue)
|
||||||
|
setSpans()
|
||||||
|
showGraph()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
setSpans()
|
||||||
|
showGraph()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setSpans() {
|
||||||
|
unixToSpan = when (timeRangeSelection) {
|
||||||
|
TimeRange.DAY -> { unix: Long -> unixToDays(unix) }
|
||||||
|
TimeRange.WEEK -> { unix: Long -> unixToWeeks(unix) }
|
||||||
|
TimeRange.MONTH -> { unix: Long -> unixToMonths(unix) }
|
||||||
|
}
|
||||||
|
|
||||||
|
spanToUnix = when (timeRangeSelection) {
|
||||||
|
TimeRange.DAY -> { span: Int -> daysToUnix(span) }
|
||||||
|
TimeRange.WEEK -> { span: Int -> weeksToUnix(span) }
|
||||||
|
TimeRange.MONTH -> { span: Int -> monthsToUnix(span) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class SleepRange(val start: Long, var end: Long)
|
||||||
|
|
||||||
|
fun toSleepRanges(events: List<LunaEvent>): ArrayList<SleepRange> {
|
||||||
|
val ranges = arrayListOf<SleepRange>()
|
||||||
|
val now = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
|
// Transform events into time ranges.
|
||||||
|
// Merge overlapping times and extend
|
||||||
|
// ongoing sleep events until now.
|
||||||
|
var warningShown = false
|
||||||
|
for (event in events) {
|
||||||
|
val startTime = event.time
|
||||||
|
val endTime = if (event.quantity == 0) {
|
||||||
|
now
|
||||||
|
} else {
|
||||||
|
event.time + event.quantity
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle overlap
|
||||||
|
val previousRange = ranges.lastOrNull()
|
||||||
|
if (previousRange != null && previousRange.end > startTime) {
|
||||||
|
// cap previous range to avoid overlap
|
||||||
|
previousRange.end = startTime
|
||||||
|
if (!warningShown) {
|
||||||
|
Toast.makeText(applicationContext, "Overlapping sleep event at ${DateUtils.formatDateTime(startTime)}", Toast.LENGTH_SHORT).show()
|
||||||
|
warningShown = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ranges.add(SleepRange(startTime, endTime))
|
||||||
|
}
|
||||||
|
|
||||||
|
return ranges
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showSleepPatternBarGraphSlotted(state: GraphState) {
|
||||||
|
val ranges = toSleepRanges(state.events)
|
||||||
|
val values = ArrayList<BarEntry>()
|
||||||
|
val stack = ArrayList(List(state.endSpan - state.startSpan + 1) { IntArray(24 * 60 * 60 / SLEEP_PATTERN_GRANULARITY) })
|
||||||
|
|
||||||
|
fun stackValuePattern(index: Int, spanBegin: Long, spanEnd: Long, begin: Long, end: Long) {
|
||||||
|
val beginDays = unixToDays(begin)
|
||||||
|
val endDays = unixToDays(end)
|
||||||
|
var mid = begin
|
||||||
|
|
||||||
|
for (i in beginDays..endDays) {
|
||||||
|
// i is the days/weeks/months since unix epoch
|
||||||
|
val dayBegin = daysToUnix(i)
|
||||||
|
val dayEnd = daysToUnix(i + 1)
|
||||||
|
val sleepBegin = max(mid, dayBegin)
|
||||||
|
val sleepEnd = min(end, dayEnd)
|
||||||
|
|
||||||
|
if (sleepBegin != sleepEnd) {
|
||||||
|
assert(dayBegin <= dayEnd)
|
||||||
|
assert(sleepBegin <= sleepEnd)
|
||||||
|
val iBegin = (sleepBegin - dayBegin) / SLEEP_PATTERN_GRANULARITY
|
||||||
|
val iEnd = iBegin + (sleepEnd - sleepBegin) / SLEEP_PATTERN_GRANULARITY
|
||||||
|
for (j in iBegin..<iEnd) {
|
||||||
|
stack[index][j.toInt()] += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mid = sleepEnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (range in ranges) {
|
||||||
|
// a sleep event can span to another day
|
||||||
|
// distribute sleep time over the days
|
||||||
|
val startUnix = range.start
|
||||||
|
val endUnix = range.end
|
||||||
|
val begIndex = unixToSpan(startUnix)
|
||||||
|
val endIndex = unixToSpan(endUnix)
|
||||||
|
var mid = startUnix
|
||||||
|
|
||||||
|
for (i in begIndex..endIndex) {
|
||||||
|
// i is the days/weeks/months since unix epoch
|
||||||
|
val spanBegin = spanToUnix(i)
|
||||||
|
val spanEnd = spanToUnix(i + 1)
|
||||||
|
val sleepBegin = max(mid, spanBegin)
|
||||||
|
val sleepEnd = min(endUnix, spanEnd)
|
||||||
|
val index = i - state.startSpan
|
||||||
|
val duration = sleepEnd - sleepBegin
|
||||||
|
|
||||||
|
state.dayCounter.setDaysWithData(sleepBegin, sleepEnd)
|
||||||
|
stackValuePattern(index, spanBegin, spanEnd, sleepBegin, sleepEnd)
|
||||||
|
|
||||||
|
mid = sleepEnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun mapColor(occurrences: Int, maxOccurrences: Int): Int {
|
||||||
|
// occurrences: number of reported sleeps in a specific time slot
|
||||||
|
// maxOccurrences: maximum number of days with data that can contribute to maxOccurrences
|
||||||
|
assert(maxOccurrences > 0)
|
||||||
|
assert(occurrences <= maxOccurrences)
|
||||||
|
|
||||||
|
// map to color
|
||||||
|
val q = occurrences.toFloat() / maxOccurrences.toFloat()
|
||||||
|
val i = q * (SLEEP_PATTERN_COLORS.size - 1).toFloat()
|
||||||
|
return SLEEP_PATTERN_COLORS[i.toInt()]
|
||||||
|
}
|
||||||
|
|
||||||
|
val allColors = ArrayList<Int>()
|
||||||
|
|
||||||
|
// convert array of time slots that represent a day to value and color arrays used by chart library
|
||||||
|
for ((index, dayArray) in stack.withIndex()) {
|
||||||
|
val daysWithData = state.dayCounter.countDaysWithData(spanToUnix(state.startSpan + index), spanToUnix(state.startSpan + index + 1))
|
||||||
|
|
||||||
|
val vals = ArrayList<Float>()
|
||||||
|
|
||||||
|
var prevIndex = -1 // time slot index
|
||||||
|
var prevValue = -1 // number of entries we have found for time slot
|
||||||
|
for ((i, v) in dayArray.withIndex()) {
|
||||||
|
if (i == 0) {
|
||||||
|
prevIndex = i
|
||||||
|
prevValue = v
|
||||||
|
} else if (prevValue != v) {
|
||||||
|
vals.add((i - prevIndex).toFloat())
|
||||||
|
allColors.add(mapColor(prevValue.coerceAtMost(daysWithData), daysWithData))
|
||||||
|
prevIndex = i
|
||||||
|
prevValue = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prevIndex != -1) {
|
||||||
|
vals.add((dayArray.size - prevIndex).toFloat())
|
||||||
|
allColors.add(mapColor(prevValue, daysWithData))
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(values.size == index)
|
||||||
|
values.add(BarEntry(values.size.toFloat(), vals.toFloatArray()))
|
||||||
|
}
|
||||||
|
|
||||||
|
barChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener {
|
||||||
|
override fun onValueSelected(e: Entry?, h: Highlight?) {
|
||||||
|
if (e == null || h == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val index = e.x.toInt()
|
||||||
|
if (index !in 0..values.size) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val value = values[index]
|
||||||
|
if (value.yVals == null || h.stackIndex !in 0..value.yVals.size) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lastToastShown + TOAST_FREQUENCY_MS) > System.currentTimeMillis()) {
|
||||||
|
// only show one Toast message after another
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val dayStartUnix = daysToUnix(unixToDays(state.startUnix) + index)
|
||||||
|
|
||||||
|
val startSeconds =
|
||||||
|
SLEEP_PATTERN_GRANULARITY * value.yVals.sliceArray(0..<h.stackIndex)
|
||||||
|
.fold(0) { acc, y -> acc + y.toInt() }
|
||||||
|
val durationSeconds =
|
||||||
|
SLEEP_PATTERN_GRANULARITY * value.yVals[h.stackIndex].toInt()
|
||||||
|
val endSeconds = startSeconds + durationSeconds
|
||||||
|
|
||||||
|
val format = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||||
|
val startTimeString =
|
||||||
|
format.format((dayStartUnix + startSeconds) * 1000).toString()
|
||||||
|
val endTimeString =
|
||||||
|
format.format((dayStartUnix + endSeconds) * 1000).toString()
|
||||||
|
val durationString = DateUtils.formatTimeDuration(applicationContext, durationSeconds.toLong())
|
||||||
|
|
||||||
|
val daysWithData =
|
||||||
|
stack[e.x.toInt()][startSeconds / SLEEP_PATTERN_GRANULARITY]
|
||||||
|
val daysWithDataMax = state.dayCounter.countDaysWithData(
|
||||||
|
spanToUnix(state.startSpan + index),
|
||||||
|
spanToUnix(state.startSpan + index + 1)
|
||||||
|
)
|
||||||
|
|
||||||
|
// percentage of days in this span where baby is asleep in this time slot
|
||||||
|
val pc = if (daysWithDataMax > 0) {
|
||||||
|
(100F * daysWithData.toFloat() / daysWithDataMax.toFloat()).toInt()
|
||||||
|
} else {
|
||||||
|
// no data for this day
|
||||||
|
0
|
||||||
|
}
|
||||||
|
|
||||||
|
Toast.makeText(
|
||||||
|
applicationContext,
|
||||||
|
"$startTimeString - $endTimeString ($durationString) - ${pc}%",
|
||||||
|
Toast.LENGTH_LONG
|
||||||
|
).show()
|
||||||
|
lastToastShown = System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected() {}
|
||||||
|
})
|
||||||
|
|
||||||
|
val set1 = BarDataSet(values, "")
|
||||||
|
set1.colors = allColors
|
||||||
|
set1.setDrawValues(false) // usually too many values
|
||||||
|
set1.isHighlightEnabled = true
|
||||||
|
set1.setDrawIcons(false)
|
||||||
|
|
||||||
|
val data = BarData(set1)
|
||||||
|
data.setValueTextSize(12f)
|
||||||
|
|
||||||
|
val valueCount = min(values.size, 24)
|
||||||
|
barChart.setData(data)
|
||||||
|
barChart.legend.isEnabled = false
|
||||||
|
barChart.setVisibleXRangeMaximum(valueCount.toFloat())
|
||||||
|
barChart.xAxis.setLabelCount(valueCount)
|
||||||
|
barChart.xAxis.setCenterAxisLabels(false)
|
||||||
|
barChart.moveViewTo(data.getEntryCount().toFloat(), 0f, YAxis.AxisDependency.LEFT)
|
||||||
|
barChart.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sleep pattern bars that do not use time slots.
|
||||||
|
// This is useful/nicer for bars that only represent data of a singular days.
|
||||||
|
fun showSleepPatternBarGraphDaily(state: GraphState) {
|
||||||
|
val ranges = toSleepRanges(state.events)
|
||||||
|
val values = ArrayList(List(state.endSpan - state.startSpan + 1) { BarEntry(it.toFloat(), FloatArray(0)) })
|
||||||
|
|
||||||
|
// stack awake/sleep durations
|
||||||
|
fun stackValuePattern(index: Int, spanBegin: Long, spanEnd: Long, begin: Long, end: Long) {
|
||||||
|
assert(begin in spanBegin..spanEnd)
|
||||||
|
assert(end in spanBegin..spanEnd)
|
||||||
|
assert(begin <= end)
|
||||||
|
|
||||||
|
val x = values[index].x
|
||||||
|
val yVals = values[index].yVals // alternating sleep/awake durations
|
||||||
|
val y = yVals.fold(0F) { acc, next -> acc + next }
|
||||||
|
|
||||||
|
// y value is seconds when last awake
|
||||||
|
val awakeDuration = max(begin - spanBegin - y.toLong(), 0L)
|
||||||
|
val sleepDuration = end - begin
|
||||||
|
|
||||||
|
if ((awakeDuration + sleepDuration) > (spanEnd - spanBegin)) {
|
||||||
|
Log.e(TAG, "Invalid sleep duration, exceeds day/week or month bounds => ignore value")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// update value
|
||||||
|
val newYVals = appendToFloatArray(yVals, awakeDuration.toFloat(), sleepDuration.toFloat())
|
||||||
|
assert(index == x.toInt())
|
||||||
|
values[index] = BarEntry(index.toFloat(), newYVals)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (range in ranges) {
|
||||||
|
// a sleep event can span to another day
|
||||||
|
// distribute sleep time over the days
|
||||||
|
val startUnix = range.start
|
||||||
|
val endUnix = range.end
|
||||||
|
val begIndex = unixToSpan(startUnix)
|
||||||
|
val endIndex = unixToSpan(endUnix)
|
||||||
|
var mid = startUnix
|
||||||
|
|
||||||
|
for (i in begIndex..endIndex) {
|
||||||
|
// i is the days/weeks/months since unix epoch
|
||||||
|
val spanBegin = spanToUnix(i)
|
||||||
|
val spanEnd = spanToUnix(i + 1)
|
||||||
|
val sleepBegin = max(mid, spanBegin)
|
||||||
|
val sleepEnd = min(endUnix, spanEnd)
|
||||||
|
val index = i - state.startSpan
|
||||||
|
val duration = sleepEnd - sleepBegin
|
||||||
|
|
||||||
|
state.dayCounter.setDaysWithData(sleepBegin, sleepEnd)
|
||||||
|
stackValuePattern(index, spanBegin, spanEnd, sleepBegin, sleepEnd)
|
||||||
|
|
||||||
|
mid = sleepEnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// awake phase color is transparent
|
||||||
|
val set1 = BarDataSet(values, "")
|
||||||
|
set1.colors = arrayListOf("#00000000".toColorInt(), "#72d7f5".toColorInt())
|
||||||
|
set1.setDrawValues(false) // usually too many values
|
||||||
|
set1.setDrawIcons(false)
|
||||||
|
set1.isHighlightEnabled = true
|
||||||
|
|
||||||
|
barChart.setOnChartValueSelectedListener(object : OnChartValueSelectedListener {
|
||||||
|
override fun onValueSelected(e: Entry?, h: Highlight?) {
|
||||||
|
if (e == null || h == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val index = e.x.toInt()
|
||||||
|
if (index !in 0..values.size) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val value = values[index]
|
||||||
|
if (value.yVals == null || h.stackIndex !in 0..value.yVals.size) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((lastToastShown + TOAST_FREQUENCY_MS) > System.currentTimeMillis()) {
|
||||||
|
// only show one Toast message after another
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val duration = value.yVals[h.stackIndex].toInt()
|
||||||
|
val durationString = DateUtils.formatTimeDuration(applicationContext, duration.toLong())
|
||||||
|
|
||||||
|
val offsetUnix = spanToUnix(state.startSpan + e.x.toInt()) // start of the time span (day/week/month)
|
||||||
|
val startUnix = offsetUnix + value.yVals.sliceArray(0..<h.stackIndex).fold(0) { acc, y -> acc + y.toInt() }
|
||||||
|
val endUnix = startUnix + duration
|
||||||
|
|
||||||
|
val format = SimpleDateFormat("HH:mm", Locale.getDefault())
|
||||||
|
val startTimeString = format.format(startUnix * 1000).toString()
|
||||||
|
val endTimeString = format.format(endUnix * 1000).toString()
|
||||||
|
Toast.makeText(applicationContext, "$startTimeString - $endTimeString ($durationString)", Toast.LENGTH_LONG).show()
|
||||||
|
lastToastShown = System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected() {}
|
||||||
|
})
|
||||||
|
|
||||||
|
val data = BarData(set1)
|
||||||
|
data.setValueTextSize(12f)
|
||||||
|
|
||||||
|
val valueCount = min(values.size, 24)
|
||||||
|
barChart.setData(data)
|
||||||
|
barChart.legend.isEnabled = false
|
||||||
|
barChart.setVisibleXRangeMaximum(valueCount.toFloat())
|
||||||
|
barChart.xAxis.setLabelCount(valueCount)
|
||||||
|
barChart.xAxis.setCenterAxisLabels(false)
|
||||||
|
barChart.moveViewTo(data.getEntryCount().toFloat(), 0f, YAxis.AxisDependency.LEFT)
|
||||||
|
barChart.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the value on the bar is not out of screen.
|
||||||
|
class CustomHorizontalBarChartRenderer(chart: BarDataProvider, animator: ChartAnimator, viewPortHandler: ViewPortHandler): HorizontalBarChartRenderer(chart, animator, viewPortHandler) {
|
||||||
|
override fun drawValue(
|
||||||
|
c: Canvas,
|
||||||
|
valueText: String,
|
||||||
|
x: Float,
|
||||||
|
y: Float,
|
||||||
|
color: Int
|
||||||
|
) {
|
||||||
|
mValuePaint.setColor(color)
|
||||||
|
c.drawText(valueText, x.coerceAtLeast(60F), y, mValuePaint)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showSleepBarGraph(state: GraphState) {
|
||||||
|
val ranges = toSleepRanges(state.events)
|
||||||
|
val values = ArrayList(List(state.endSpan - state.startSpan + 1) { BarEntry(it.toFloat(), 0F) })
|
||||||
|
|
||||||
|
for (range in ranges) {
|
||||||
|
// a sleep event can span to another day
|
||||||
|
// distribute sleep time over the days
|
||||||
|
val startUnix = range.start
|
||||||
|
val endUnix = range.end
|
||||||
|
val begIndex = unixToSpan(startUnix)
|
||||||
|
val endIndex = unixToSpan(endUnix)
|
||||||
|
var mid = startUnix
|
||||||
|
|
||||||
|
for (i in begIndex..endIndex) {
|
||||||
|
// i is the days/weeks/months since unix epoch
|
||||||
|
val spanBegin = spanToUnix(i)
|
||||||
|
val spanEnd = spanToUnix(i + 1)
|
||||||
|
val sleepBegin = max(mid, spanBegin)
|
||||||
|
val sleepEnd = min(endUnix, spanEnd)
|
||||||
|
val index = i - state.startSpan
|
||||||
|
val duration = sleepEnd - sleepBegin
|
||||||
|
|
||||||
|
state.dayCounter.setDaysWithData(sleepBegin, sleepEnd)
|
||||||
|
|
||||||
|
if (graphTypeSelection == GraphType.SLEEP_SUM) {
|
||||||
|
values[index].y += duration.toFloat()
|
||||||
|
} else if (graphTypeSelection == GraphType.SLEEP_EVENTS) {
|
||||||
|
values[index].y += 1F
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "Unexpected graph type.")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
mid = sleepEnd
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index in values.indices) {
|
||||||
|
val daysWithData = state.dayCounter.countDaysWithData(spanToUnix(state.startSpan + index), spanToUnix(state.startSpan + index + 1))
|
||||||
|
if (daysWithData == 0) {
|
||||||
|
assert(values[index].y == 0F)
|
||||||
|
} else {
|
||||||
|
values[index].y /= daysWithData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val set1 = BarDataSet(values, "")
|
||||||
|
set1.setDrawValues(true)
|
||||||
|
set1.setDrawIcons(false)
|
||||||
|
set1.isHighlightEnabled = false
|
||||||
|
|
||||||
|
val data = BarData(set1)
|
||||||
|
data.setValueTextSize(12f)
|
||||||
|
data.setValueFormatter(object : ValueFormatter() {
|
||||||
|
override fun getFormattedValue(value: Float): String {
|
||||||
|
|
||||||
|
val prefix = if (timeRangeSelection == TimeRange.DAY) { "" } else { "⌀ " }
|
||||||
|
return when (graphTypeSelection) {
|
||||||
|
GraphType.SLEEP_EVENTS -> {
|
||||||
|
prefix + value.toInt().toString()
|
||||||
|
}
|
||||||
|
GraphType.SLEEP_SUM -> {
|
||||||
|
prefix + DateUtils.formatTimeDuration(applicationContext, value.toLong())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Log.e(TAG, "unhandled graphTypeSelection $graphTypeSelection")
|
||||||
|
prefix + value.toInt().toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
val valueCount = min(values.size, 24)
|
||||||
|
barChart.renderer = CustomHorizontalBarChartRenderer(barChart, barChart.animator, barChart.viewPortHandler)
|
||||||
|
barChart.setData(data)
|
||||||
|
barChart.legend.isEnabled = false
|
||||||
|
barChart.setVisibleXRangeMaximum(valueCount.toFloat())
|
||||||
|
barChart.xAxis.setLabelCount(valueCount)
|
||||||
|
barChart.xAxis.setCenterAxisLabels(false)
|
||||||
|
barChart.moveViewTo(data.getEntryCount().toFloat(), 0f, YAxis.AxisDependency.LEFT)
|
||||||
|
barChart.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun showBottleBarGraph(state: GraphState) {
|
||||||
|
val values = ArrayList(List(state.endSpan - state.startSpan + 1) { BarEntry(it.toFloat(), 0F) })
|
||||||
|
|
||||||
|
for (event in state.events) {
|
||||||
|
val index = unixToSpan(event.time) - state.startSpan
|
||||||
|
|
||||||
|
state.dayCounter.setDaysWithData(event.time, event.time)
|
||||||
|
|
||||||
|
if (graphTypeSelection == GraphType.BOTTLE_EVENTS) {
|
||||||
|
values[index].y += 1F
|
||||||
|
} else if (graphTypeSelection == GraphType.BOTTLE_SUM) {
|
||||||
|
values[index].y += event.quantity.toFloat()
|
||||||
|
} else {
|
||||||
|
Log.e(TAG, "unhandled graphTypeSelection: $graphTypeSelection")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (index in values.indices) {
|
||||||
|
val daysWithData = state.dayCounter.countDaysWithData(spanToUnix(state.startSpan + index), spanToUnix(state.startSpan + index + 1))
|
||||||
|
if (daysWithData == 0) {
|
||||||
|
assert(values[index].y == 0F)
|
||||||
|
} else {
|
||||||
|
values[index].y /= daysWithData
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val set1 = BarDataSet(values, "")
|
||||||
|
set1.setDrawValues(true)
|
||||||
|
set1.isHighlightEnabled = false
|
||||||
|
|
||||||
|
val data = BarData(set1)
|
||||||
|
data.setValueTextSize(12f)
|
||||||
|
data.setValueFormatter(object : ValueFormatter() {
|
||||||
|
override fun getFormattedValue(value: Float): String {
|
||||||
|
val prefix = if (timeRangeSelection == TimeRange.DAY) { "" } else { "⌀ " }
|
||||||
|
return when (graphTypeSelection) {
|
||||||
|
GraphType.BOTTLE_EVENTS -> {
|
||||||
|
prefix + value.toInt().toString()
|
||||||
|
}
|
||||||
|
GraphType.BOTTLE_SUM -> {
|
||||||
|
prefix + NumericUtils(applicationContext).formatEventQuantity(LunaEvent.Type.BABY_BOTTLE, value.toInt())
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
Log.e(TAG, "unhandled graphTypeSelection")
|
||||||
|
prefix + value.toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
val valueCount = min(values.size, 24)
|
||||||
|
barChart.renderer = CustomHorizontalBarChartRenderer(barChart, barChart.animator, barChart.viewPortHandler)
|
||||||
|
barChart.setData(data)
|
||||||
|
barChart.setVisibleXRangeMaximum(valueCount.toFloat())
|
||||||
|
barChart.xAxis.setLabelCount(valueCount)
|
||||||
|
barChart.xAxis.setCenterAxisLabels(false)
|
||||||
|
barChart.moveViewTo(data.getEntryCount().toFloat(), 0f, YAxis.AxisDependency.LEFT)
|
||||||
|
barChart.invalidate()
|
||||||
|
}
|
||||||
|
|
||||||
|
class DayCounter(val startDays: Int, val stopDays: Int) {
|
||||||
|
val daysWithData = BooleanArray(stopDays - startDays + 1)
|
||||||
|
|
||||||
|
// count days in a span that have data
|
||||||
|
// e.g. return 7 (days) for applied span of a week where there is data for every day
|
||||||
|
fun countDaysWithData(beginUnix: Long, endUnix: Long): Int {
|
||||||
|
val beginDays = unixToDays(beginUnix)
|
||||||
|
val endDays = unixToDays(endUnix)
|
||||||
|
var count = 0
|
||||||
|
for (i in (beginDays - startDays)..<(endDays - startDays)) {
|
||||||
|
count += if (daysWithData[i]) { 1 } else { 0 }
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setDaysWithData(beginUnix: Long, endUnix: Long) {
|
||||||
|
val beginDays = unixToDays(beginUnix)
|
||||||
|
val endDays = unixToDays(endUnix)
|
||||||
|
assert(beginDays <= endDays)
|
||||||
|
assert(startDays <= beginDays)
|
||||||
|
for (i in (beginDays - startDays)..(endDays - startDays)) {
|
||||||
|
daysWithData[i] = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class GraphState(val events: List<LunaEvent>, val dayCounter: DayCounter, val startUnix: Long, val endUnix: Long, val startSpan: Int, val endSpan: Int)
|
||||||
|
|
||||||
|
fun showGraph() {
|
||||||
|
barChart.fitScreen()
|
||||||
|
barChart.data?.clearValues()
|
||||||
|
barChart.xAxis.valueFormatter = null
|
||||||
|
barChart.notifyDataSetChanged()
|
||||||
|
barChart.clear()
|
||||||
|
barChart.invalidate()
|
||||||
|
|
||||||
|
val type = when (graphTypeSelection) {
|
||||||
|
GraphType.BOTTLE_EVENTS,
|
||||||
|
GraphType.BOTTLE_SUM -> LunaEvent.Type.BABY_BOTTLE
|
||||||
|
GraphType.SLEEP_EVENTS,
|
||||||
|
GraphType.SLEEP_SUM,
|
||||||
|
GraphType.SLEEP_PATTERN -> LunaEvent.Type.SLEEP
|
||||||
|
}
|
||||||
|
|
||||||
|
val events = MainActivity.allEvents.filter { it.type == type }.sortedBy { it.time }
|
||||||
|
|
||||||
|
if (events.isEmpty()) {
|
||||||
|
barChart.visibility = View.GONE
|
||||||
|
noDataTextView.visibility = View.VISIBLE
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
barChart.visibility = View.VISIBLE
|
||||||
|
noDataTextView.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
// unix time span of all events
|
||||||
|
val startUnix = events.minOf { it.time }
|
||||||
|
val endUnix = System.currentTimeMillis() / 1000
|
||||||
|
|
||||||
|
// convert to days, weeks or months
|
||||||
|
val startSpan = unixToSpan(startUnix)
|
||||||
|
val endSpan = unixToSpan(endUnix)
|
||||||
|
|
||||||
|
// days when the a day/week/month starts/ends
|
||||||
|
val startDays = unixToDays(spanToUnix(startSpan))
|
||||||
|
val endDays = unixToDays(spanToUnix(endSpan + 1)) // until end of next span
|
||||||
|
val dayCounter = DayCounter(startDays, endDays)
|
||||||
|
|
||||||
|
// print dates
|
||||||
|
barChart.xAxis.valueFormatter = object: ValueFormatter() {
|
||||||
|
override fun getFormattedValue(value: Float): String {
|
||||||
|
val index = value.toInt()
|
||||||
|
val unixSeconds = spanToUnix(startSpan + index)
|
||||||
|
|
||||||
|
val dateTime = Calendar.getInstance()
|
||||||
|
dateTime.time = Date(1000L * unixSeconds)
|
||||||
|
val year = dateTime.get(Calendar.YEAR)
|
||||||
|
val month = dateTime.get(Calendar.MONTH) + 1 // month starts at 0
|
||||||
|
val week = dateTime.get(Calendar.WEEK_OF_YEAR)
|
||||||
|
val day = dateTime.get(Calendar.DAY_OF_MONTH)
|
||||||
|
|
||||||
|
// Adjust years if the first week of a year starts in the previous year.
|
||||||
|
val years = if (month == 12 && week == 1) {
|
||||||
|
year + 1
|
||||||
|
} else {
|
||||||
|
year
|
||||||
|
}
|
||||||
|
|
||||||
|
val days = "%02d".format(day)
|
||||||
|
val weeks = "%02d".format(week)
|
||||||
|
val months = "%02d".format(month)
|
||||||
|
|
||||||
|
return when (timeRangeSelection) {
|
||||||
|
TimeRange.DAY -> "$days/$months/$years"
|
||||||
|
TimeRange.WEEK -> "$weeks/$years"
|
||||||
|
TimeRange.MONTH -> "$months/$years"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val state = GraphState(events, dayCounter, startUnix, endUnix, startSpan, endSpan)
|
||||||
|
|
||||||
|
when (graphTypeSelection) {
|
||||||
|
GraphType.BOTTLE_EVENTS,
|
||||||
|
GraphType.BOTTLE_SUM -> showBottleBarGraph(state)
|
||||||
|
GraphType.SLEEP_EVENTS,
|
||||||
|
GraphType.SLEEP_SUM -> showSleepBarGraph(state)
|
||||||
|
GraphType.SLEEP_PATTERN -> if (timeRangeSelection == TimeRange.DAY) {
|
||||||
|
// specialized pattern bar for daily view (optional)
|
||||||
|
showSleepPatternBarGraphDaily(state)
|
||||||
|
} else {
|
||||||
|
showSleepPatternBarGraphSlotted(state)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface SpinnerItemSelected {
|
||||||
|
fun call(newValue: String?)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun setupSpinner(
|
||||||
|
currentValue: String,
|
||||||
|
spinnerId: Int,
|
||||||
|
arrayId: Int,
|
||||||
|
arrayValuesId: Int,
|
||||||
|
callback: SpinnerItemSelected
|
||||||
|
) {
|
||||||
|
val arrayValues = resources.getStringArray(arrayValuesId)
|
||||||
|
val spinner = findViewById<Spinner>(spinnerId)
|
||||||
|
val spinnerAdapter =
|
||||||
|
ArrayAdapter.createFromResource(this, arrayId, R.layout.statistics_spinner_item)
|
||||||
|
|
||||||
|
spinner.adapter = spinnerAdapter
|
||||||
|
spinner.setSelection(arrayValues.indexOf(currentValue))
|
||||||
|
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||||
|
var check = 0
|
||||||
|
override fun onItemSelected(parent: AdapterView<*>?, view: View?, pos: Int, id: Long) {
|
||||||
|
if (pos >= arrayValues.size) {
|
||||||
|
Toast.makeText(
|
||||||
|
this@StatisticsActivity,
|
||||||
|
"pos out of bounds: $arrayValues", Toast.LENGTH_SHORT
|
||||||
|
).show()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (check++ > 0) {
|
||||||
|
callback.call(arrayValues[pos])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val TAG = "StatisticsActivity"
|
||||||
|
|
||||||
|
// 15 min steps
|
||||||
|
const val SLEEP_PATTERN_GRANULARITY = 15 * 60
|
||||||
|
|
||||||
|
// Time between toast messages (to prevent jams)
|
||||||
|
const val TOAST_FREQUENCY_MS = 3500
|
||||||
|
|
||||||
|
// color gradient
|
||||||
|
val SLEEP_PATTERN_COLORS = arrayOf(
|
||||||
|
"#FFFFFF".toColorInt(), "#EEF5F7".toColorInt(), "#DDEBEF".toColorInt(), "#CCE2E7".toColorInt(),
|
||||||
|
"#BBD8DF".toColorInt(), "#AACED7".toColorInt(), "#99C4CF".toColorInt(), "#88BAC7".toColorInt(),
|
||||||
|
"#77B1BF".toColorInt(), "#66A7B7".toColorInt(), "#559DAF".toColorInt(), "#4493A7".toColorInt(),
|
||||||
|
"#33899F".toColorInt(), "#228097".toColorInt(), "#11768F".toColorInt(), "#006C87".toColorInt()
|
||||||
|
)
|
||||||
|
|
||||||
|
var graphTypeSelection = GraphType.SLEEP_SUM
|
||||||
|
var timeRangeSelection = TimeRange.DAY
|
||||||
|
|
||||||
|
private val dateTime = Calendar.getInstance() // scratch pad
|
||||||
|
|
||||||
|
// convert month to seconds since epoch
|
||||||
|
fun unixToMonths(seconds: Long): Int {
|
||||||
|
dateTime.time = Date(seconds * 1000)
|
||||||
|
val years = dateTime.get(Calendar.YEAR)
|
||||||
|
val months = dateTime.get(Calendar.MONTH)
|
||||||
|
return 12 * years + months
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert month to seconds since epoch
|
||||||
|
fun monthsToUnix(months: Int): Long {
|
||||||
|
dateTime.time = Date(0)
|
||||||
|
dateTime.set(Calendar.YEAR, months / 12)
|
||||||
|
dateTime.set(Calendar.MONTH, months % 12)
|
||||||
|
dateTime.set(Calendar.HOUR, 0)
|
||||||
|
dateTime.set(Calendar.MINUTE, 0)
|
||||||
|
dateTime.set(Calendar.SECOND, 0)
|
||||||
|
return dateTime.time.time / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert seconds to weeks since epoch
|
||||||
|
fun unixToWeeks(seconds: Long): Int {
|
||||||
|
dateTime.time = Date(seconds * 1000)
|
||||||
|
val years = dateTime.get(Calendar.YEAR) - 1970
|
||||||
|
val weeks = dateTime.get(Calendar.WEEK_OF_YEAR)
|
||||||
|
val month = dateTime.get(Calendar.MONTH) + 1 // month starts at 0
|
||||||
|
|
||||||
|
if (month == 12 && weeks == 1) {
|
||||||
|
// The first week if the year might start in the previous year.
|
||||||
|
return 52 * (years + 1) + weeks
|
||||||
|
}
|
||||||
|
|
||||||
|
return 52 * years + weeks
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert weeks to seconds since epoch
|
||||||
|
fun weeksToUnix(weeks: Int): Long {
|
||||||
|
dateTime.time = Date(0)
|
||||||
|
dateTime.set(Calendar.YEAR, 1970 + weeks / 52)
|
||||||
|
dateTime.set(Calendar.WEEK_OF_YEAR, weeks % 52)
|
||||||
|
dateTime.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY)
|
||||||
|
dateTime.set(Calendar.HOUR, 0)
|
||||||
|
dateTime.set(Calendar.MINUTE, 0)
|
||||||
|
dateTime.set(Calendar.SECOND, 0)
|
||||||
|
return dateTime.time.time / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert seconds to days since epoch
|
||||||
|
fun unixToDays(seconds: Long): Int {
|
||||||
|
dateTime.time = Date(seconds * 1000)
|
||||||
|
val years = dateTime.get(Calendar.YEAR)
|
||||||
|
val days = dateTime.get(Calendar.DAY_OF_YEAR)
|
||||||
|
return 365 * years + days
|
||||||
|
}
|
||||||
|
|
||||||
|
// convert days to seconds since epoch
|
||||||
|
fun daysToUnix(days: Int): Long {
|
||||||
|
dateTime.time = Date(0)
|
||||||
|
dateTime.set(Calendar.YEAR, days / 365)
|
||||||
|
dateTime.set(Calendar.DAY_OF_YEAR, days % 365)
|
||||||
|
dateTime.set(Calendar.HOUR, 0)
|
||||||
|
dateTime.set(Calendar.MINUTE, 0)
|
||||||
|
dateTime.set(Calendar.SECOND, 0)
|
||||||
|
return dateTime.time.time / 1000
|
||||||
|
}
|
||||||
|
|
||||||
|
fun appendToFloatArray(array: FloatArray, vararg values: Float): FloatArray {
|
||||||
|
// create new array
|
||||||
|
val newArray = FloatArray(array.size + values.size)
|
||||||
|
// copy old values
|
||||||
|
for (i in array.indices) {
|
||||||
|
newArray[i] = array[i]
|
||||||
|
}
|
||||||
|
// add new values
|
||||||
|
for (i in values.indices) {
|
||||||
|
newArray[array.size + i] = values[i]
|
||||||
|
}
|
||||||
|
return newArray
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debugging
|
||||||
|
fun debugBarValues(values: ArrayList<BarEntry>) {
|
||||||
|
for (value in values) {
|
||||||
|
val yVals = value.yVals
|
||||||
|
if (yVals != null) {
|
||||||
|
val y = yVals.fold(0F) { acc, next -> acc + next }
|
||||||
|
val yVals = yVals.joinToString { it.toString() }
|
||||||
|
Log.d(TAG, "value: ${value.x} $y ($yVals)")
|
||||||
|
} else {
|
||||||
|
Log.d(TAG, "value: ${value.x} ${value.y}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/src/main/res/layout/activity_statistics.xml
Normal file
50
app/src/main/res/layout/activity_statistics.xml
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<?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"
|
||||||
|
android:padding="10dp">
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1">
|
||||||
|
|
||||||
|
<com.github.mikephil.charting.charts.HorizontalBarChart
|
||||||
|
android:id="@+id/bar_chart"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/no_data"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/statistics_no_data"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/graph_type_selection"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/time_range_selection"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
@@ -7,26 +7,83 @@
|
|||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/dialog_date_picker_begin"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_marginTop="10dp"/>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/dialog_date_duration"
|
android:id="@+id/dialog_date_duration"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="20dp"
|
android:layout_marginTop="10dp"
|
||||||
android:textSize="20sp"
|
android:textSize="20sp"
|
||||||
android:text="💤"/>
|
android:text="💤"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/duration_buttons"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
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"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:text="@string/dialog_duration_button_now"/>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
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_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>
|
||||||
|
|
||||||
|
<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: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
|
<TextView
|
||||||
android:id="@+id/dialog_date_picker_end"
|
android:id="@+id/dialog_date_picker_end"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:gravity="center"
|
||||||
android:layout_marginTop="20dp"/>
|
android:layout_weight="1"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -10,7 +10,17 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
<!-- Buttons are inserted dynamically -->
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/button_statistics"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:background="@drawable/dropdown_list_item_background"
|
||||||
|
style="@style/OverflowMenuText"
|
||||||
|
android:text="📊 Statistics"/>
|
||||||
|
|
||||||
|
<!-- Other buttons are inserted dynamically -->
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -6,4 +6,32 @@
|
|||||||
<item>@string/amount_normal</item>
|
<item>@string/amount_normal</item>
|
||||||
<item>@string/amount_plenty</item>
|
<item>@string/amount_plenty</item>
|
||||||
</string-array>
|
</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>SLEEP_EVENTS</item>
|
||||||
|
<item>SLEEP_PATTERN</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="StatisticsTimeLabels">
|
||||||
|
<item>Day</item>
|
||||||
|
<item>Week</item>
|
||||||
|
<item>Month</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="StatisticsTimeValues">
|
||||||
|
<item>DAY</item>
|
||||||
|
<item>WEEK</item>
|
||||||
|
<item>MONTH</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -88,6 +88,9 @@
|
|||||||
<string name="no_connection_go_to_settings">Settings</string>
|
<string name="no_connection_go_to_settings">Settings</string>
|
||||||
<string name="no_connection_retry">Retry</string>
|
<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">Dynamic Menu</string>
|
||||||
<string name="settings_dynamic_menu_desc">Populate the header menu with the most used events.</string>
|
<string name="settings_dynamic_menu_desc">Populate the header menu with the most used events.</string>
|
||||||
<string name="settings_title">Settings</string>
|
<string name="settings_title">Settings</string>
|
||||||
@@ -138,6 +141,13 @@
|
|||||||
<string name="measurement_unit_temperature_base_imperial" translatable="false">°F</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="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_description">Description</string>
|
||||||
<string name="row_luna_event_quantity">Qty</string>
|
<string name="row_luna_event_quantity">Qty</string>
|
||||||
<string name="row_luna_event_time">Time</string>
|
<string name="row_luna_event_time">Time</string>
|
||||||
@@ -150,6 +160,11 @@
|
|||||||
<string name="dialog_event_detail_notes">Notes</string>
|
<string name="dialog_event_detail_notes">Notes</string>
|
||||||
<string name="dialog_event_detail_signature">by %s</string>
|
<string name="dialog_event_detail_signature">by %s</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_plus_5">+5 min</string>
|
||||||
|
|
||||||
<string name="dialog_add_logbook_title">Add logbook</string>
|
<string name="dialog_add_logbook_title">Add logbook</string>
|
||||||
<string name="dialog_add_logbook_logbookname">👶 Logbook name</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>
|
<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>
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ lifecycleRuntimeKtx = "2.6.1"
|
|||||||
activityCompose = "1.8.0"
|
activityCompose = "1.8.0"
|
||||||
composeBom = "2024.04.01"
|
composeBom = "2024.04.01"
|
||||||
appcompat = "1.7.0"
|
appcompat = "1.7.0"
|
||||||
|
mpandroidchart = "v4.2.2"
|
||||||
|
mpandroidchartVersion = "v3.1.0"
|
||||||
recyclerview = "1.3.2"
|
recyclerview = "1.3.2"
|
||||||
material = "1.12.0"
|
material = "1.12.0"
|
||||||
sardineAndroid = "v0.9"
|
sardineAndroid = "v0.9"
|
||||||
@@ -31,6 +33,8 @@ androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit
|
|||||||
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
|
||||||
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
|
||||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||||
|
mpandroidchart = { module = "com.github.PhilJay:MPAndroidChart", version.ref = "mpandroidchart" }
|
||||||
|
mpandroidchart-vv310 = { module = "com.github.PhilJay:MPAndroidChart", version.ref = "mpandroidchartVersion" }
|
||||||
sardine-android = { module = "com.github.thegrizzlylabs:sardine-android", version.ref = "sardineAndroid" }
|
sardine-android = { module = "com.github.thegrizzlylabs:sardine-android", version.ref = "sardineAndroid" }
|
||||||
|
|
||||||
[plugins]
|
[plugins]
|
||||||
|
|||||||
Reference in New Issue
Block a user