Skip to content

Commit

Permalink
retain data on scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
aman-alfresco committed Feb 14, 2024
1 parent 80ea2fa commit 72af17e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ enum class FieldType {
READONLY,
PEOPLE,
FUNCTIONAL_GROUP,
HYPERLINK,
;

fun value() = name.lowercase()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.alfresco.content.data.ProcessEntry
import com.alfresco.content.data.ResponseListForm
import com.alfresco.content.data.ResponseListProcessDefinition
import com.alfresco.content.data.TaskRepository
import com.alfresco.content.data.UserGroupDetails
import com.alfresco.content.data.payloads.FieldsData
import com.alfresco.coroutines.asFlow
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -91,7 +92,7 @@ class FormViewModel(
}
}

fun updateFieldValue(fieldId: String, newValue: String, state: FormViewState) {
fun updateFieldValue(fieldId: String, newValue: Any?, state: FormViewState) {
val updatedFields = state.copy(
formFields = state.formFields.map { field ->
if (field.id == fieldId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
val keyboardController = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current

val formList = state.formFields.map { it }
val formList by remember(state.formFields) {
mutableStateOf(state.formFields.map { it })
}

Column(
modifier = Modifier
Expand All @@ -55,7 +57,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally,

) {
) {
LazyColumn(
modifier = Modifier
.fillMaxSize(),
Expand Down Expand Up @@ -117,6 +119,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
checkedValue = checkedValue,
onCheckChanged = { newChecked ->
checkedValue = newChecked
viewModel.updateFieldValue(field.id, newChecked, state)
},
field,
)
Expand All @@ -128,6 +131,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
dateTimeValue = textFieldValue,
onValueChanged = { newText ->
textFieldValue = newText
viewModel.updateFieldValue(field.id, newText, state)
},
field,
)
Expand All @@ -142,6 +146,7 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
onValueChanged = { (newText, newQuery) ->
textFieldValue = newText
textFieldQuery = newQuery
viewModel.updateFieldValue(field.id, newText, state)
},
fieldsData = field,
)
Expand All @@ -156,16 +161,21 @@ fun FormDetailScreen(state: FormViewState, viewModel: FormViewModel) {
}

FieldType.PEOPLE.value(), FieldType.FUNCTIONAL_GROUP.value() -> {
var userDetailValue by remember { mutableStateOf<UserGroupDetails?>(null) }
var userDetailValue by remember { mutableStateOf(field.value as? UserGroupDetails) }
PeopleField(
userDetail = userDetailValue,
onAssigneeSelected = { userDetails ->
userDetailValue = userDetails
viewModel.updateFieldValue(field.id, userDetails, state)
},
fieldsData = field,
processEntry = ProcessEntry.withProcess(state.parent, field.type),
)
}

FieldType.HYPERLINK.value() -> {

}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ private fun customLabel(visibleText: String, showReadMoreButtonState: Boolean, f
val startIndexReadMore = labelReadMore.indexOf(readMore)
val endIndexReadMore = startIndexReadMore + readMore.length

println("startIndexReadMore == $startIndexReadMore")

val startIndexAsteric = labelReadMore.indexOf(spaceAsteric)
val endIndexAsteric = startIndexAsteric + spaceAsteric.length

Expand All @@ -153,7 +155,7 @@ private fun customLabel(visibleText: String, showReadMoreButtonState: Boolean, f

addStyle(
style = SpanStyle(color = MaterialTheme.colorScheme.primary),
start = startIndexReadMore,
start = startIndexReadMore + 1,
end = endIndexReadMore,
)

Expand Down

0 comments on commit 72af17e

Please sign in to comment.