From 2284b8f98e65d005fd6ca74acfd0a2f2e48de926 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 29 Jan 2024 14:04:34 +0100 Subject: [PATCH 1/5] add: [ANDROAPP-4826] string added --- ui-components/src/main/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/ui-components/src/main/res/values/strings.xml b/ui-components/src/main/res/values/strings.xml index d799973f57..818e763cdf 100644 --- a/ui-components/src/main/res/values/strings.xml +++ b/ui-components/src/main/res/values/strings.xml @@ -14,6 +14,7 @@ Cancel Search Clear all + This form has no fields configured %s error %s errors From 8baf2321c594b915c4b5cae790f33ad6690d419a Mon Sep 17 00:00:00 2001 From: = Date: Mon, 29 Jan 2024 14:32:41 +0100 Subject: [PATCH 2/5] add: [ANDROAPP-4826] no section infobar added --- form/src/main/java/org/dhis2/form/ui/Form.kt | 39 ++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/form/src/main/java/org/dhis2/form/ui/Form.kt b/form/src/main/java/org/dhis2/form/ui/Form.kt index 9f5ac6d8d3..40246eb975 100644 --- a/form/src/main/java/org/dhis2/form/ui/Form.kt +++ b/form/src/main/java/org/dhis2/form/ui/Form.kt @@ -6,6 +6,7 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.interaction.MutableInteractionSource +import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -13,6 +14,9 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState +import androidx.compose.material.Icon +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.outlined.ErrorOutline import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf @@ -25,13 +29,17 @@ import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.unit.dp import kotlinx.coroutines.launch import org.dhis2.commons.resources.ResourceManager +import org.dhis2.form.R import org.dhis2.form.model.FieldUiModel import org.dhis2.form.model.FormSection import org.dhis2.form.ui.event.RecyclerViewUiEvents import org.dhis2.form.ui.intent.FormIntent import org.dhis2.form.ui.provider.inputfield.FieldProvider +import org.hisp.dhis.mobile.ui.designsystem.component.InfoBar +import org.hisp.dhis.mobile.ui.designsystem.component.InfoBarData import org.hisp.dhis.mobile.ui.designsystem.component.Section import org.hisp.dhis.mobile.ui.designsystem.component.SectionState +import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor @OptIn(ExperimentalFoundationApi::class) @Composable @@ -55,7 +63,8 @@ fun Form( } } } - LazyColumn( + if (sections.isNotEmpty() && sections[0].uid != "DUMMY") { + LazyColumn( modifier = Modifier .fillMaxSize() .background(Color.White) @@ -67,7 +76,6 @@ fun Form( contentPadding = PaddingValues(horizontal = 16.dp, vertical = 16.dp), state = scrollState, ) { - if (sections.isNotEmpty()) { this.itemsIndexed( items = sections, key = { _, fieldUiModel -> fieldUiModel.uid }, @@ -96,7 +104,7 @@ fun Form( Section( title = section.title, isLastSection = getNextSection(section, sections) == null, - description = section.description, + description = if (sections.size >= 2 && section.fields.isNotEmpty()) section.description else null, completedFields = section.completedFields(), totalFields = section.fields.size, state = section.state, @@ -137,9 +145,34 @@ fun Form( Spacer(modifier = Modifier.height(120.dp)) } } + } else { + Column(modifier = Modifier + .height(120.dp) + ) { + InfoBar( + infoBarData = InfoBarData( + text = resources.getString(R.string.form_without_fields), + icon = { + Icon( + imageVector = Icons.Outlined.ErrorOutline, + contentDescription = "not synced", + tint = SurfaceColor.Warning, + ) + }, + color = SurfaceColor.Warning, + backgroundColor = SurfaceColor.WarningContainer, + actionText = null, + onClick = null + ), + modifier = Modifier + .background(SurfaceColor.WarningContainer) + ) + } } + } + private fun getNextSection(section: FormSection, sections: List): FormSection? { val currentIndex = sections.indexOf(section) if (currentIndex != -1 && currentIndex < sections.size - 1) { From 28a23fc79ac71a57514490086633cc6514b958b9 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 29 Jan 2024 17:28:42 +0100 Subject: [PATCH 3/5] delete: [ANDROAPP-4826] dummy section removed --- form/src/main/java/org/dhis2/form/ui/Form.kt | 2 +- .../java/org/dhis2/form/ui/mapper/FormSectionMapper.kt | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/form/src/main/java/org/dhis2/form/ui/Form.kt b/form/src/main/java/org/dhis2/form/ui/Form.kt index 40246eb975..0d69d5ba08 100644 --- a/form/src/main/java/org/dhis2/form/ui/Form.kt +++ b/form/src/main/java/org/dhis2/form/ui/Form.kt @@ -63,7 +63,7 @@ fun Form( } } } - if (sections.isNotEmpty() && sections[0].uid != "DUMMY") { + if (sections.isNotEmpty()) { LazyColumn( modifier = Modifier .fillMaxSize() diff --git a/form/src/main/java/org/dhis2/form/ui/mapper/FormSectionMapper.kt b/form/src/main/java/org/dhis2/form/ui/mapper/FormSectionMapper.kt index 06f12753f1..0b0b02a171 100644 --- a/form/src/main/java/org/dhis2/form/ui/mapper/FormSectionMapper.kt +++ b/form/src/main/java/org/dhis2/form/ui/mapper/FormSectionMapper.kt @@ -29,16 +29,6 @@ class FormSectionMapper { ) } } - } else { - sections.add( - FormSection( - uid = "DUMMY", - title = "TITLE", - description = null, - state = SectionState.NO_HEADER, - fields = items.filterIsInstance(), - ), - ) } return sections From 0a75c6795e426b643705bccbd340d657d39677e0 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 30 Jan 2024 13:58:25 +0100 Subject: [PATCH 4/5] update: [ANDROAPP-4826] code formated, infobar added --- form/src/main/java/org/dhis2/form/ui/Form.kt | 103 ++++++++++++------- 1 file changed, 64 insertions(+), 39 deletions(-) diff --git a/form/src/main/java/org/dhis2/form/ui/Form.kt b/form/src/main/java/org/dhis2/form/ui/Form.kt index 0d69d5ba08..71cf0d72fc 100644 --- a/form/src/main/java/org/dhis2/form/ui/Form.kt +++ b/form/src/main/java/org/dhis2/form/ui/Form.kt @@ -65,17 +65,17 @@ fun Form( } if (sections.isNotEmpty()) { LazyColumn( - modifier = Modifier - .fillMaxSize() - .background(Color.White) - .clickable( - interactionSource = MutableInteractionSource(), - indication = null, - onClick = { focusManager.clearFocus() }, - ), - contentPadding = PaddingValues(horizontal = 16.dp, vertical = 16.dp), - state = scrollState, - ) { + modifier = Modifier + .fillMaxSize() + .background(Color.White) + .clickable( + interactionSource = MutableInteractionSource(), + indication = null, + onClick = { focusManager.clearFocus() }, + ), + contentPadding = PaddingValues(horizontal = 16.dp, vertical = 16.dp), + state = scrollState, + ) { this.itemsIndexed( items = sections, key = { _, fieldUiModel -> fieldUiModel.uid }, @@ -115,28 +115,54 @@ fun Form( intentHandler.invoke(FormIntent.OnSection(section.uid)) }, content = { - section.fields.forEachIndexed { index, fieldUiModel -> - fieldUiModel.setCallback(callback) - FieldProvider( - modifier = Modifier.animateItemPlacement( - animationSpec = tween( - durationMillis = 500, - easing = LinearOutSlowInEasing, + if (sections.size >= 2 && section.fields.isNotEmpty()) { + section.fields.forEachIndexed { index, fieldUiModel -> + fieldUiModel.setCallback(callback) + FieldProvider( + modifier = Modifier.animateItemPlacement( + animationSpec = tween( + durationMillis = 500, + easing = LinearOutSlowInEasing, + ), + ), + fieldUiModel = fieldUiModel, + uiEventHandler = uiEventHandler, + intentHandler = intentHandler, + resources = resources, + focusManager = focusManager, + onNextClicked = { + if (index == section.fields.size - 1) { + onNextSection() + } else { + focusManager.moveFocus(FocusDirection.Down) + } + }, + ) + } + } else { + Column( + modifier = Modifier + .height(120.dp), + ) { + InfoBar( + infoBarData = InfoBarData( + text = resources.getString(R.string.form_without_fields), + icon = { + Icon( + imageVector = Icons.Outlined.ErrorOutline, + contentDescription = "no fields", + tint = SurfaceColor.Warning, + ) + }, + color = SurfaceColor.Warning, + backgroundColor = SurfaceColor.WarningContainer, + actionText = null, + onClick = null, ), - ), - fieldUiModel = fieldUiModel, - uiEventHandler = uiEventHandler, - intentHandler = intentHandler, - resources = resources, - focusManager = focusManager, - onNextClicked = { - if (index == section.fields.size - 1) { - onNextSection() - } else { - focusManager.moveFocus(FocusDirection.Down) - } - }, - ) + modifier = Modifier + .background(SurfaceColor.WarningContainer), + ) + } } }, ) @@ -146,8 +172,9 @@ fun Form( } } } else { - Column(modifier = Modifier - .height(120.dp) + Column( + modifier = Modifier + .height(120.dp), ) { InfoBar( infoBarData = InfoBarData( @@ -155,24 +182,22 @@ fun Form( icon = { Icon( imageVector = Icons.Outlined.ErrorOutline, - contentDescription = "not synced", + contentDescription = "no fields", tint = SurfaceColor.Warning, ) }, color = SurfaceColor.Warning, backgroundColor = SurfaceColor.WarningContainer, actionText = null, - onClick = null + onClick = null, ), modifier = Modifier - .background(SurfaceColor.WarningContainer) + .background(SurfaceColor.WarningContainer), ) } } - } - private fun getNextSection(section: FormSection, sections: List): FormSection? { val currentIndex = sections.indexOf(section) if (currentIndex != -1 && currentIndex < sections.size - 1) { From 6dcf25dd69c7547ef23a03c1f223d8d07b9c7bc8 Mon Sep 17 00:00:00 2001 From: = Date: Wed, 31 Jan 2024 10:21:44 +0100 Subject: [PATCH 5/5] update: [ANDROAPP-4826] focus next restored --- form/src/main/java/org/dhis2/form/ui/Form.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/form/src/main/java/org/dhis2/form/ui/Form.kt b/form/src/main/java/org/dhis2/form/ui/Form.kt index 1c2db8a75c..1428b8c811 100644 --- a/form/src/main/java/org/dhis2/form/ui/Form.kt +++ b/form/src/main/java/org/dhis2/form/ui/Form.kt @@ -68,6 +68,7 @@ fun Form( } } if (sections.isNotEmpty()) { + val focusNext = remember { mutableStateOf(false) } LazyColumn( modifier = Modifier .fillMaxSize() @@ -136,6 +137,7 @@ fun Form( onNextClicked = { if (index == section.fields.size - 1) { onNextSection() + focusNext.value = true } else { focusManager.moveFocus(FocusDirection.Down) }