Skip to content

Commit

Permalink
Implement pumping logging
Browse files Browse the repository at this point in the history
  • Loading branch information
MrApplejuice committed Jul 9, 2024
1 parent 178656f commit f70e526
Show file tree
Hide file tree
Showing 8 changed files with 201 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,8 @@ interface ApiInterface {
@POST("feedings/")
@Headers("Content-Type: application/json")
fun sendFeedingEntry(@Body data: JsonNode): Call<FeedingEntry>

@POST("pumping/")
@Headers("Content-Type: application/json")
fun sendPumpingEntry(@Body data: JsonNode): Call<PumpingEntry>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -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<PumpingRecord>(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<String>,
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand All @@ -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
)
Expand Down
100 changes: 100 additions & 0 deletions app/src/main/res/layout/pumping_logging_entry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<FrameLayout
android:id="@+id/sleepIcon"
android:layout_width="48dp"
android:layout_height="0dp"
android:background="@color/pumping_enabled"
android:minHeight="48dp"
android:padding="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHeight_min="48dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter"
android:src="@drawable/pkg_pumping"
android:tintMode="src_in"
android:visibility="visible"
app:tint="@color/fixed_color_button_text_color" />
</FrameLayout>

<TextView
android:id="@+id/currentTimerTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginTop="8dp"
android:layout_weight="0"
android:text="1:10:00"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/sleepIcon"
app:layout_constraintTop_toTopOf="parent">

<EditText
android:id="@+id/noteEditor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="top|left"
android:hint="@string/activity_notes_hint"
android:inputType="textLongMessage|textMultiLine|text"
android:maxLines="5"
android:minLines="1"
android:selectAllOnFocus="false"
android:singleLine="false"
app:layout_constraintTop_toBottomOf="@+id/amountNumberPicker" />


<ImageButton
android:id="@+id/sendButton"
android:layout_width="56dp"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="0"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/noteEditor"
app:srcCompat="@android:drawable/ic_menu_save" />

<TextView
android:id="@+id/amountText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="Amount"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Widget.TextView.SpinnerItem"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<eu.pkgsoftware.babybuddywidgets.widgets.HorizontalDecIncEditor
android:id="@+id/amountNumberPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:visibility="visible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/amountText" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions tools/babybuddy-version-array/versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
v2.5.0
v2.3.0
v2.2.1
v2.1.2
Expand Down

0 comments on commit f70e526

Please sign in to comment.