Skip to content

Commit a6021de

Browse files
siddh1004sagarwal
andauthored
1 parent 9575075 commit a6021de

File tree

5 files changed

+117
-10
lines changed

5 files changed

+117
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
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
1718

1819
## 2025.05.20
1920

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

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@ import android.content.Context
55
import android.os.Parcelable
66
import android.util.AttributeSet
77
import android.view.LayoutInflater
8+
import androidx.compose.runtime.getValue
9+
import androidx.compose.runtime.mutableStateOf
10+
import androidx.compose.runtime.setValue
11+
import androidx.compose.ui.platform.ComposeView
12+
import androidx.compose.ui.platform.ViewCompositionStrategy
813
import com.google.android.material.card.MaterialCardView
914
import io.reactivex.Observable
15+
import org.simple.clinic.common.ui.theme.SimpleTheme
1016
import org.simple.clinic.databinding.PatientsummaryAssignedFacilityContentBinding
1117
import org.simple.clinic.di.injector
1218
import org.simple.clinic.facility.Facility
@@ -17,6 +23,7 @@ import org.simple.clinic.navigation.v2.keyprovider.ScreenKeyProvider
1723
import org.simple.clinic.summary.PatientSummaryChildView
1824
import org.simple.clinic.summary.PatientSummaryModelUpdateCallback
1925
import org.simple.clinic.summary.PatientSummaryScreenKey
26+
import org.simple.clinic.summary.assignedfacility.ui.AssignedFacility
2027
import org.simple.clinic.util.unsafeLazy
2128
import javax.inject.Inject
2229

@@ -33,11 +40,7 @@ class AssignedFacilityView(
3340

3441
private var binding: PatientsummaryAssignedFacilityContentBinding? = null
3542

36-
private val assignedFacilityTextView
37-
get() = binding!!.assignedFacilityTextView
38-
39-
private val changeAssignedFacilityButton
40-
get() = binding!!.changeAssignedFacilityButton
43+
private var assignedFacilityName by mutableStateOf("")
4144

4245
init {
4346
val layoutInflater = LayoutInflater.from(context)
@@ -83,9 +86,20 @@ class AssignedFacilityView(
8386
}
8487

8588
context.injector<Injector>().inject(this)
86-
changeAssignedFacilityButton.setOnClickListener {
87-
changeAssignedFacilityClicks?.invoke()
88-
}
89+
90+
addView(ComposeView(context).apply {
91+
setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnDetachedFromWindow)
92+
93+
setContent {
94+
SimpleTheme {
95+
AssignedFacility(
96+
facilityName = assignedFacilityName
97+
) {
98+
changeAssignedFacilityClicks?.invoke()
99+
}
100+
}
101+
}
102+
})
89103
}
90104

91105
override fun onAttachedToWindow() {
@@ -107,7 +121,7 @@ class AssignedFacilityView(
107121
}
108122

109123
override fun renderAssignedFacilityName(facilityName: String) {
110-
assignedFacilityTextView.text = facilityName
124+
assignedFacilityName = facilityName
111125
}
112126

113127
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+
}

common-ui/src/main/java/org/simple/clinic/common/ui/components/Button.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.simple.clinic.common.ui.components
22

33
import androidx.compose.foundation.BorderStroke
4+
import androidx.compose.foundation.layout.PaddingValues
45
import androidx.compose.foundation.layout.RowScope
56
import androidx.compose.foundation.layout.Spacer
67
import androidx.compose.foundation.layout.defaultMinSize
78
import androidx.compose.foundation.layout.fillMaxWidth
89
import androidx.compose.foundation.layout.requiredWidth
10+
import androidx.compose.material.ButtonDefaults
911
import androidx.compose.material.Icon
1012
import androidx.compose.material.ProvideTextStyle
1113
import androidx.compose.material.Text
@@ -30,6 +32,7 @@ fun OutlinedButton(
3032
content: @Composable RowScope.() -> Unit
3133
) {
3234
val minHeight = when (buttonSize) {
35+
ButtonSize.ExtraSmall -> 32.dp
3336
ButtonSize.Small -> 40.dp
3437
ButtonSize.Default -> 48.dp
3538
ButtonSize.Big -> 56.dp
@@ -68,6 +71,7 @@ fun FilledButton(
6871
content: @Composable RowScope.() -> Unit
6972
) {
7073
val minHeight = when (buttonSize) {
74+
ButtonSize.ExtraSmall -> 32.dp
7175
ButtonSize.Small -> 40.dp
7276
ButtonSize.Default -> 48.dp
7377
ButtonSize.Big -> 56.dp
@@ -103,6 +107,7 @@ fun TextButton(
103107
content: @Composable RowScope.() -> Unit
104108
) {
105109
val minHeight = when (buttonSize) {
110+
ButtonSize.ExtraSmall -> 32.dp
106111
ButtonSize.Small -> 40.dp
107112
ButtonSize.Default -> 48.dp
108113
ButtonSize.Big -> 56.dp
@@ -134,6 +139,7 @@ sealed interface ButtonSize {
134139
data object Default : ButtonSize
135140
data object Big : ButtonSize
136141
data object Small : ButtonSize
142+
data object ExtraSmall : ButtonSize
137143
}
138144

139145
@Preview(group = "OutlinedButton")

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ android.experimental.enableTestFixturesKotlinSupport=true
2626
# Manifest URL endpoint
2727
# These are currently the same as the API endpoints declared earlier. Those will be removed later
2828
# once the country selection feature is complete.
29-
manifestEndpoint=https://manifest.simple.org/sandbox/
29+
manifestEndpoint=https://manifest.simple.org/qa/
3030
# Needed to switch NDK versions on the CI server since they have different
3131
# NDK versions on macOS and Linux environments. Gradle plugin 3.6+ requires
3232
# us to pin an NDK version if we package native libs.

0 commit comments

Comments
 (0)