Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/0.4.0 snapshot #330

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/github-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ on:
branches:
- main
- develop
- release/*
pull_request:
branches:
- main
- develop

- release/*
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment.Companion.TopCenter
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.hisp.dhis.common.screens.components.GroupComponentDropDown
import org.hisp.dhis.mobile.ui.designsystem.component.DropdownItem
import org.hisp.dhis.mobile.ui.designsystem.component.LocationBar
Expand All @@ -37,6 +40,8 @@ fun LocationSearchBarScreen(
screenDropdownItemList.add(DropdownItem(it.label))
}

val scope = rememberCoroutineScope()

GroupComponentDropDown(
dropdownItems = screenDropdownItemList.toList(),
onItemSelected = {
Expand All @@ -52,6 +57,8 @@ fun LocationSearchBarScreen(

when (currentScreen.value) {
LocationSearchBarOptions.DEFAULT_BEHAVIOUR -> {
var searching by remember { mutableStateOf(false) }

Box(
modifier = Modifier.fillMaxSize()
.background(Color.White)
Expand All @@ -63,18 +70,26 @@ fun LocationSearchBarScreen(
onBackClicked = {},
onClearLocation = {},
onSearchLocation = { locationQuery ->
onSearchLocation(locationQuery) {
itemList =
it.takeIf { locationQuery.isNotBlank() } ?: defaultLocationItems
searching = true
scope.launch {
delay(3000)
onSearchLocation(locationQuery) {
itemList =
it.takeIf { locationQuery.isNotBlank() } ?: defaultLocationItems
searching = false
}
}
},
onLocationSelected = { locationItemModel ->
},
searching = searching,
)
}
}

LocationSearchBarOptions.AUTOSELECT_ON_ONE_ITEM_FOUND -> {
var searching by remember { mutableStateOf(false) }

Box(
modifier = Modifier.fillMaxSize()
.background(Color.White)
Expand All @@ -87,14 +102,19 @@ fun LocationSearchBarScreen(
onBackClicked = {},
onClearLocation = {},
onSearchLocation = { locationQuery ->
onSearchLocation(locationQuery) {
itemList =
it.take(1).takeIf { locationQuery.isNotBlank() }
?: defaultLocationItems
searching = true
scope.launch {
onSearchLocation(locationQuery) {
itemList =
it.take(1).takeIf { locationQuery.isNotBlank() }
?: defaultLocationItems
searching = false
}
}
},
onLocationSelected = { locationItemModel ->
},
searching = searching,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class LocationBarButtonSnapshotTest {
onClearLocation = {},
onSearchLocation = {},
onLocationSelected = {},
searching = false,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class LocationBarSearchSnapshotTest {
onClearLocation = {},
onSearchLocation = {},
onLocationSelected = {},
searching = false,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ enum class SearchBarMode {
SEARCH,
}

/**
* DHIS2 Location Bar search actions
* Default: The user will need to select a result to mark it as selected
* OnOneItemSelect: If only one item is available, it will be selected automatically
* */
enum class OnSearchAction {
Default,
OnOneItemSelect,
Expand All @@ -75,6 +80,8 @@ enum class OnSearchAction {
* DHIS2 Location Bar.
* @param currentResults: the available location items to display before/after search.
* @param mode: the initial mode for the composable.
* @param searchAction: How the search result selection is carried out.
* @param searching: whether the search is currently in progress.
* @param onBackClicked: callback for when the back button is clicked.
* @param onClearLocation: callback for when the clear location button is clicked.
* @param onSearchLocation: callback for when the search location button is clicked.
Expand All @@ -86,6 +93,7 @@ fun LocationBar(
currentResults: List<LocationItemModel>,
mode: SearchBarMode = SearchBarMode.BUTTON,
searchAction: OnSearchAction = OnSearchAction.Default,
searching: Boolean,
onBackClicked: () -> Unit,
onClearLocation: () -> Unit,
onSearchLocation: (query: String) -> Unit,
Expand Down Expand Up @@ -129,6 +137,7 @@ fun LocationBar(
SearchBarMode.SEARCH -> LocationSearchBar(
currentSearch = currentSearch,
currentResults = currentResults,
activeSearching = searching,
onSearchChanged = {
currentSearch = it
onSearchLocation(currentSearch)
Expand Down Expand Up @@ -212,6 +221,7 @@ private fun LocationSearchBarButton(
private fun LocationSearchBar(
currentSearch: String = "",
currentResults: List<LocationItemModel>,
activeSearching: Boolean,
onSearchChanged: (String) -> Unit,
onSearch: (String) -> Unit,
onBackClicked: () -> Unit,
Expand All @@ -221,6 +231,7 @@ private fun LocationSearchBar(
val focusRequester = remember { FocusRequester() }
val keyboardController = LocalSoftwareKeyboardController.current
var needsToFocus by remember { mutableStateOf(true) }
var searching by remember(currentSearch) { mutableStateOf(false) }

Column(
modifier = Modifier.fillMaxSize(),
Expand Down Expand Up @@ -259,6 +270,11 @@ private fun LocationSearchBar(

LazyColumn(modifier = Modifier.fillMaxWidth(), state = scrollState) {
when {
activeSearching ->
item {
SearchProgressMessage()
}

currentResults.isNotEmpty() ->
itemsIndexed(items = currentResults) { index, locationItemModel ->
SearchResultLocationItem(
Expand Down Expand Up @@ -431,3 +447,24 @@ private fun NoResultsMessage(isSearching: Boolean) {
)
}
}

@Composable
private fun SearchProgressMessage() {
val message = provideStringResource("searching_location")

Column(
modifier = Modifier
.testTag("SEARCHING_LOCATION")
.fillMaxWidth()
.padding(vertical = 64.dp),
verticalArrangement = spacedBy(16.dp),
horizontalAlignment = CenterHorizontally,
) {
ProgressIndicator(type = ProgressIndicatorType.CIRCULAR)
Text(
text = message,
style = MaterialTheme.typography.bodyLarge,
color = TextColor.OnSurfaceVariant,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@
<string name="select_in_map">Seleccionar en el mapa</string>
<string name="no_recent_results">No hay resultados recientes</string>
<string name="no_results">No hay resultados</string>
<string name="searching_location">Buscando...</string>
</resources>
1 change: 1 addition & 0 deletions designsystem/src/commonMain/resources/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@
<string name="select_in_map">Select in map</string>
<string name="no_recent_results">No recent results</string>
<string name="no_results">No results</string>
<string name="searching_location">Searching...</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class LocationSearchBarTest {
onClearLocation = {},
onSearchLocation = {},
onLocationSelected = {},
searching = false,
)
}

Expand Down Expand Up @@ -60,6 +61,7 @@ class LocationSearchBarTest {
onClearLocation = {},
onSearchLocation = {},
onLocationSelected = {},
searching = false,
)
}

Expand Down Expand Up @@ -97,6 +99,7 @@ class LocationSearchBarTest {
items = listOf()
},
onLocationSelected = {},
searching = false,
)
}

Expand Down Expand Up @@ -144,6 +147,7 @@ class LocationSearchBarTest {
)
},
onLocationSelected = {},
searching = false,
)
}

Expand Down Expand Up @@ -192,6 +196,7 @@ class LocationSearchBarTest {
)
},
onLocationSelected = {},
searching = false,
)
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading