Skip to content

Commit ca8fccd

Browse files
committed
Add entry point feature toggle
1 parent b852f81 commit ca8fccd

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/RealDuckChat.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@ interface DuckChatInternal : DuckChat {
146146
*/
147147
fun isAddressBarEntryPointEnabled(): Boolean
148148

149+
/**
150+
* Returns whether voice search entry point is enabled or not.
151+
*/
152+
fun isVoiceSearchEntryPointEnabled(): Boolean
153+
149154
/**
150155
* Returns whether DuckChat is user enabled or not.
151156
*/
@@ -287,6 +292,7 @@ class RealDuckChat @Inject constructor(
287292
private var duckChatLink = DUCK_CHAT_WEB_LINK
288293
private var bangRegex: Regex? = null
289294
private var isAddressBarEntryPointEnabled: Boolean = false
295+
private var isVoiceSearchEntryPointEnabled: Boolean = false
290296
private var isImageUploadEnabled: Boolean = false
291297
private var keepSessionAliveInMinutes: Int = DEFAULT_SESSION_ALIVE
292298
private var clearChatHistory: Boolean = true
@@ -383,6 +389,7 @@ class RealDuckChat @Inject constructor(
383389
}
384390

385391
override fun isAddressBarEntryPointEnabled(): Boolean = isAddressBarEntryPointEnabled
392+
override fun isVoiceSearchEntryPointEnabled(): Boolean = isVoiceSearchEntryPointEnabled
386393

387394
override fun isDuckChatUserEnabled(): Boolean = isDuckChatUserEnabled
388395

@@ -646,6 +653,7 @@ class RealDuckChat @Inject constructor(
646653
bangRegex = settingsJson.aiChatBangRegex?.replace("{bangs}", bangAlternation)?.toRegex()
647654
}
648655
isAddressBarEntryPointEnabled = settingsJson?.addressBarEntryPoint ?: false
656+
isVoiceSearchEntryPointEnabled = duckChatFeature.duckAiVoiceSearch().isEnabled()
649657
isImageUploadEnabled = imageUploadFeature.self().isEnabled()
650658

651659
keepSession.value = duckChatFeature.keepSession().isEnabled()
@@ -690,7 +698,7 @@ class RealDuckChat @Inject constructor(
690698

691699
val showVoiceSearchToggle =
692700
duckChatFeatureRepository.shouldShowInVoiceSearch() &&
693-
isDuckChatFeatureEnabled && isDuckChatUserEnabled
701+
isDuckChatFeatureEnabled && isDuckChatUserEnabled && isVoiceSearchEntryPointEnabled
694702
_showVoiceSearchToggle.emit(showVoiceSearchToggle)
695703
}
696704

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/feature/DuckChatFeature.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,12 @@ interface DuckChatFeature {
102102
*/
103103
@Toggle.DefaultValue(DefaultFeatureValue.INTERNAL)
104104
fun showMainButtonsInInputScreen(): Toggle
105+
106+
/**
107+
* @return `true` when the remote config has the "duckAiVoiceSearch"
108+
* sub-feature flag enabled
109+
* If the remote feature is not present defaults to `internal`
110+
*/
111+
@Toggle.DefaultValue(DefaultFeatureValue.INTERNAL)
112+
fun duckAiVoiceSearch(): Toggle
105113
}

duckchat/duckchat-impl/src/main/java/com/duckduckgo/duckchat/impl/ui/settings/DuckAiShortcutSettingsViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class DuckAiShortcutSettingsViewModel @Inject constructor(
5353
showInAddressBar = showInAddressBar,
5454
showInVoiceSearch = showInVoiceSearch,
5555
shouldShowAddressBarToggle = duckChat.isAddressBarEntryPointEnabled(),
56-
shouldShowVoiceSearchToggle = showVoiceSearchToggle,
56+
shouldShowVoiceSearchToggle = duckChat.isVoiceSearchEntryPointEnabled(),
5757
)
5858
}.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), ViewState())
5959

0 commit comments

Comments
 (0)