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

Commit

Permalink
feat: Add toggle for showing previous title suggestions in transactio… (
Browse files Browse the repository at this point in the history
#3466)

* feat: Add toggle for showing previous title suggestions in transaction editor

* remove showTitleSuggestion state

* removed showTitleSuggestions  state
  • Loading branch information
akashs056 authored Sep 3, 2024
1 parent 607f6b2 commit 0ff49ef
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ class EditTransactionViewModel @Inject constructor(

@Composable
private fun getTitleSuggestions(): ImmutableSet<String> {
return titleSuggestions.value
return if (features.showTitleSuggestions.asEnabledState()) {
titleSuggestions.value
} else {
persistentSetOf()
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ private fun BoxWithConstraintsScope.UI(
titleTextFieldValue = it
},
suggestions = emptySet(), // DO NOT display title suggestions for "Planned Payments"

onTitleChanged = { onEvent(EditPlannedScreenEvent.OnTitleChanged(it)) },
onNext = {
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ class BoolFeature(
val key: String,
val name: String? = null,
val description: String? = null,
private val defaultValue: Boolean = false
) {
@Composable
fun asEnabledState(): Boolean {
val context = LocalContext.current
val featureFlag = remember { enabledFlow(context) }
.collectAsState(false).value
return featureFlag ?: false
.collectAsState(defaultValue).value
return featureFlag ?: defaultValue
}

suspend fun isEnabled(appContext: Context): Boolean =
enabledFlow(appContext).first() ?: false
enabledFlow(appContext).first() ?: defaultValue

fun enabledFlow(appContext: Context): Flow<Boolean?> = appContext.dataStore
.data.map {
it[featureKey]
it[featureKey] ?: defaultValue
}

suspend fun set(appContext: Context, enabled: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface Features {
val sortCategoriesAlphabetically: BoolFeature
val compactAccountsMode: BoolFeature
val compactCategoriesMode: BoolFeature
val showTitleSuggestions: BoolFeature

val allFeatures: List<BoolFeature>
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,18 @@ class IvyFeatures @Inject constructor() : Features {
description = "Activates a more streamlined and space-efficient interface for the \"Categories\" Screen"
)

override val showTitleSuggestions = BoolFeature(
key = "show_title_suggestions",
name = "Show previous title suggestions",
description = "Enables display of previous transaction titles when editing or creating a new transaction",
defaultValue = true
)

override val allFeatures: List<BoolFeature>
get() = listOf(
sortCategoriesAlphabetically,
compactAccountsMode,
compactCategoriesMode
compactCategoriesMode,
showTitleSuggestions
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,11 @@ fun ColumnScope.Title(
type: TransactionType,
titleFocus: FocusRequester,
initialTransactionId: UUID?,

titleTextFieldValue: TextFieldValue,
setTitleTextFieldValue: (TextFieldValue) -> Unit,
suggestions: Set<String>,
scrollState: ScrollState? = null,

onTitleChanged: (String?) -> Unit,
scrollState: ScrollState? = null,
onNext: () -> Unit,
) {
IvyTitleTextField(
Expand Down

0 comments on commit 0ff49ef

Please sign in to comment.