diff --git a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/compat/BabyBuddyV2TimerAdapter.kt b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/compat/BabyBuddyV2TimerAdapter.kt index dcb36485..af2b515e 100644 --- a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/compat/BabyBuddyV2TimerAdapter.kt +++ b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/compat/BabyBuddyV2TimerAdapter.kt @@ -15,7 +15,9 @@ import java.util.Locale data class WrappedTimer(val mappedActivityIndex: Int, val timer: Timer) { } -val IMPLEMENTED_ACTIVITIES = listOf(ACTIVITIES.FEEDING, ACTIVITIES.SLEEP, ACTIVITIES.TUMMY_TIME) +val IMPLEMENTED_ACTIVITIES = listOf( + ACTIVITIES.FEEDING, ACTIVITIES.SLEEP, ACTIVITIES.TUMMY_TIME, ACTIVITIES.PUMPING +) class BabyBuddyV2TimerAdapter( val childId: Int, diff --git a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/ApiInterface.kt b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/ApiInterface.kt index 98685669..e5fed181 100644 --- a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/ApiInterface.kt +++ b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/ApiInterface.kt @@ -140,4 +140,8 @@ interface ApiInterface { @POST("feedings/") @Headers("Content-Type: application/json") fun sendFeedingEntry(@Body data: JsonNode): Call + + @POST("pumping/") + @Headers("Content-Type: application/json") + fun sendPumpingEntry(@Body data: JsonNode): Call } diff --git a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/TimeEntries.kt b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/TimeEntries.kt index 641920bf..b45f0e9c 100644 --- a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/TimeEntries.kt +++ b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/networking/babybuddy/models/TimeEntries.kt @@ -113,17 +113,17 @@ data class FeedingEntry( data class PumpingEntry( @JsonProperty("id", required = true) override val id: Int, @JsonProperty("child", required = true) override val childId: Int, - @JsonProperty("start", required = false) @JsonDeserialize(using = DateTimeDeserializer::class) val _start: Date?, - @JsonProperty("end", required = false) @JsonDeserialize(using = DateTimeDeserializer::class) val _end: Date?, - @JsonProperty("notes", required = false) val _notes: String?, + @JsonSetter("start") @JsonDeserialize(using = DateTimeDeserializer::class) val _start: Date?, + @JsonSetter("end") @JsonDeserialize(using = DateTimeDeserializer::class) val _end: Date?, + @JsonSetter("notes") val _notes: String?, @JsonProperty("amount", required = true) val amount: Double, - @JsonProperty("time", required = false) @JsonDeserialize(using = DateTimeDeserializer::class) private val _legacyTime: Date? + @JsonSetter("time") @JsonDeserialize(using = DateTimeDeserializer::class) private val _legacyTime: Date? ) : TimeEntry { override @JsonIgnore val appType: String = ACTIVITIES.PUMPING override @JsonIgnore val appTypeId: Int = ACTIVITIES.index(appType) - override val start: Date = _start ?: _legacyTime!! - override val end: Date = _end ?: _legacyTime!! - override val notes: String = _notes ?: "" + override @get:JsonGetter("start") @JsonSerialize(using = DateTimeSerializer::class) val start: Date = _start ?: _legacyTime!! + override @get:JsonGetter("end") @JsonSerialize(using = DateTimeSerializer::class) val end: Date = _end ?: _legacyTime!! + override @get:JsonGetter("notes") val notes: String = _notes ?: "" } @UIPath("changes") diff --git a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControlInterface.kt b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControlInterface.kt index 84b9313c..73619340 100644 --- a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControlInterface.kt +++ b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControlInterface.kt @@ -1,7 +1,6 @@ package eu.pkgsoftware.babybuddywidgets.timers import eu.pkgsoftware.babybuddywidgets.CredStore.Notes -import eu.pkgsoftware.babybuddywidgets.networking.BabyBuddyClient import eu.pkgsoftware.babybuddywidgets.utils.Promise import eu.pkgsoftware.babybuddywidgets.networking.BabyBuddyClient.Timer diff --git a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControllersV2.kt b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControllersV2.kt index fb39cc39..433d5c39 100644 --- a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControllersV2.kt +++ b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/timers/TimerControllersV2.kt @@ -27,6 +27,7 @@ import eu.pkgsoftware.babybuddywidgets.databinding.DiaperLoggingEntryBinding import eu.pkgsoftware.babybuddywidgets.databinding.FeedingLoggingEntryBinding import eu.pkgsoftware.babybuddywidgets.databinding.GenericTimerLoggingEntryBinding import eu.pkgsoftware.babybuddywidgets.databinding.NoteLoggingEntryBinding +import eu.pkgsoftware.babybuddywidgets.databinding.PumpingLoggingEntryBinding import eu.pkgsoftware.babybuddywidgets.login.Utils import eu.pkgsoftware.babybuddywidgets.networking.BabyBuddyClient import eu.pkgsoftware.babybuddywidgets.networking.BabyBuddyClient.Timer @@ -34,6 +35,7 @@ import eu.pkgsoftware.babybuddywidgets.networking.RequestCodeFailure import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.ChangeEntry import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.FeedingEntry import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.NoteEntry +import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.PumpingEntry import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.SleepEntry import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.TimeEntry import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.models.TummyTimeEntry @@ -42,6 +44,8 @@ import eu.pkgsoftware.babybuddywidgets.networking.babybuddy.nowServer import eu.pkgsoftware.babybuddywidgets.utils.AsyncPromise import eu.pkgsoftware.babybuddywidgets.utils.AsyncPromiseFailure import eu.pkgsoftware.babybuddywidgets.utils.Promise +import eu.pkgsoftware.babybuddywidgets.widgets.HorizontalDecIncEditor +import eu.pkgsoftware.babybuddywidgets.widgets.HorizontalNumberPicker import eu.pkgsoftware.babybuddywidgets.widgets.SwitchButtonLogic import kotlinx.coroutines.Runnable import kotlinx.coroutines.launch @@ -692,6 +696,70 @@ class FeedingLoggingController( } } +@JsonIgnoreProperties(ignoreUnknown = true) +data class PumpingRecord( + @JsonProperty("amount") val amount: Double, + @JsonProperty("note") val note: String, +) + +class PumpingLoggingController( + fragment: BaseFragment, + childId: Int, + timerControl: TimerControlInterface +) : GenericLoggingController(fragment, childId, timerControl, TummyTimeEntry::class) { + val pumpingBinding = PumpingLoggingEntryBinding.inflate(fragment.layoutInflater) + + override val uiCurrentTimerTime = pumpingBinding.currentTimerTime + override val uiNoteEditor = pumpingBinding.noteEditor + override val saveButton: ImageButton = pumpingBinding.sendButton + override val controlsView: View = pumpingBinding.root + + val amountNumberPicker: HorizontalDecIncEditor = pumpingBinding.amountNumberPicker + + override fun postInit() { + super.postInit() + + amountNumberPicker.allowNull = false + amountNumberPicker.value = 0.0 + + fragment.mainActivity.storage.child(childId, "pumping")?.let { + amountNumberPicker.value = it.amount + uiNoteEditor.setText(it.note) + } + + updateVisuals() + } + + override fun storeStateForSuspend() { + val pr = PumpingRecord( + pumpingBinding.amountNumberPicker.value?.toDouble() ?: 0.0, + pumpingBinding.noteEditor.text.toString() + ) + fragment.mainActivity.storage.child(childId, "pumping", pr) + } + + override fun reset() { + pumpingBinding.amountNumberPicker.value = null + pumpingBinding.noteEditor.setText("") + storeStateForSuspend() + } + + override suspend fun createEntry(timer: Timer): TimeEntry { + return fragment.mainActivity.client.v2client.createEntry( + PumpingEntry::class, + PumpingEntry( + id = 0, + childId = childId, + _start = timer.start, + _end = nowServer(), + amount = amountNumberPicker.value!!.toDouble(), + _notes = uiNoteEditor.text.toString(), + _legacyTime = timer.start + ) + ) + } +} + @JsonIgnoreProperties(ignoreUnknown = true) data class LoggingButtonControllerStoreState( @JsonProperty("open_state") val openState: Array, @@ -737,6 +805,9 @@ class LoggingButtonController( BabyBuddyClient.ACTIVITIES.FEEDING to FeedingLoggingController( fragment, child.id, timerControl ), + BabyBuddyClient.ACTIVITIES.PUMPING to PumpingLoggingController( + fragment, child.id, timerControl + ), ) private var timerHandler: Handler? = Handler(fragment.mainActivity.mainLooper) diff --git a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/widgets/HorizontalDecIncEditor.kt b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/widgets/HorizontalDecIncEditor.kt index cd43d14d..41527be3 100644 --- a/app/src/main/java/eu/pkgsoftware/babybuddywidgets/widgets/HorizontalDecIncEditor.kt +++ b/app/src/main/java/eu/pkgsoftware/babybuddywidgets/widgets/HorizontalDecIncEditor.kt @@ -18,7 +18,13 @@ class HorizontalDecIncEditor : LinearLayout { } set(value) { val v = value?.let { - if (it < 0) null else it + if (it < 0) { + if (allowNull) { + return@let null + } + return@let 0.0 + } + it } if (v == null) { binding.numberEditor.setText("") @@ -27,6 +33,14 @@ class HorizontalDecIncEditor : LinearLayout { } } + var allowNull: Boolean = true + set(value) { + field = value + if (!value && this.value == null) { + this.value = 0.0 + } + } + val binding = HorizontalDecIncEditorBinding.inflate( LayoutInflater.from(context), this, true ) diff --git a/app/src/main/res/layout/pumping_logging_entry.xml b/app/src/main/res/layout/pumping_logging_entry.xml new file mode 100644 index 00000000..d85b4f50 --- /dev/null +++ b/app/src/main/res/layout/pumping_logging_entry.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tools/babybuddy-version-array/versions b/tools/babybuddy-version-array/versions index 72df6376..ba820762 100644 --- a/tools/babybuddy-version-array/versions +++ b/tools/babybuddy-version-array/versions @@ -1,3 +1,4 @@ +v2.5.0 v2.3.0 v2.2.1 v2.1.2