Hi team, I am building a search Screen. Could you ...
# android
r
Hi team, I am building a search Screen. Could you help me with this?
🧵 4
I have a list of Country
Copy code
@Keep
@Parcelize
@Immutable
d.ata class Country(
  @SerializedName("abbreviation")
    val abbreviation: List<String?>? = null,
  @SerializedName("city")
    val city: List<String?> = emptyList(),
  @SerializedName("countryCode")
    val countryCode: String = "",
  @SerializedName("countryName")
    val countryName: String = ""
) : Parcelable
Now when there is no query I only need to display list of countryName but as the user types , the list should update to a list of "city, countryName" Example - Idle state (USA), Search state (Boston, USA), (Dallas, USA), (Nyc, USA) .... My Composable will only know the title I am providing
Copy code
@Keep
@Parcelize
@Immutable
data class IRSearch(
  val title: String,
  val country: Country
) : Parcelable
I want to write concise and elegant Kotlin for the mapping part of cities with country Name which I am unable to do so. Any help, advice, follow up is appreciated
Copy code
LaunchedEffect(key1 = searchText) {
  snapshotFlow { searchText }
    .onEach {
      searchingInProgress = it.isNotEmpty()
    }
    .distinctUntilChanged()
    .combine(viewModel.getCountryList()) { text, list ->
      (list as? ApiResponse.Success)?.let {
        if (text.isEmpty()) {
          it.data?.countryList?.filterNotNull()?.map {
              country -> IRSearch(
                title = country.countryName,
                country = country
              )
          }
        } else
          it.data?.countryList?.filterNotNull()?.map {
              country -> IRSearch(
            title = , // <---- Need help here mapping list of city with country
            country = country
          )
          }
      } ?: emptyList()
    }
    .flowOn(Dispatchers.Default)
    .collectLatest {

    }
@Ian Lake @Chrimaeon @kenkyee. Apologies. I have created thread as you asked. Could have a look at this