diff --git a/app/src/main/java/com/nqmgaming/searchaddresslab/core/util/Constrains.kt b/app/src/main/java/com/nqmgaming/searchaddresslab/core/util/Constrains.kt index e67fc04..4aef27b 100644 --- a/app/src/main/java/com/nqmgaming/searchaddresslab/core/util/Constrains.kt +++ b/app/src/main/java/com/nqmgaming/searchaddresslab/core/util/Constrains.kt @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/nqmgaming/searchaddresslab/data/remote/ApiService.kt b/app/src/main/java/com/nqmgaming/searchaddresslab/data/remote/ApiService.kt index d51367f..cf941cb 100644 --- a/app/src/main/java/com/nqmgaming/searchaddresslab/data/remote/ApiService.kt +++ b/app/src/main/java/com/nqmgaming/searchaddresslab/data/remote/ApiService.kt @@ -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 @@ -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 } \ No newline at end of file diff --git a/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/SearchScreen.kt b/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/SearchScreen.kt index 5d17bfb..7686d91 100644 --- a/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/SearchScreen.kt +++ b/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/SearchScreen.kt @@ -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 @@ -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 @@ -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 @@ -75,6 +78,7 @@ fun SearchScreen( val coroutineScope = rememberCoroutineScope() val keyboardController = LocalSoftwareKeyboardController.current + val listState = rememberLazyListState() val networkIsConnected = NetworkUtils.isInternetAvailable(context) @@ -145,6 +149,12 @@ fun SearchScreen( } } + + LaunchedEffect(listState.firstVisibleItemIndex) { + // if user scroll then hide keyboard + keyboardController?.hide() + } + if (networkIsConnected) { Column( modifier = modifier.fillMaxSize(), @@ -216,6 +226,7 @@ fun SearchScreen( ) LazyColumn( + state = listState, modifier = Modifier .fillMaxSize() .padding(top = 8.dp) @@ -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, @@ -290,7 +303,6 @@ fun SearchScreen( } - } } else { Column( diff --git a/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/components/AddressItem.kt b/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/components/AddressItem.kt index 31ee8b3..93ee09e 100644 --- a/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/components/AddressItem.kt +++ b/app/src/main/java/com/nqmgaming/searchaddresslab/presentation/screen/search/components/AddressItem.kt @@ -117,6 +117,7 @@ fun AddressItem( val labelSpanStyle = if (label.contains(query, ignoreCase = true)) { SpanStyle( color = Color.Black, + fontSize = 12.sp ) } else { SpanStyle()