Skip to content

Commit

Permalink
update ui, improve search
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Jun 4, 2024
1 parent afac32a commit 9244130
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@ fun Address.asDomainAddress(): DomainAddress {
county = county,
district = district,
label = label,
postalCode = postalCode
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import retrofit2.http.GET
import retrofit2.http.Query

interface ApiService {
@GET("autosuggest")
@GET("autocomplete")
suspend fun getGeocode(
@Query("q") q: String,
@Query("apiKey") apiKey: String = API_KEY,
@Query("at") at: String = CURRENT_LOCATION,
@Query("in") inCountry: String = COUNTRY_CODE
// @Query("at") at: String = CURRENT_LOCATION, this is for auto suggest
// @Query("in") inCountry: String = COUNTRY_CODE
): Response
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ data class Address(
val county: String?,
val district: String?,
val label: String?,
val postalCode: String?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.nqmgaming.searchaddresslab.data.remote.dto

data class Highlights (
val title: Title?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.nqmgaming.searchaddresslab.data.remote.dto

data class Title(
val start: Int?,
val end: Int?
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ data class Address(
val county: String?,
val district: String?,
val label: String?,
val postalCode: String?
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
Expand All @@ -39,7 +38,6 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavController
import com.airbnb.lottie.compose.LottieAnimation
import com.airbnb.lottie.compose.LottieCompositionSpec
import com.airbnb.lottie.compose.LottieConstants
Expand Down Expand Up @@ -186,7 +184,7 @@ fun SearchScreen(
painter = painterResource(id = R.drawable.ic_location_off),
contentDescription = "Here Maps Search Address Lab",
modifier = Modifier
.size(200.dp),
.size(100.dp),
contentScale = ContentScale.Crop
)
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ class SearchScreenViewModel @Inject constructor(

fun debounceQuery(scope: CoroutineScope, newQuery: String, delayMillis: Long = 1000L) {
searchJob?.cancel()
searchJob = scope.launch {
delay(delayMillis)
onEvent(SearchScreenEvent.OnSearch(newQuery))
if(newQuery.isNotEmpty()){
searchJob = scope.launch {
delay(delayMillis)
onEvent(SearchScreenEvent.OnSearch(newQuery))
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Intent
import android.net.Uri
import android.widget.Toast
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
Expand All @@ -18,25 +17,21 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.LocationOn
import androidx.compose.material.icons.filled.PlayArrow
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.nqmgaming.searchaddresslab.R
import com.nqmgaming.searchaddresslab.domain.model.Address
import com.nqmgaming.searchaddresslab.domain.model.Item

@Composable
Expand Down Expand Up @@ -95,13 +90,34 @@ fun AddressItem(
} else {
SpanStyle()
}

val label = item.address?.label ?: ""
val labelSpanStyle = if (label.contains(query, ignoreCase = true)) {
SpanStyle(
color = Color.Black,
)
} else {
SpanStyle()
}

Text(
text = annotateRecursively(
placeHolderList = listOf(Pair(query, titleSpanStyle)),
originalText = title
),
maxLines = 1,
modifier = Modifier.padding(horizontal = 10.dp)
modifier = Modifier.padding(horizontal = 10.dp),
overflow = TextOverflow.Ellipsis
)

Text(
text = annotateRecursively(
placeHolderList = listOf(Pair(query, labelSpanStyle)),
originalText = label
),
maxLines = 1,
modifier = Modifier.padding(horizontal = 10.dp),
overflow = TextOverflow.Ellipsis
)
}
Icon(
Expand Down
2 changes: 1 addition & 1 deletion local.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
# For customization when using a Version Control System, please read the
# header note.
sdk.dir=/Users/nqmgaming/Library/Android/sdk
API_KEY=""
API_KEY="ZXonmH3awU1xN48WapjeZq5gDE5WM1TBSMF4JkxEnxA"

0 comments on commit 9244130

Please sign in to comment.