Skip to content

Commit

Permalink
Add search by QR code option in register (#3379)
Browse files Browse the repository at this point in the history
* Support search by QR code config in register search

* Move clear button to show as last in register search

* Hide qr/barcode icon when showing clear text icon

to match design
  • Loading branch information
LZRS committed Jul 16, 2024
1 parent 400253b commit c425132
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ data class RegisterContentConfig(
val rules: List<RuleConfig>? = null,
val visible: Boolean? = null,
val computedRules: List<String>? = null,
val searchByBarcode: Boolean? = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ fun GeoWidgetLauncherScreen(
filteredRecordsCount = 1,
isSearchBarVisible = geoWidgetConfiguration.topScreenSection?.searchBar?.visible ?: true,
searchPlaceholder = geoWidgetConfiguration.topScreenSection?.searchBar?.display,
showSearchByBarcode =
geoWidgetConfiguration.topScreenSection?.searchBar?.searchByBarcode ?: false,
toolBarHomeNavigation = toolBarHomeNavigation,
onSearchTextChanged = { searchText ->
onEvent(GeoWidgetEvent.SearchServicePoints(searchText = searchText))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package org.smartregister.fhircore.quest.ui.main.components
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down Expand Up @@ -49,7 +50,9 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
Expand All @@ -63,8 +66,10 @@ import org.smartregister.fhircore.engine.domain.model.ToolBarHomeNavigation
import org.smartregister.fhircore.engine.domain.model.TopScreenSectionConfig
import org.smartregister.fhircore.engine.ui.theme.GreyTextColor
import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundExcludeGenerated
import org.smartregister.fhircore.engine.util.extension.getActivity
import org.smartregister.fhircore.quest.event.ToolbarClickEvent
import org.smartregister.fhircore.quest.ui.shared.components.Image
import org.smartregister.fhircore.quest.util.QrCodeScanUtils

const val DRAWER_MENU = "Drawer Menu"
const val SEARCH = "Search"
Expand All @@ -85,17 +90,20 @@ const val TOP_ROW_TOGGLE_ICON_TEST_tAG = "topRowToggleIconTestTag"
fun TopScreenSection(
modifier: Modifier = Modifier,
title: String,
navController: NavController,
isSearchBarVisible: Boolean,
searchText: String,
showSearchByBarcode: Boolean = false,
filteredRecordsCount: Long? = null,
searchPlaceholder: String? = null,
toolBarHomeNavigation: ToolBarHomeNavigation = ToolBarHomeNavigation.OPEN_DRAWER,
onSearchTextChanged: (String) -> Unit,
onSearchTextChanged: (String) -> Unit = {},
isFilterIconEnabled: Boolean = false,
topScreenSection: TopScreenSectionConfig? = null,
navController: NavController,
onClick: (ToolbarClickEvent) -> Unit,
onClick: (ToolbarClickEvent) -> Unit = {},
) {
val currentContext = LocalContext.current

Column(
modifier = modifier.fillMaxWidth().background(MaterialTheme.colors.primary),
) {
Expand Down Expand Up @@ -187,17 +195,40 @@ fun TopScreenSection(
)
},
trailingIcon = {
if (searchText.isNotEmpty()) {
IconButton(
onClick = { onSearchTextChanged("") },
modifier = modifier.testTag(TRAILING_ICON_BUTTON_TEST_TAG),
) {
Icon(
imageVector = Icons.Filled.Clear,
CLEAR,
tint = Color.Gray,
modifier = modifier.testTag(TRAILING_ICON_TEST_TAG),
)
Box(contentAlignment = Alignment.CenterEnd) {
when {
searchText.isNotBlank() -> {
IconButton(
onClick = { onSearchTextChanged("") },
modifier = modifier.testTag(TRAILING_ICON_BUTTON_TEST_TAG),
) {
Icon(
imageVector = Icons.Filled.Clear,
CLEAR,
tint = Color.Gray,
modifier = modifier.testTag(TRAILING_ICON_TEST_TAG),
)
}
}
showSearchByBarcode -> {
IconButton(
onClick = {
currentContext.getActivity()?.let {
QrCodeScanUtils.scanBarcode(it) { code -> onSearchTextChanged(code ?: "") }
}
},
) {
navController.context
Icon(
painter =
painterResource(id = org.smartregister.fhircore.quest.R.drawable.ic_qr_code),
contentDescription =
stringResource(
id = org.smartregister.fhircore.quest.R.string.qr_code,
),
)
}
}
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ fun RegisterScreen(
filteredRecordsCount = registerUiState.filteredRecordsCount,
isSearchBarVisible = registerUiState.registerConfiguration?.searchBar?.visible ?: true,
searchPlaceholder = registerUiState.registerConfiguration?.searchBar?.display,
showSearchByBarcode =
registerUiState.registerConfiguration?.searchBar?.searchByBarcode ?: false,
toolBarHomeNavigation = toolBarHomeNavigation,
onSearchTextChanged = { searchText ->
onEvent(RegisterEvent.SearchRegister(searchText = searchText))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import androidx.compose.ui.unit.sp
import org.smartregister.fhircore.engine.R
import org.smartregister.fhircore.engine.util.annotation.PreviewWithBackgroundExcludeGenerated

class SearchView

const val SEARCH_BAR_TRAILING_ICON_TEST_TAG = "searchBarTrailingIconTestTag"
const val SEARCH_BAR_TRAILING_ICON_BUTTON_TEST_TAG = "searchBarTrailingIconButtonTestTag"
const val SEARCH_BAR_TRAILING_TEXT_FIELD_TEST_TAG = "searchBarTrailingTextFieldTestTag"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

package org.smartregister.fhircore.quest.util

import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentActivity
import org.smartregister.fhircore.quest.ui.sdc.qrCode.EditTextQrCodeViewHolderFactory
import org.smartregister.fhircore.quest.ui.sdc.qrCode.QrCodeCameraDialogFragment

object QrCodeScanUtils {

fun scanBarcode(lifecycleOwner: AppCompatActivity, onBarcodeScanResult: (String?) -> Unit) {
fun scanBarcode(lifecycleOwner: FragmentActivity, onBarcodeScanResult: (String?) -> Unit) {
lifecycleOwner.supportFragmentManager.apply {
setFragmentResultListener(
QrCodeCameraDialogFragment.RESULT_REQUEST_KEY,
Expand Down

0 comments on commit c425132

Please sign in to comment.