Skip to content

Commit

Permalink
fix: [ANDROAPP-5888] fix failing rebase (#3938)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavimolloy authored Dec 20, 2024
1 parent 7be5526 commit d0ca314
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ data class TextInputModel(
val selection: TextRange? = null,
val error: String? = null,
val warning: String? = null,
val regex: Regex? = null,
private val clearable: Boolean = false,
) {
fun showClearButton() = clearable && currentValue?.isNotEmpty() == true
Expand Down
35 changes: 27 additions & 8 deletions compose-table/src/main/java/org/dhis2/composetable/ui/TextInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,7 @@ private fun TextInputContent(
},
value = textFieldValueState,
onValueChange = {
textFieldValueState = it
onTextChanged(
textInputModel.copy(
currentValue = it.text,
selection = it.selection,
error = null,
),
)
textFieldValueState = manageOnValueChanged(textFieldValueState, it, onTextChanged, textInputModel)
},
textStyle = TextStyle.Default.copy(
fontSize = 12.sp,
Expand Down Expand Up @@ -271,6 +264,32 @@ private fun TextInputContent(
}
}

fun manageOnValueChanged(textFieldValueState: TextFieldValue, newValue: TextFieldValue, onTextChanged: (TextInputModel) -> Unit, textInputModel: TextInputModel): TextFieldValue {
return if (textInputModel.regex != null) {
if (textInputModel.regex.matches(newValue.text)) {
onTextChanged(
textInputModel.copy(
currentValue = newValue.text,
selection = newValue.selection,
error = null,
),
)
newValue
} else {
textFieldValueState
}
} else {
onTextChanged(
textInputModel.copy(
currentValue = newValue.text,
selection = newValue.selection,
error = null,
),
)
newValue
}
}

@Composable
private fun dividerColor(hasError: Boolean, hasWarning: Boolean, hasFocus: Boolean) = when {
hasError -> LocalTableColors.current.errorColor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ fun HomeScreen(
) { targetIndex ->
when (targetIndex) {
BottomNavigation.ANALYTICS.id -> {
DHIS2Theme() {}
AnalyticsScreen(
viewModel = viewModel,
backAction = { manageStockViewModel.onHandleBackNavigation() },
themeColor = themeColor,
modifier = Modifier.padding(paddingValues),
scaffoldState = scaffoldState,
supportFragmentManager = supportFragmentManager,
)
DHIS2Theme() {
AnalyticsScreen(
viewModel = viewModel,
backAction = { manageStockViewModel.onHandleBackNavigation() },
themeColor = themeColor,
modifier = Modifier.padding(paddingValues),
scaffoldState = scaffoldState,
supportFragmentManager = supportFragmentManager,
)
}
}

BottomNavigation.DATA_ENTRY.id -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.dhis2.composetable.model.TableCell
import org.dhis2.composetable.model.TextInputModel
import org.dhis2.composetable.model.ValidationResult
import org.hisp.dhis.android.core.program.ProgramRuleActionType
import org.hisp.dhis.mobile.ui.designsystem.component.model.RegExValidations
import org.hisp.dhis.rules.models.RuleEffect
import org.jetbrains.annotations.NotNull
import java.util.Collections
Expand Down Expand Up @@ -329,9 +330,17 @@ class ManageStockViewModel @Inject constructor(
currentValue = cell.value,
keyboardInputType = KeyboardInputType.NumberPassword(),
error = stockEntry?.errorMessage,
regex = getRegExBasedOnTransactionType(),
)
}

private fun getRegExBasedOnTransactionType(): Regex? {
return when (transaction.value?.transactionType) {
TransactionType.CORRECTION -> null
else -> RegExValidations.POSITIVE_INTEGER.regex
}
}

fun onSaveValueChange(cell: TableCell) {
viewModelScope.launch(
dispatcherProvider.io(),
Expand Down

0 comments on commit d0ca314

Please sign in to comment.