Skip to content

Commit

Permalink
update ui: add limit, improve ui
Browse files Browse the repository at this point in the history
  • Loading branch information
nqmgaming committed Jun 4, 2024
1 parent 39876a5 commit 8cd5ee3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ object Constrains {
const val API_KEY = BuildConfig.API_KEY
const val CURRENT_LOCATION = "0,0"
const val COUNTRY_CODE = "countryCode:VNM"
const val LIMIT = 10
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.nqmgaming.searchaddresslab.data.remote
import com.nqmgaming.searchaddresslab.core.util.Constrains.API_KEY
import com.nqmgaming.searchaddresslab.core.util.Constrains.COUNTRY_CODE
import com.nqmgaming.searchaddresslab.core.util.Constrains.CURRENT_LOCATION
import com.nqmgaming.searchaddresslab.core.util.Constrains.LIMIT
import com.nqmgaming.searchaddresslab.data.remote.dto.Response
import retrofit2.http.GET
import retrofit2.http.Query
Expand All @@ -13,7 +14,8 @@ interface ApiService {
@Query("q") q: String,
@Query("apiKey") apiKey: String = API_KEY,
@Query("at") at: String = CURRENT_LOCATION,
@Query("in") inCountry: String = COUNTRY_CODE
@Query("in") inCountry: String = COUNTRY_CODE,
@Query("limit") limit: Int = LIMIT
): Response

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
Expand All @@ -26,6 +27,7 @@ import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableDoubleStateOf
import androidx.compose.runtime.mutableFloatStateOf
Expand All @@ -35,6 +37,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.painterResource
Expand Down Expand Up @@ -75,6 +78,7 @@ fun SearchScreen(

val coroutineScope = rememberCoroutineScope()
val keyboardController = LocalSoftwareKeyboardController.current
val listState = rememberLazyListState()

val networkIsConnected = NetworkUtils.isInternetAvailable(context)

Expand Down Expand Up @@ -145,6 +149,12 @@ fun SearchScreen(
}
}


LaunchedEffect(listState.firstVisibleItemIndex) {
// if user scroll then hide keyboard
keyboardController?.hide()
}

if (networkIsConnected) {
Column(
modifier = modifier.fillMaxSize(),
Expand Down Expand Up @@ -216,6 +226,7 @@ fun SearchScreen(

)
LazyColumn(
state = listState,
modifier = Modifier
.fillMaxSize()
.padding(top = 8.dp)
Expand All @@ -233,7 +244,9 @@ fun SearchScreen(

val sortedItems = items.sortedBy { address -> address.distance }

items(sortedItems.size) { index ->
items(sortedItems.size, key = {
sortedItems[it].id ?: it
}) { index ->
val address = sortedItems[index]
AddressItem(
item = address,
Expand Down Expand Up @@ -290,7 +303,6 @@ fun SearchScreen(


}

}
} else {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ fun AddressItem(
val labelSpanStyle = if (label.contains(query, ignoreCase = true)) {
SpanStyle(
color = Color.Black,
fontSize = 12.sp
)
} else {
SpanStyle()
Expand Down

0 comments on commit 8cd5ee3

Please sign in to comment.