Commit 8b4191b5 authored by Joey's avatar Joey

data: add "deprecated" timeFrame

Used when an insulin is no longer used and we don't want it:
- suggested
- removed

Also sort liveData by timeFrame
Signed-off-by: Joey's avatarJoey <bevilacquajoey@gmail.com>
Change-Id: I8ad11bba2951f5e1f13a62d12e2c735fbfa92f89
parent 7213f2db
......@@ -10,6 +10,7 @@ package it.diab.data.converters
import androidx.room.TypeConverter
import it.diab.data.entities.TimeFrame
import it.diab.data.extensions.toTimeFrame
class TimeFrameConverter {
......@@ -17,13 +18,5 @@ class TimeFrameConverter {
fun toInt(value: TimeFrame?) = (value ?: TimeFrame.EXTRA).toInt()
@TypeConverter
fun toTimeFrame(value: Int?) = when (value) {
0 -> TimeFrame.MORNING
1 -> TimeFrame.LATE_MORNING
2 -> TimeFrame.LUNCH
3 -> TimeFrame.AFTERNOON
4 -> TimeFrame.DINNER
5 -> TimeFrame.NIGHT
else -> TimeFrame.EXTRA
}
fun toTimeFrame(value: Int?) = value?.toTimeFrame() ?: TimeFrame.EXTRA
}
......@@ -22,7 +22,7 @@ import it.diab.data.entities.Insulin
@TypeConverters(TimeFrameConverter::class)
interface InsulinDao {
@get:Query("SELECT * FROM insulin")
@get:Query("SELECT * FROM insulin ORDER BY timeFrame")
val all: DataSource.Factory<Int, Insulin>
@Query("SELECT * FROM insulin")
......
......@@ -75,6 +75,15 @@ enum class TimeFrame {
override val string = R.string.time_night
override val reprHour = 22
override fun toInt() = 5
},
UNUSED {
@DrawableRes
override val icon = R.drawable.ic_time_extra
@StringRes
override val string = R.string.time_unused
override val reprHour = -1
override fun toInt() = 6
};
abstract val icon: Int
......
......@@ -17,5 +17,6 @@ fun Int.toTimeFrame() = when (this) {
3 -> TimeFrame.AFTERNOON
4 -> TimeFrame.DINNER
5 -> TimeFrame.NIGHT
6 -> TimeFrame.UNUSED
else -> TimeFrame.EXTRA
}
......@@ -15,4 +15,5 @@
<string name="time_afternoon">दोपहर</string>
<string name="time_dinner">रात का खाना</string>
<string name="time_night">रात</string>
<string name="time_unused">Unused</string>
</resources>
\ No newline at end of file
......@@ -15,4 +15,5 @@
<string name="time_afternoon">Pomeriggio</string>
<string name="time_dinner">Cena</string>
<string name="time_night">Notte</string>
<string name="time_unused">Non in uso</string>
</resources>
\ No newline at end of file
......@@ -15,4 +15,5 @@
<string name="time_afternoon">Afternoon</string>
<string name="time_dinner">Dinner</string>
<string name="time_night">Night</string>
<string name="time_unused">No longer used</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment