Skip to content

Commit 582abd2

Browse files
committed
Refactor DuckChatSettingsViewModel to improve AI settings handling
1 parent 824bbce commit 582abd2

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ import kotlinx.coroutines.flow.flowOn
4444
import kotlinx.coroutines.flow.receiveAsFlow
4545
import kotlinx.coroutines.flow.stateIn
4646
import kotlinx.coroutines.launch
47+
import kotlinx.coroutines.withContext
4748

4849
class DuckChatSettingsViewModel @AssistedInject constructor(
4950
@Assisted duckChatActivityParams: GlobalActivityStarter.ActivityParams,
5051
private val duckChat: DuckChatInternal,
5152
private val pixel: Pixel,
5253
private val inputScreenDiscoveryFunnel: InputScreenDiscoveryFunnel,
5354
private val settingsPageFeature: SettingsPageFeature,
54-
dispatcherProvider: DispatcherProvider,
55+
private val dispatcherProvider: DispatcherProvider,
5556
) : ViewModel() {
5657
private val commandChannel = Channel<Command>(capacity = 1, onBufferOverflow = DROP_OLDEST)
5758
val commands = commandChannel.receiveAsFlow()
@@ -142,11 +143,15 @@ class DuckChatSettingsViewModel @AssistedInject constructor(
142143

143144
fun duckChatSearchAISettingsClicked() {
144145
viewModelScope.launch {
146+
val hideAiGeneratedImagesOptionEnabled = withContext(dispatcherProvider.io()) {
147+
settingsPageFeature.hideAiGeneratedImagesOption().isEnabled()
148+
}
149+
145150
if (settingsPageFeature.embeddedSettingsWebView().isEnabled()) {
146151
commandChannel.send(
147152
OpenLink(
148153
link = DUCK_CHAT_SEARCH_AI_SETTINGS_LINK_EMBEDDED,
149-
titleRes = if (settingsPageFeature.hideAiGeneratedImagesOption().isEnabled()) {
154+
titleRes = if (hideAiGeneratedImagesOptionEnabled) {
150155
R.string.duckAiSerpSettingsTitle
151156
} else {
152157
R.string.duck_chat_assist_settings_title

0 commit comments

Comments
 (0)