Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,9 @@
<string name="feature_search_close">Cerrar</string>
<string name="feature_search_all">Todos</string>

<string-array name="feature_search_filter_options">
<item>Clientes</item>
<item>Grupos</item>
<item>Centros</item>
<item>Cuentas de préstamo</item>
<item>Cuentas de ahorro</item>
</string-array>

<string-array name="feature_search_filter_option_values">
<item>clients</item>
<item>groups</item>
<item>centers</item>
<item>loans</item>
<item>savingsaccounts</item>
</string-array>
<string name="feature_search_filter_options_clients_label">Clientes</string>
<string name="feature_search_filter_options_groups_label">Grupos</string>
<string name="feature_search_filter_options_centers_label">Centros</string>
<string name="feature_search_filter_options_loans_label">Cuentas de préstamo</string>
<string name="feature_search_filter_options_savings_label">Cuentas de ahorro</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,14 @@
<string name="feature_search_close">Close</string>
<string name="feature_search_all">All</string>

<string-array name="feature_search_filter_options">
<item>Clients</item>
<item>Groups</item>
<item>Centers</item>
<item>Loan Accounts</item>
<item>Savings Accounts</item>
</string-array>

<string-array name="feature_search_filter_option_values">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removed string array?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string-array was originally introduced during "Migrate Search Fragment To Compose"
The filter options are mainly structured data of the

  • label (these are localized)
  • values (these are the constants - localization not needed)

I believe using string-array in this context would introduce additional complexity. It would be depended on the positional indexing between the two arrays.

<item>clients</item>
<item>groups</item>
<item>centers</item>
<item>loans</item>
<item>savingsaccounts</item>
</string-array>
<string name="feature_search_filter_options_clients_label">Clients</string>
<string name="feature_search_filter_options_clients_value" translatable="false">clients</string>
<string name="feature_search_filter_options_groups_label">Groups</string>
<string name="feature_search_filter_options_groups_value" translatable="false">groups</string>
<string name="feature_search_filter_options_centers_label">Centers</string>
<string name="feature_search_filter_options_centers_value" translatable="false">centers</string>
<string name="feature_search_filter_options_loans_label">Loan Accounts</string>
<string name="feature_search_filter_options_loans_value" translatable="false">loans</string>
<string name="feature_search_filter_options_savings_label">Savings Accounts</string>
<string name="feature_search_filter_options_savings_value" translatable="false">savingsaccounts</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
*/
package com.mifos.feature.search

import androidclient.feature.search.generated.resources.Res
import androidclient.feature.search.generated.resources.feature_search_filter_options_clients_label
import androidclient.feature.search.generated.resources.feature_search_filter_options_clients_value
import androidclient.feature.search.generated.resources.feature_search_filter_options_groups_label
import androidclient.feature.search.generated.resources.feature_search_filter_options_groups_value
import androidclient.feature.search.generated.resources.feature_search_filter_options_loans_label
import androidclient.feature.search.generated.resources.feature_search_filter_options_loans_value
import androidclient.feature.search.generated.resources.feature_search_filter_options_savings_label
import androidclient.feature.search.generated.resources.feature_search_filter_options_savings_value
import androidx.compose.runtime.mutableStateOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
Expand All @@ -24,6 +33,8 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import org.jetbrains.compose.resources.StringResource
import org.jetbrains.compose.resources.getString

class SearchViewModel(
private val searchRepository: SearchRepository,
Expand Down Expand Up @@ -96,7 +107,7 @@ class SearchViewModel(
state.value = state.value.copy(showEmptyError = false)
searchJob = searchRepository.searchResources(
query = state.value.searchText,
resources = state.value.selectedFilter?.value,
resources = state.value.selectedFilter?.let { getString(it.valueRes) },
exactMatch = state.value.exactMatch,
).onStart {
searchResultState.update { SearchResultState.Loading }
Expand Down Expand Up @@ -157,16 +168,27 @@ sealed interface SearchScreenEvent {
data object PerformSearch : SearchScreenEvent
}

sealed class FilterOption(val label: String, val value: String) {
sealed class FilterOption(val labelRes: StringResource, val valueRes: StringResource) {

data object Clients : FilterOption(label = "Clients", value = "clients")
data object Clients : FilterOption(
labelRes = Res.string.feature_search_filter_options_clients_label,
valueRes = Res.string.feature_search_filter_options_clients_value,
)

data object Groups : FilterOption(label = "Groups", value = "groups")
data object Groups : FilterOption(
labelRes = Res.string.feature_search_filter_options_groups_label,
valueRes = Res.string.feature_search_filter_options_groups_value,
)

data object LoanAccounts : FilterOption(label = "Loan Accounts", value = "loans")
data object LoanAccounts : FilterOption(
labelRes = Res.string.feature_search_filter_options_loans_label,
valueRes = Res.string.feature_search_filter_options_loans_value,
)

data object SavingsAccounts :
FilterOption(label = "Savings Accounts", value = "savingsaccounts")
data object SavingsAccounts : FilterOption(
labelRes = Res.string.feature_search_filter_options_savings_label,
valueRes = Res.string.feature_search_filter_options_savings_value,
)

companion object {
val values = listOf(Clients, Groups, LoanAccounts, SavingsAccounts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal fun FilterDialog(
HorizontalDivider()
FilterOption.values.forEachIndexed { index, option ->
FilterOption(
text = option.label,
text = stringResource(option.labelRes),
selected = option == selectedFilter,
onSelected = {
selectedFilter = option
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package com.mifos.feature.search.components

import androidclient.feature.search.generated.resources.Res
import androidclient.feature.search.generated.resources.feature_search_all
import androidclient.feature.search.generated.resources.feature_search_empty_input_field
import androidclient.feature.search.generated.resources.feature_search_exact_match
import androidclient.feature.search.generated.resources.feature_search_search_hint
Expand Down Expand Up @@ -83,7 +84,8 @@ internal fun SearchBox(
},
label = {
Text(
text = state.selectedFilter?.label ?: "All",
text = state.selectedFilter?.let { stringResource(it.labelRes) }
?: stringResource(Res.string.feature_search_all),
style = MaterialTheme.typography.bodyLarge,
)
},
Expand Down