Skip to content

Commit

Permalink
Make LocationItem public
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Sep 27, 2024
1 parent fbf2ae0 commit 079cc33
Showing 1 changed file with 60 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.icons.Icons
Expand Down Expand Up @@ -41,6 +40,8 @@ import androidx.compose.ui.Alignment.Companion.Top
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -216,9 +217,9 @@ private fun LocationSearchBar(
when {
currentResults.isNotEmpty() ->
itemsIndexed(items = currentResults) { index, locationItemModel ->
LocationItem(
SearchResultLocationItem(
modifier = Modifier.testTag("LOCATION_ITEM_$index"),
locationItemModel = locationItemModel,
locationItemModel,
) {
onLocationSelected(locationItemModel)
}
Expand Down Expand Up @@ -276,22 +277,9 @@ private fun LocationSearchBar(
fun LocationItem(
modifier: Modifier = Modifier,
locationItemModel: LocationItemModel,
icon: @Composable () -> Unit,
onClick: () -> Unit,
) {
val icon = when (locationItemModel) {
is LocationItemModel.StoredResult -> Icons.Outlined.WatchLater
is LocationItemModel.SearchResult -> Icons.Outlined.Place
}
val tintedColor = when (locationItemModel) {
is LocationItemModel.StoredResult -> SurfaceColor.Warning
is LocationItemModel.SearchResult -> SurfaceColor.Primary
}

val bgColor = when (locationItemModel) {
is LocationItemModel.StoredResult -> SurfaceColor.WarningContainer
is LocationItemModel.SearchResult -> SurfaceColor.PrimaryContainer
}

Row(
modifier = modifier
.fillMaxWidth()
Expand All @@ -301,18 +289,7 @@ fun LocationItem(
horizontalArrangement = spacedBy(Spacing.Spacing16),
verticalAlignment = Top,
) {
Box(
modifier = Modifier.size(Spacing.Spacing40)
.clip(Shape.Full)
.background(color = bgColor, shape = Shape.Full),
contentAlignment = Center,
) {
Icon(
imageVector = icon,
tint = tintedColor,
contentDescription = "location icon",
)
}
icon()

Column(modifier = Modifier.fillMaxWidth()) {
Text(
Expand All @@ -331,6 +308,60 @@ fun LocationItem(
}
}

@Composable
private fun SearchResultLocationItem(
modifier: Modifier = Modifier,
locationItemModel: LocationItemModel,
onClick: () -> Unit,
) {
val icon = when (locationItemModel) {
is LocationItemModel.StoredResult -> Icons.Outlined.WatchLater
is LocationItemModel.SearchResult -> Icons.Outlined.Place
}
val tintedColor = when (locationItemModel) {
is LocationItemModel.StoredResult -> SurfaceColor.Warning
is LocationItemModel.SearchResult -> SurfaceColor.Primary
}

val bgColor = when (locationItemModel) {
is LocationItemModel.StoredResult -> SurfaceColor.WarningContainer
is LocationItemModel.SearchResult -> SurfaceColor.PrimaryContainer
}

LocationItem(
modifier = modifier,
locationItemModel = locationItemModel,
icon = {
LocationItemIcon(
icon = icon,
tintedColor = tintedColor,
bgColor = bgColor,
)
},
onClick = onClick,
)
}

@Composable
fun LocationItemIcon(
icon: ImageVector,
tintedColor: Color,
bgColor: Color,
) {
Box(
modifier = Modifier.size(Spacing.Spacing40)
.clip(Shape.Full)
.background(color = bgColor, shape = Shape.Full),
contentAlignment = Center,
) {
Icon(
imageVector = icon,
tint = tintedColor,
contentDescription = "location icon",
)
}
}

@Composable
private fun NoResultsMessage(isSearching: Boolean) {
val message = if (!isSearching) {
Expand Down

0 comments on commit 079cc33

Please sign in to comment.