From 0ff49ef84b68e5017cffbcc525b4d2fda2200431 Mon Sep 17 00:00:00 2001 From: Akash Subramanian <152642367+akashs056@users.noreply.github.com> Date: Tue, 3 Sep 2024 17:38:17 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20Add=20toggle=20for=20showing=20previous?= =?UTF-8?q?=20title=20suggestions=20in=20transactio=E2=80=A6=20(#3466)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add toggle for showing previous title suggestions in transaction editor * remove showTitleSuggestion state * removed showTitleSuggestions state --- .../com/ivy/transaction/EditTransactionViewModel.kt | 6 +++++- .../java/com/ivy/planned/edit/EditPlannedScreen.kt | 1 - .../main/java/com/ivy/domain/features/BoolFeature.kt | 9 +++++---- .../src/main/java/com/ivy/domain/features/Features.kt | 1 + .../main/java/com/ivy/domain/features/IvyFeatures.kt | 10 +++++++++- .../com/ivy/legacy/ui/component/edit/core/Title.kt | 4 +--- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt b/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt index 339684a8f8..0574322227 100644 --- a/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt +++ b/screen/edit-transaction/src/main/java/com/ivy/transaction/EditTransactionViewModel.kt @@ -222,7 +222,11 @@ class EditTransactionViewModel @Inject constructor( @Composable private fun getTitleSuggestions(): ImmutableSet { - return titleSuggestions.value + return if (features.showTitleSuggestions.asEnabledState()) { + titleSuggestions.value + } else { + persistentSetOf() + } } @Composable diff --git a/screen/planned-payments/src/main/java/com/ivy/planned/edit/EditPlannedScreen.kt b/screen/planned-payments/src/main/java/com/ivy/planned/edit/EditPlannedScreen.kt index 39efe51427..8ffe95c7b0 100644 --- a/screen/planned-payments/src/main/java/com/ivy/planned/edit/EditPlannedScreen.kt +++ b/screen/planned-payments/src/main/java/com/ivy/planned/edit/EditPlannedScreen.kt @@ -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 { diff --git a/shared/domain/src/main/java/com/ivy/domain/features/BoolFeature.kt b/shared/domain/src/main/java/com/ivy/domain/features/BoolFeature.kt index f921359432..f12e7a86dd 100644 --- a/shared/domain/src/main/java/com/ivy/domain/features/BoolFeature.kt +++ b/shared/domain/src/main/java/com/ivy/domain/features/BoolFeature.kt @@ -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 = appContext.dataStore .data.map { - it[featureKey] + it[featureKey] ?: defaultValue } suspend fun set(appContext: Context, enabled: Boolean) { 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 42e5947bd5..0fa57609eb 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 @@ -4,6 +4,7 @@ interface Features { val sortCategoriesAlphabetically: BoolFeature val compactAccountsMode: BoolFeature val compactCategoriesMode: BoolFeature + val showTitleSuggestions: 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 7929a03bf8..54e857683f 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 @@ -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 get() = listOf( sortCategoriesAlphabetically, compactAccountsMode, - compactCategoriesMode + compactCategoriesMode, + showTitleSuggestions ) } diff --git a/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/edit/core/Title.kt b/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/edit/core/Title.kt index c9e0af82be..d5748cc0c6 100644 --- a/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/edit/core/Title.kt +++ b/temp/legacy-code/src/main/java/com/ivy/legacy/ui/component/edit/core/Title.kt @@ -42,13 +42,11 @@ fun ColumnScope.Title( type: TransactionType, titleFocus: FocusRequester, initialTransactionId: UUID?, - titleTextFieldValue: TextFieldValue, setTitleTextFieldValue: (TextFieldValue) -> Unit, suggestions: Set, - scrollState: ScrollState? = null, - onTitleChanged: (String?) -> Unit, + scrollState: ScrollState? = null, onNext: () -> Unit, ) { IvyTitleTextField(