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

feat: Add toggle for showing previous title suggestions in transactio… #3466

Merged
merged 3 commits into from
Sep 3, 2024
Merged
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 @@ -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
ILIYANGERMANOV marked this conversation as resolved.
Show resolved Hide resolved
) {
@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(
akashs056 marked this conversation as resolved.
Show resolved Hide resolved
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