diff --git a/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt b/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt index 5f8fd38cd4..e55719c897 100644 --- a/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt +++ b/screen/categories/src/main/java/com/ivy/categories/CategoriesScreen.kt @@ -51,9 +51,11 @@ import com.ivy.data.model.primitive.IconAsset import com.ivy.data.model.primitive.NotBlankTrimmedString import com.ivy.design.l0_system.UI import com.ivy.design.l0_system.style +import com.ivy.legacy.ui.SearchInput import com.ivy.legacy.utils.balancePrefix import com.ivy.legacy.utils.compactBalancePrefix import com.ivy.legacy.utils.format +import com.ivy.legacy.utils.selectEndTextFieldValue import com.ivy.navigation.CategoriesScreen import com.ivy.navigation.TransactionsScreen import com.ivy.navigation.navigation @@ -100,7 +102,10 @@ fun BoxWithConstraintsScope.CategoriesScreen(screen: CategoriesScreen) { @Composable private fun BoxWithConstraintsScope.UI( - state: CategoriesScreenState = CategoriesScreenState(compactCategoriesModeEnabled = false), + state: CategoriesScreenState = CategoriesScreenState( + compactCategoriesModeEnabled = false, + showCategorySearchBar = false + ), onEvent: (CategoriesScreenEvent) -> Unit = {} ) { val nav = navigation() @@ -158,6 +163,10 @@ private fun BoxWithConstraintsScope.UI( Spacer(Modifier.width(24.dp)) } + if (state.showCategorySearchBar) { + Spacer(Modifier.height(16.dp)) + SearchField(onSearch = {}) + } Spacer(Modifier.height(16.dp)) } @@ -679,11 +688,16 @@ private fun PreviewCategoriesCompactModeEnabled(theme: Theme = Theme.LIGHT) { @Preview @Composable -private fun Preview(theme: Theme = Theme.LIGHT, compactModeEnabled: Boolean = false) { +private fun Preview( + theme: Theme = Theme.LIGHT, + compactModeEnabled: Boolean = false, + displaySearchBarEnabled: Boolean = false +) { com.ivy.legacy.IvyWalletPreview(theme) { val state = CategoriesScreenState( baseCurrency = "BGN", compactCategoriesModeEnabled = compactModeEnabled, + showCategorySearchBar = displaySearchBarEnabled, categories = persistentListOf( CategoryData( category = Category( @@ -752,6 +766,27 @@ private fun Preview(theme: Theme = Theme.LIGHT, compactModeEnabled: Boolean = fa } } +@Composable +private fun SearchField( + onSearch: (String) -> Unit, +) { + var searchQueryTextFieldValue by remember { + mutableStateOf(selectEndTextFieldValue("")) + } + + SearchInput( + searchQueryTextFieldValue = searchQueryTextFieldValue, + hint = "Search categories", + focus = false, + showClearIcon = searchQueryTextFieldValue.text.isNotEmpty(), + onSetSearchQueryTextField = { + searchQueryTextFieldValue = it + onSearch(it.text) + } + ) +} + + /** For screenshot testing */ @Composable fun CategoriesScreenUiTest(isDark: Boolean) { diff --git a/screen/categories/src/main/java/com/ivy/categories/CategoriesScreenState.kt b/screen/categories/src/main/java/com/ivy/categories/CategoriesScreenState.kt index 4cbbaa5b46..7988b8196b 100644 --- a/screen/categories/src/main/java/com/ivy/categories/CategoriesScreenState.kt +++ b/screen/categories/src/main/java/com/ivy/categories/CategoriesScreenState.kt @@ -15,4 +15,6 @@ data class CategoriesScreenState( val sortOrderItems: ImmutableList = SortOrder.values().toList().toImmutableList(), val sortOrder: SortOrder = SortOrder.DEFAULT, val compactCategoriesModeEnabled: Boolean, + val showCategorySearchBar: Boolean, + ) diff --git a/screen/categories/src/main/java/com/ivy/categories/CategoriesViewModel.kt b/screen/categories/src/main/java/com/ivy/categories/CategoriesViewModel.kt index a92b8e3c7a..56cc92f2c8 100644 --- a/screen/categories/src/main/java/com/ivy/categories/CategoriesViewModel.kt +++ b/screen/categories/src/main/java/com/ivy/categories/CategoriesViewModel.kt @@ -74,6 +74,7 @@ class CategoriesViewModel @Inject constructor( sortOrder = getSortOrder(), sortModalVisible = getSortModalVisible(), compactCategoriesModeEnabled = getCompactCategoriesMode(), + showCategorySearchBar = getShowCategorySearchBar() ) } @@ -82,6 +83,11 @@ class CategoriesViewModel @Inject constructor( return features.compactCategoriesMode.asEnabledState() } + @Composable + private fun getShowCategorySearchBar(): Boolean { + return features.showCategorySearchBar.asEnabledState() + } + @Composable private fun getBaseCurrency(): String { return baseCurrency.value diff --git a/shared/domain/src/main/java/com/ivy/domain/features/Features.kt b/shared/domain/src/main/java/com/ivy/domain/features/Features.kt index 561796e3eb..fedb4c25f7 100644 --- a/shared/domain/src/main/java/com/ivy/domain/features/Features.kt +++ b/shared/domain/src/main/java/com/ivy/domain/features/Features.kt @@ -5,6 +5,7 @@ interface Features { val compactAccountsMode: BoolFeature val compactCategoriesMode: BoolFeature val showTitleSuggestions: BoolFeature + val showCategorySearchBar: BoolFeature val hideTotalBalance: BoolFeature val allFeatures: List diff --git a/shared/domain/src/main/java/com/ivy/domain/features/IvyFeatures.kt b/shared/domain/src/main/java/com/ivy/domain/features/IvyFeatures.kt index a565ce493f..ddc0764ec4 100644 --- a/shared/domain/src/main/java/com/ivy/domain/features/IvyFeatures.kt +++ b/shared/domain/src/main/java/com/ivy/domain/features/IvyFeatures.kt @@ -32,6 +32,14 @@ class IvyFeatures @Inject constructor() : Features { defaultValue = true ) + + override val showCategorySearchBar = BoolFeature( + key = "show_category_search_bar", + name = "Show category search bar", + description = "Show search bar in category screen", + defaultValue = false + ) + override val hideTotalBalance = BoolFeature( key = "hide_total_balance", name = "Hide total balance", @@ -45,6 +53,7 @@ class IvyFeatures @Inject constructor() : Features { compactAccountsMode, compactCategoriesMode, showTitleSuggestions, + showCategorySearchBar, hideTotalBalance ) } diff --git a/temp/legacy-code/src/main/java/com/ivy/legacy/ui/SearchInput.kt b/temp/legacy-code/src/main/java/com/ivy/legacy/ui/SearchInput.kt index fca8567fe6..a3af0fba77 100644 --- a/temp/legacy-code/src/main/java/com/ivy/legacy/ui/SearchInput.kt +++ b/temp/legacy-code/src/main/java/com/ivy/legacy/ui/SearchInput.kt @@ -29,6 +29,7 @@ fun SearchInput( searchQueryTextFieldValue: TextFieldValue, hint: String, focus: Boolean = true, + showClearIcon : Boolean = true, onSetSearchQueryTextField: (TextFieldValue) -> Unit ) { Row( @@ -61,13 +62,16 @@ fun SearchInput( } } - IvyIcon( - modifier = Modifier - .weight(1f) - .clickable { - onSetSearchQueryTextField(selectEndTextFieldValue("")) - }, - icon = R.drawable.ic_outline_clear_24 - ) + if(showClearIcon){ + IvyIcon( + modifier = Modifier + .weight(1f) + .clickable { + onSetSearchQueryTextField(selectEndTextFieldValue("")) + }, + icon = R.drawable.ic_outline_clear_24 + ) + } + } }