Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Under dev
Browse files Browse the repository at this point in the history
  • Loading branch information
shamim-emon committed Sep 12, 2024
1 parent 6231cf5 commit b30851e
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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))
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ data class CategoriesScreenState(
val sortOrderItems: ImmutableList<SortOrder> = SortOrder.values().toList().toImmutableList(),
val sortOrder: SortOrder = SortOrder.DEFAULT,
val compactCategoriesModeEnabled: Boolean,
val showCategorySearchBar: Boolean,

)
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CategoriesViewModel @Inject constructor(
sortOrder = getSortOrder(),
sortModalVisible = getSortModalVisible(),
compactCategoriesModeEnabled = getCompactCategoriesMode(),
showCategorySearchBar = getShowCategorySearchBar()
)
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interface Features {
val compactAccountsMode: BoolFeature
val compactCategoriesMode: BoolFeature
val showTitleSuggestions: BoolFeature
val showCategorySearchBar: BoolFeature
val hideTotalBalance: BoolFeature

val allFeatures: List<BoolFeature>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -45,6 +53,7 @@ class IvyFeatures @Inject constructor() : Features {
compactAccountsMode,
compactCategoriesMode,
showTitleSuggestions,
showCategorySearchBar,
hideTotalBalance
)
}
20 changes: 12 additions & 8 deletions temp/legacy-code/src/main/java/com/ivy/legacy/ui/SearchInput.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ fun SearchInput(
searchQueryTextFieldValue: TextFieldValue,
hint: String,
focus: Boolean = true,
showClearIcon : Boolean = true,
onSetSearchQueryTextField: (TextFieldValue) -> Unit
) {
Row(
Expand Down Expand Up @@ -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
)
}

}
}

0 comments on commit b30851e

Please sign in to comment.