Skip to content

Commit 2cc553c

Browse files
mmmateosBalcan
authored andcommitted
fix: add options for boolean valueType and orientation
Signed-off-by: Manu Muñoz <[email protected]>
1 parent 142ad30 commit 2cc553c

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/SearchParametersScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ fun SearchParametersScreen(
269269
),
270270
)
271271
},
272+
resourceManager = resourceManager,
272273
),
273274
// TODO is this always the same string?, check if it is optional somewhere
274275
helperText = resourceManager.getString(R.string.optional),

app/src/main/java/org/dhis2/usescases/searchTrackEntity/searchparameters/mapper/ParameterInputModelMapper.kt

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ import androidx.compose.runtime.getValue
77
import androidx.compose.runtime.remember
88
import androidx.compose.ui.graphics.Color
99
import androidx.paging.compose.collectAsLazyPagingItems
10+
import com.google.common.primitives.Booleans
11+
import org.dhis2.commons.resources.ResourceManager
12+
import org.dhis2.form.R
1013
import org.dhis2.form.model.FieldUiModel
14+
import org.dhis2.form.model.OptionSetConfiguration
1115
import org.dhis2.form.model.PeriodSelector
1216
import org.dhis2.form.model.UiRenderType
1317
import org.dhis2.tracker.ui.input.model.TrackerInputModel
@@ -16,11 +20,13 @@ import org.dhis2.tracker.ui.input.model.TrackerOptionItem
1620
import org.dhis2.tracker.ui.input.model.TrackerOptionSetConfiguration
1721
import org.hisp.dhis.android.core.common.ValueType
1822
import org.hisp.dhis.mobile.ui.designsystem.component.LegendData
23+
import org.hisp.dhis.mobile.ui.designsystem.component.Orientation
1924

2025
@Composable
2126
fun FieldUiModel.toParameterInputModel(
2227
onValueChange: (String?) -> Unit,
2328
fetchOptions: () -> Unit,
29+
resourceManager: ResourceManager,
2430
): TrackerInputModel {
2531
val trackerInputType =
2632
when {
@@ -60,8 +66,12 @@ fun FieldUiModel.toParameterInputModel(
6066
popUpLegendDescriptionData = it.legendsInfo,
6167
)
6268
},
69+
orientation = renderingType.getOrientation(),
6370
optionSetConfiguration =
64-
optionSetConfiguration?.toTrackerOptionSetConfiguration(fetchOptions),
71+
when (valueType) {
72+
ValueType.BOOLEAN -> getBooleanOptionConfiguration(resourceManager)
73+
else -> optionSetConfiguration?.toTrackerOptionSetConfiguration(fetchOptions)
74+
},
6575
onItemClick = { onItemClick() },
6676
onValueChange = onValueChange,
6777
)
@@ -174,3 +184,27 @@ private fun getInputTypeByValueType(
174184
null,
175185
-> TrackerInputType.NOT_SUPPORTED
176186
}
187+
188+
private fun UiRenderType?.getOrientation(): Orientation =
189+
when (this) {
190+
UiRenderType.HORIZONTAL_CHECKBOXES,
191+
UiRenderType.HORIZONTAL_RADIOBUTTONS,
192+
-> Orientation.HORIZONTAL
193+
194+
else -> Orientation.VERTICAL
195+
}
196+
197+
private fun getBooleanOptionConfiguration(resourceManager: ResourceManager) =
198+
TrackerOptionSetConfiguration(
199+
options =
200+
listOf(
201+
TrackerOptionItem(
202+
true.toString(),
203+
resourceManager.getString(R.string.yes),
204+
),
205+
TrackerOptionItem(
206+
false.toString(),
207+
resourceManager.getString(R.string.no),
208+
),
209+
),
210+
)

tracker/src/commonMain/kotlin/org/dhis2/tracker/search/ui/provider/TrackerCheckboxInputProvider.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import org.dhis2.tracker.ui.input.model.supportingText
88
import org.hisp.dhis.mobile.ui.designsystem.component.CheckBoxData
99
import org.hisp.dhis.mobile.ui.designsystem.component.InputCheckBox
1010
import org.hisp.dhis.mobile.ui.designsystem.component.InputStyle
11-
import org.hisp.dhis.mobile.ui.designsystem.component.Orientation
1211

1312
@Composable
1413
fun TrackerCheckboxInputProvider(
@@ -40,7 +39,7 @@ fun TrackerCheckboxInputProvider(
4039
inputStyle = inputStyle,
4140
title = model.label,
4241
checkBoxData = data,
43-
orientation = Orientation.VERTICAL,
42+
orientation = model.orientation,
4443
state = model.inputState(),
4544
supportingText = model.supportingText(),
4645
legendData = model.legend,

tracker/src/commonMain/kotlin/org/dhis2/tracker/search/ui/provider/TrackerRadioButtonInputProvider.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import org.dhis2.tracker.ui.input.model.inputState
77
import org.dhis2.tracker.ui.input.model.supportingText
88
import org.hisp.dhis.mobile.ui.designsystem.component.InputRadioButton
99
import org.hisp.dhis.mobile.ui.designsystem.component.InputStyle
10-
import org.hisp.dhis.mobile.ui.designsystem.component.Orientation
1110
import org.hisp.dhis.mobile.ui.designsystem.component.RadioButtonData
1211

1312
@Composable
@@ -40,7 +39,7 @@ fun TrackerRadioButtonInputProvider(
4039
inputStyle = inputStyle,
4140
title = model.label,
4241
radioButtonData = data,
43-
orientation = Orientation.VERTICAL,
42+
orientation = model.orientation,
4443
state = model.inputState(),
4544
supportingText = model.supportingText(),
4645
legendData = model.legend,

tracker/src/commonMain/kotlin/org/dhis2/tracker/ui/input/model/TrackerInputModel.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.dhis2.tracker.ui.input.model
22

33
import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState
44
import org.hisp.dhis.mobile.ui.designsystem.component.LegendData
5+
import org.hisp.dhis.mobile.ui.designsystem.component.Orientation
56
import org.hisp.dhis.mobile.ui.designsystem.component.SupportingTextData
67
import org.hisp.dhis.mobile.ui.designsystem.component.SupportingTextState
78

@@ -18,6 +19,7 @@ data class TrackerInputModel(
1819
val mandatory: Boolean,
1920
val editable: Boolean,
2021
val legend: LegendData?,
22+
val orientation: Orientation,
2123
val optionSetConfiguration: TrackerOptionSetConfiguration? = null,
2224
val onItemClick: () -> Unit,
2325
val onValueChange: (String?) -> Unit,

0 commit comments

Comments
 (0)