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

Location search bar #300

Merged
merged 9 commits into from
Sep 30, 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
21 changes: 21 additions & 0 deletions android/src/main/java/org/hisp/dhis/android/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.graphics.asImageBitmap
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat
import org.hisp.dhis.common.App
import org.hisp.dhis.mobile.ui.designsystem.component.model.LocationItemModel

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -28,6 +29,26 @@ class MainActivity : AppCompatActivity() {
.also { it.inPreferredConfig = Bitmap.Config.ARGB_8888 },
).asImageBitmap()
},
onLocationRequest = { locationQuery, locationSearchCallback ->

if (locationQuery.isNotBlank()) {
val fakeList = buildList<LocationItemModel> {
repeat(20) {
add(
LocationItemModel.SearchResult(
"Fake Location Title #$it",
"Fake Location Address, Fake Country, Fake City",
0.0,
0.0,
),
)
}
}
locationSearchCallback(fakeList)
} else {
locationSearchCallback(emptyList())
}
},
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kotlin {
implementation(compose.material3)
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
implementation(project(":designsystem"))
api(project(":designsystem"))
}
commonTest.dependencies {
implementation(kotlin("test"))
Expand Down
26 changes: 23 additions & 3 deletions common/src/commonMain/kotlin/org/hisp/dhis/common/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.hisp.dhis.common.screens.basicTextInputs.BasicTextInputsScreen
import org.hisp.dhis.common.screens.bottomSheets.BottomSheetsScreen
import org.hisp.dhis.common.screens.buttons.ButtonsScreen
import org.hisp.dhis.common.screens.cards.CardsScreen
import org.hisp.dhis.common.screens.location.LocationSearchBarScreen
import org.hisp.dhis.common.screens.others.BadgesScreen
import org.hisp.dhis.common.screens.others.ChipsScreen
import org.hisp.dhis.common.screens.others.IndicatorScreen
Expand All @@ -38,21 +39,36 @@ import org.hisp.dhis.mobile.ui.designsystem.component.InputDropDown
import org.hisp.dhis.mobile.ui.designsystem.component.InputShellState
import org.hisp.dhis.mobile.ui.designsystem.component.InputStyle
import org.hisp.dhis.mobile.ui.designsystem.component.MetadataAvatarSize
import org.hisp.dhis.mobile.ui.designsystem.component.model.LocationItemModel
import org.hisp.dhis.mobile.ui.designsystem.theme.DHIS2Theme
import org.hisp.dhis.mobile.ui.designsystem.theme.Shape
import org.hisp.dhis.mobile.ui.designsystem.theme.Spacing
import org.hisp.dhis.mobile.ui.designsystem.theme.SurfaceColor

@Composable
fun App(imageBitmapLoader: (() -> ImageBitmap)? = null) {
fun App(
imageBitmapLoader: (() -> ImageBitmap)? = null,
onLocationRequest: (
(
locationQuery: String,
locationSearchCallback: (List<LocationItemModel>) -> Unit,
) -> Unit
)? = null,
) {
DHIS2Theme {
Main(imageBitmapLoader)
Main(imageBitmapLoader, onLocationRequest)
}
}

@Composable
fun Main(
imageBitmapLoader: (() -> ImageBitmap)?,
onLocationRequest: (
(
locationQuery: String,
locationSearchCallback: (List<LocationItemModel>) -> Unit,
) -> Unit
)?,
) {
val currentScreen = remember { mutableStateOf(Groups.NO_GROUP_SELECTED) }
var isComponentSelected by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -81,7 +97,8 @@ fun Main(
state = InputShellState.UNFOCUSED,
expanded = true,
selectedItem = DropdownItem(currentScreen.value.label),
inputStyle = InputStyle.DataInputStyle().apply { backGroundColor = SurfaceColor.SurfaceBright },
inputStyle = InputStyle.DataInputStyle()
.apply { backGroundColor = SurfaceColor.SurfaceBright },
)

when (currentScreen.value) {
Expand All @@ -105,6 +122,9 @@ fun Main(
Groups.MENU -> MenuItemScreen()
Groups.NO_GROUP_SELECTED -> NoComponentSelectedScreen()
Groups.TOP_BAR -> TopBarScreen()
Groups.LOCATION_SEARCH_BAR -> LocationSearchBarScreen { locationQuery, locationCallback ->
onLocationRequest?.invoke(locationQuery, locationCallback)
}
}
} else {
NoComponentSelectedScreen(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ enum class Groups(val label: String) {
TOP_BAR("Top Bar"),
MENU("Menu"),
NO_GROUP_SELECTED("No group selected"),
LOCATION_SEARCH_BAR("Location Search Bar"),
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.hisp.dhis.common.screens.location

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
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 org.hisp.dhis.mobile.ui.designsystem.component.LocationBar
import org.hisp.dhis.mobile.ui.designsystem.component.model.LocationItemModel

@Composable
fun LocationSearchBarScreen(
onSearchLocation: (
locationQuery: String,
locationSearchCallback: (List<LocationItemModel>) -> Unit,

) -> Unit,
) {
var itemList: List<LocationItemModel> by remember {
mutableStateOf(defaultLocationItems)
}
Box(
modifier = Modifier.fillMaxSize()
.background(Color.White)
.padding(16.dp),
contentAlignment = TopCenter,
) {
LocationBar(
currentResults = itemList,
onBackClicked = {},
onClearLocation = {},
onSearchLocation = { locationQuery ->
onSearchLocation(locationQuery) {
itemList = it.takeIf { locationQuery.isNotBlank() } ?: defaultLocationItems
}
},
onLocationSelected = { locationItemModel ->
},
)
}
}

private val defaultLocationItems = listOf(
LocationItemModel.StoredResult(
storedTitle = "Location #1",
storedSubtitle = "Location description, location description, location description",
storedLatitude = 0.0,
storedLongitude = 0.0,
),
LocationItemModel.StoredResult(
storedTitle = "Location #2",
storedSubtitle = "Location description, location description, location description",
storedLatitude = 0.0,
storedLongitude = 0.0,
),
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.hisp.dhis.mobile.ui.designsystem

import org.hisp.dhis.mobile.ui.designsystem.component.LocationBar
import org.junit.Rule
import org.junit.Test

class LocationBarButtonSnapshotTest {
@get:Rule
val paparazzi = paparazzi()

@Test
fun launchSearchBarButtonTest() {
paparazzi.snapshot {
LocationBar(
currentResults = emptyList(),
onBackClicked = {},
onClearLocation = {},
onSearchLocation = {},
onLocationSelected = {},
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.hisp.dhis.mobile.ui.designsystem

import org.hisp.dhis.mobile.ui.designsystem.component.LocationBar
import org.hisp.dhis.mobile.ui.designsystem.component.SearchBarMode
import org.hisp.dhis.mobile.ui.designsystem.component.model.LocationItemModel
import org.junit.Rule
import org.junit.Test

class LocationBarSearchSnapshotTest {
@get:Rule
val paparazzi = paparazzi()

@Test
fun launchSearchBarButtonTest() {
paparazzi.snapshot {
LocationBar(
currentResults = listOf(
LocationItemModel.StoredResult(
"Location Item title",
"Location Item address",
0.0,
0.0,
),
LocationItemModel.SearchResult(
"Location Item title 2",
"Location Item address 2",
0.0,
0.0,
),
),
mode = SearchBarMode.SEARCH,
onBackClicked = {},
onClearLocation = {},
onSearchLocation = {},
onLocationSelected = {},
)
}
}
}
Loading
Loading