-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MessagesAction Update to also handle non-actionable messages without failing #168
base: main
Are you sure you want to change the base?
Changes from all commits
9db1bea
5ac2d0c
eb49697
1534afd
0768fd1
291e440
47458c1
7bb95e3
411e22a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
package edu.stanford.bdh.engagehf.bluetooth.data.models | ||
|
||
import edu.stanford.bdh.engagehf.messages.Message | ||
import edu.stanford.bdh.engagehf.messages.MessageAction | ||
import edu.stanford.spezi.core.design.R | ||
import java.time.format.DateTimeFormatter | ||
|
||
data class UiState( | ||
val bloodPressure: VitalDisplayData = VitalDisplayData( | ||
|
@@ -13,7 +16,26 @@ | |
title = "Weight", | ||
), | ||
val missingPermissions: Set<String> = emptySet(), | ||
val messages: List<Message> = emptyList(), | ||
val messages: List<MessageUiModel> = emptyList(), | ||
val bluetooth: BluetoothUiState = BluetoothUiState.Idle(), | ||
val measurementDialog: MeasurementDialogUiState = MeasurementDialogUiState(), | ||
) | ||
|
||
data class MessageUiModel( | ||
val message: Message, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrapping the domain message in a ui model still violates why we discussed. Ideally the ui model should remain domain agnostic and only contain properties relevant for UI. It should be created in a UI mapper, e.g. data class MessageUiModel(
val id: String,
val title: String,
val description: String?,
val dueDate: String?,
val isExpanded: Boolean = false,
val isLoading: Boolean = false,
val icon: Int,
)
fun map(message: Message): MessageUiModel {
return MessageUiModel(
id = message.id,
title = message.title,
description = message.description,
dueDate = message.dueDate?.format(DateTimeFormatter.ofPattern("MMM dd, yyyy hh:mm a")),
isExpanded = false,
isLoading = false,
icon = when (message.action) {
is MessageAction.MedicationsAction -> R.drawable.ic_medication
is MessageAction.MeasurementsAction -> R.drawable.ic_vital_signs
is MessageAction.QuestionnaireAction -> R.drawable.ic_assignment
is MessageAction.VideoAction -> R.drawable.ic_visibility
is MessageAction.UnknownAction -> R.drawable.ic_assignment
is MessageAction.HealthSummaryAction -> R.drawable.ic_vital_signs
},
)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fine with this change as well, will do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. mhmmm, okay, so I tried this, but usually when we interact with lower layers (e.g. when dismissing a message or handling an action based on a message), we would usually want the message actually... How would you usually solve this? Mapping back seems to not really solve any issues, since either data is lost or we have an implicit coupling (i.e. we would need to copy the other object property-by-property anyways) After seeing this, I'm actually more in favor of wrapping the model type in the UI-Model, but open to discussions. @eldcn There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The lower layer does not need all the message props, but only the id, action and whether it is dismissable, similarly as you adapted the handler api to process firebase notifications. I see here two ways:
|
||
val isExpanded: Boolean = false, | ||
val isLoading: Boolean = false, | ||
) { | ||
val dueDateFormattedString: String? | ||
get() = message.dueDate?.format(DateTimeFormatter.ofPattern("MMM dd, yyyy hh:mm a")) | ||
|
||
val icon: Int get() = | ||
when (message.action) { | ||
is MessageAction.MedicationsAction -> R.drawable.ic_medication | ||
is MessageAction.MeasurementsAction -> R.drawable.ic_vital_signs | ||
is MessageAction.QuestionnaireAction -> R.drawable.ic_assignment | ||
is MessageAction.VideoAction -> R.drawable.ic_visibility | ||
is MessageAction.UnknownAction -> R.drawable.ic_assignment | ||
is MessageAction.HealthSummaryAction -> R.drawable.ic_vital_signs | ||
} | ||
Check warning on line 40 in app/src/main/kotlin/edu/stanford/bdh/engagehf/bluetooth/data/models/UiState.kt Codecov / codecov/patchapp/src/main/kotlin/edu/stanford/bdh/engagehf/bluetooth/data/models/UiState.kt#L39-L40
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is another error being thrown in the else case. I would propose changing the return type of this method to
MessageAction?
instead of result and update torunCatching { // exisiting logic }.getOrNull()
. No need for NoAction imo as we can represent it with the null caseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed it accordingly