Skip to content

Commit 765dc2b

Browse files
Merge pull request #5462 from simpledotorg/master
2 parents a9cc1b1 + d8e1ff8 commit 765dc2b

File tree

13 files changed

+493
-281
lines changed

13 files changed

+493
-281
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
- Migrate blood pressure summary view to Jetpack Compose
1515
- Migrate blood sugar summary view to Jetpack Compose
1616
- Migrate medical history summary view to Jetpack Compose
17+
- Migrate assigned facility view to Jetpack Compose
18+
- Migrate next appointment view to Jetpack Compose
19+
- Migrate patient status view to Jetpack Compose
1720

1821
## 2025.05.20
1922

app/src/main/java/org/simple/clinic/summary/PatientSummaryScreen.kt

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ import androidx.compose.runtime.mutableStateOf
1616
import androidx.compose.runtime.setValue
1717
import androidx.compose.ui.Modifier
1818
import androidx.compose.ui.platform.ViewCompositionStrategy
19+
import androidx.compose.ui.res.dimensionResource
20+
import androidx.compose.ui.res.painterResource
21+
import androidx.compose.ui.res.stringResource
1922
import androidx.compose.ui.unit.dp
2023
import androidx.dynamicanimation.animation.DynamicAnimation
2124
import androidx.transition.AutoTransition
@@ -77,6 +80,7 @@ import org.simple.clinic.util.messagesender.WhatsAppMessageSender
7780
import org.simple.clinic.util.setFragmentResultListener
7881
import org.simple.clinic.util.toLocalDateAtZone
7982
import org.simple.clinic.widgets.UiEvent
83+
import org.simple.clinic.widgets.compose.PatientStatusView
8084
import org.simple.clinic.widgets.hideKeyboard
8185
import org.simple.clinic.widgets.scrollToChild
8286
import org.simple.clinic.widgets.spring
@@ -147,17 +151,14 @@ class PatientSummaryScreen :
147151
private val doneButtonFrame
148152
get() = binding.doneButtonFrame
149153

150-
private val patientDiedStatusView
151-
get() = binding.patientDiedStatusView
152-
153154
private val nextAppointmentFacilityView
154155
get() = binding.nextAppointmentFacilityView
155156

156157
private val clinicalDecisionSupportAlertView
157158
get() = binding.clinicalDecisionSupportBpHighAlert.rootView
158159

159-
private val statinComposeView
160-
get() = binding.statinComposeView
160+
private val composeView
161+
get() = binding.composeView
161162

162163
@Inject
163164
lateinit var router: Router
@@ -197,6 +198,8 @@ class PatientSummaryScreen :
197198

198199
private var statinInfo by mutableStateOf(StatinInfo.default())
199200

201+
private var showPatientDiedStatusView by mutableStateOf(false)
202+
200203
override fun defaultModel(): PatientSummaryModel {
201204
return PatientSummaryModel.from(screenKey.intention, screenKey.patientUuid)
202205
}
@@ -295,7 +298,7 @@ class PatientSummaryScreen :
295298

296299
subscriptions.add(setupChildViewVisibility())
297300

298-
statinComposeView.apply {
301+
composeView.apply {
299302
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed)
300303
setContent {
301304
SimpleTheme {
@@ -308,6 +311,18 @@ class PatientSummaryScreen :
308311
addBMIClick = { additionalEvents.notify(AddBMIClicked) },
309312
addCholesterol = { additionalEvents.notify(AddCholesterolClicked) }
310313
)
314+
315+
if (showPatientDiedStatusView) {
316+
PatientStatusView(
317+
modifier = Modifier.padding(
318+
start = dimensionResource(R.dimen.spacing_8),
319+
end = dimensionResource(R.dimen.spacing_8),
320+
top = dimensionResource(R.dimen.spacing_8),
321+
),
322+
text = stringResource(R.string.patient_status_died),
323+
icon = painterResource(R.drawable.ic_patient_dead_32dp)
324+
)
325+
}
311326
}
312327
}
313328
}
@@ -708,11 +723,11 @@ class PatientSummaryScreen :
708723
}
709724

710725
override fun hidePatientDiedStatus() {
711-
patientDiedStatusView.visibility = GONE
726+
showPatientDiedStatusView = false
712727
}
713728

714729
override fun showPatientDiedStatus() {
715-
patientDiedStatusView.visibility = VISIBLE
730+
showPatientDiedStatusView = true
716731
}
717732

718733
override fun showNextAppointmentCard() {

app/src/main/java/org/simple/clinic/summary/assignedfacility/AssignedFacilityView.kt

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ import android.annotation.SuppressLint
44
import android.content.Context
55
import android.os.Parcelable
66
import android.util.AttributeSet
7-
import android.view.LayoutInflater
7+
import androidx.compose.runtime.getValue
8+
import androidx.compose.runtime.mutableStateOf
9+
import androidx.compose.runtime.setValue
10+
import androidx.compose.ui.platform.ComposeView
11+
import androidx.compose.ui.platform.ViewCompositionStrategy
812
import com.google.android.material.card.MaterialCardView
913
import io.reactivex.Observable
10-
import org.simple.clinic.databinding.PatientsummaryAssignedFacilityContentBinding
14+
import org.simple.clinic.common.ui.theme.SimpleTheme
1115
import org.simple.clinic.di.injector
1216
import org.simple.clinic.facility.Facility
1317
import org.simple.clinic.mobius.DeferredEventSource
@@ -17,6 +21,7 @@ import org.simple.clinic.navigation.v2.keyprovider.ScreenKeyProvider
1721
import org.simple.clinic.summary.PatientSummaryChildView
1822
import org.simple.clinic.summary.PatientSummaryModelUpdateCallback
1923
import org.simple.clinic.summary.PatientSummaryScreenKey
24+
import org.simple.clinic.summary.assignedfacility.ui.AssignedFacility
2025
import org.simple.clinic.util.unsafeLazy
2126
import javax.inject.Inject
2227

@@ -31,18 +36,7 @@ class AssignedFacilityView(
3136
var changeAssignedFacilityClicks: ChangeAssignedFacilityClicked? = null
3237
var assignedFacilityChanges: AssignedFacilityChanges? = null
3338

34-
private var binding: PatientsummaryAssignedFacilityContentBinding? = null
35-
36-
private val assignedFacilityTextView
37-
get() = binding!!.assignedFacilityTextView
38-
39-
private val changeAssignedFacilityButton
40-
get() = binding!!.changeAssignedFacilityButton
41-
42-
init {
43-
val layoutInflater = LayoutInflater.from(context)
44-
binding = PatientsummaryAssignedFacilityContentBinding.inflate(layoutInflater, this, true)
45-
}
39+
private var assignedFacilityName by mutableStateOf("")
4640

4741
@Inject
4842
lateinit var router: Router
@@ -83,9 +77,20 @@ class AssignedFacilityView(
8377
}
8478

8579
context.injector<Injector>().inject(this)
86-
changeAssignedFacilityButton.setOnClickListener {
87-
changeAssignedFacilityClicks?.invoke()
88-
}
80+
81+
addView(ComposeView(context).apply {
82+
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
83+
84+
setContent {
85+
SimpleTheme {
86+
AssignedFacility(
87+
facilityName = assignedFacilityName
88+
) {
89+
changeAssignedFacilityClicks?.invoke()
90+
}
91+
}
92+
}
93+
})
8994
}
9095

9196
override fun onAttachedToWindow() {
@@ -107,7 +112,7 @@ class AssignedFacilityView(
107112
}
108113

109114
override fun renderAssignedFacilityName(facilityName: String) {
110-
assignedFacilityTextView.text = facilityName
115+
assignedFacilityName = facilityName
111116
}
112117

113118
override fun registerSummaryModelUpdateCallback(callback: PatientSummaryModelUpdateCallback?) {
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package org.simple.clinic.summary.assignedfacility.ui
2+
3+
import androidx.compose.foundation.layout.Arrangement
4+
import androidx.compose.foundation.layout.Column
5+
import androidx.compose.foundation.layout.Row
6+
import androidx.compose.foundation.layout.offset
7+
import androidx.compose.foundation.layout.padding
8+
import androidx.compose.material.Card
9+
import androidx.compose.material.MaterialTheme
10+
import androidx.compose.material.Text
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Alignment
13+
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.res.dimensionResource
15+
import androidx.compose.ui.res.stringResource
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import org.simple.clinic.R
18+
import org.simple.clinic.common.ui.components.ButtonSize
19+
import org.simple.clinic.common.ui.components.TextButton
20+
import org.simple.clinic.common.ui.theme.SimpleTheme
21+
22+
@Composable
23+
fun AssignedFacility(
24+
modifier: Modifier = Modifier,
25+
facilityName: String,
26+
onChangeClick: () -> Unit,
27+
) {
28+
Card(
29+
modifier = modifier,
30+
backgroundColor = MaterialTheme.colors.surface
31+
)
32+
{
33+
Column(
34+
modifier = Modifier.padding(
35+
start = dimensionResource(R.dimen.spacing_16),
36+
bottom = dimensionResource(R.dimen.spacing_12)
37+
)
38+
) {
39+
40+
Row(
41+
modifier = Modifier.padding(
42+
top = dimensionResource(R.dimen.spacing_4),
43+
end = dimensionResource(R.dimen.spacing_8)
44+
),
45+
verticalAlignment = Alignment.CenterVertically,
46+
horizontalArrangement = Arrangement.spacedBy(dimensionResource(R.dimen.spacing_8))
47+
) {
48+
Text(
49+
modifier = Modifier.weight(1f),
50+
text = stringResource(R.string.assigned_facility_view_title),
51+
style = SimpleTheme.typography.subtitle1Medium,
52+
color = MaterialTheme.colors.onSurface,
53+
)
54+
55+
TextButton(
56+
buttonSize = ButtonSize.ExtraSmall,
57+
onClick = onChangeClick
58+
) {
59+
Text(
60+
text = stringResource(R.string.assigned_facility_view_change).uppercase(),
61+
style = MaterialTheme.typography.button,
62+
)
63+
}
64+
}
65+
66+
Text(
67+
modifier = Modifier
68+
.offset(y = (-dimensionResource(R.dimen.spacing_4)))
69+
.padding(end = dimensionResource(R.dimen.spacing_16)),
70+
text = facilityName,
71+
style = MaterialTheme.typography.body1,
72+
color = MaterialTheme.colors.onSurface,
73+
)
74+
}
75+
}
76+
}
77+
78+
@Preview
79+
@Composable
80+
fun AssignedFacilityPreview(modifier: Modifier = Modifier) {
81+
SimpleTheme {
82+
AssignedFacility(
83+
facilityName = "UHC Khardi"
84+
) { }
85+
}
86+
}

0 commit comments

Comments
 (0)