Skip to content

Commit

Permalink
[ANDROAPP-5805] clear search button visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmr committed Feb 20, 2024
1 parent 73ce7a7 commit 33d9910
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ class SearchTEIViewModel(
viewModelScope.launch {
if (canPerformSearch()) {
searching = queryData.isNotEmpty()
uiState = uiState.copy(clearSearchEnabled = queryData.isNotEmpty())
when (_screenState.value?.screenState) {
SearchScreenState.LIST -> {
SearchIdlingResourceSingleton.increment()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,21 +182,24 @@ fun SearchParametersScreen(
)
}

Button(
modifier = Modifier
.align(Alignment.CenterHorizontally),
style = ButtonStyle.TEXT,
text = resourceManager.getString(R.string.clear_search),
icon = {
Icon(
imageVector = Icons.Outlined.Cancel,
contentDescription = resourceManager.getString(R.string.clear_search),
tint = SurfaceColor.Primary,
)
},
) {
focusManager.clearFocus()
onClear()
if (uiState.clearSearchEnabled) {
Button(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(16.dp, 24.dp, 16.dp, 8.dp),
style = ButtonStyle.TEXT,
text = resourceManager.getString(R.string.clear_search),
icon = {
Icon(
imageVector = Icons.Outlined.Cancel,
contentDescription = resourceManager.getString(R.string.clear_search),
tint = SurfaceColor.Primary,
)
},
) {
focusManager.clearFocus()
onClear()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class SearchParametersUiState(
val minAttributesMessage: String? = null,
private val _shouldShowMinAttributeWarning: MutableSharedFlow<Boolean> = MutableSharedFlow(),
val searchEnabled: Boolean = false,
val clearSearchEnabled: Boolean = false,
) {
val shouldShowMinAttributeWarning: SharedFlow<Boolean> = _shouldShowMinAttributeWarning

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.dhis2.R
import org.dhis2.commons.resources.ResourceManager
import org.dhis2.form.model.FieldUiModel
import org.dhis2.form.model.UiRenderType
import org.dhis2.form.ui.event.RecyclerViewUiEvents
import org.dhis2.form.ui.provider.inputfield.FieldProvider
import org.hisp.dhis.android.core.common.ValueType
import org.hisp.dhis.mobile.ui.designsystem.component.InputStyle
Expand Down Expand Up @@ -65,11 +66,27 @@ fun provideParameterSelectorItem(
},
status = status,
onExpand = {
fieldUiModel.onItemClick()
performOnExpandActions(fieldUiModel, callback)
},
)
}

private fun performOnExpandActions(fieldUiModel: FieldUiModel, callback: FieldUiModel.Callback) {
fieldUiModel.onItemClick()

if (fieldUiModel.renderingType == UiRenderType.QR_CODE ||
fieldUiModel.renderingType == UiRenderType.BAR_CODE
) {
callback.recyclerViewUiEvents(
RecyclerViewUiEvents.ScanQRCode(
uid = fieldUiModel.uid,
optionSet = fieldUiModel.optionSet,
renderingType = fieldUiModel.renderingType,
),
)
}
}

@Composable
private fun ProvideIcon(valueType: ValueType?, renderingType: UiRenderType?) =
when (valueType) {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,6 @@
<string name="schedule">Schedule</string>
<string name="program_stage">Program stage</string>
<string name="event">event</string>
<string name="clear_search">\"Clear search\"</string>
<string name="clear_search">Clear search</string>
<string name="optional">Optional</string>
</resources>
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ minSdk = "21"
vCode = "130"
vName = "2.10-DEV"
kotlinCompilerExtensionVersion = "1.5.6"
gradle = "8.2.0"
gradle = "8.2.2"
kotlin = '1.9.21'
hilt = '2.47'
hiltCompiler = '1.0.0'
Expand Down

0 comments on commit 33d9910

Please sign in to comment.