Skip to content

Commit 36ca94d

Browse files
authored
Update widgets to match the changes in DuckChat interface (#6624)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1200581511062568/task/1211103096551754?focus=true ### Description Refactored the DuckChat widget integration to simplify the process of opening DuckChat from the search widget. Removed the `createDuckChatIntent()` method from the DuckChat interface and implementation, replacing it with a more direct approach that uses `BrowserActivity.intent()` with an `openDuckChat` parameter. ### Steps to test this PR Code review. ### NO UI changes
1 parent 7e511ca commit 36ca94d

File tree

3 files changed

+5
-32
lines changed

3 files changed

+5
-32
lines changed

app/src/main/java/com/duckduckgo/widget/SearchWidgetConfigurator.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.content.Context
2121
import android.content.Intent
2222
import android.view.View
2323
import android.widget.RemoteViews
24+
import com.duckduckgo.app.browser.BrowserActivity
2425
import com.duckduckgo.app.browser.R
2526
import com.duckduckgo.app.systemsearch.SystemSearchActivity
2627
import com.duckduckgo.common.utils.DispatcherProvider
@@ -41,13 +42,9 @@ class SearchWidgetConfigurator @Inject constructor(
4142
remoteViews: RemoteViews,
4243
fromFavWidget: Boolean,
4344
) {
44-
val voiceSearchEnabled = withContext(dispatcherProvider.io()) {
45-
voiceSearchAvailability.isVoiceSearchAvailable
45+
val (voiceSearchEnabled, duckAiEnabled) = withContext(dispatcherProvider.io()) {
46+
voiceSearchAvailability.isVoiceSearchAvailable to (duckChat.isEnabled() && duckChat.wasOpenedBefore())
4647
}
47-
val duckAiIntent = withContext(dispatcherProvider.io()) {
48-
duckChat.createDuckChatIntent()
49-
}
50-
val duckAiEnabled = duckAiIntent != null
5148

5249
logcat { "SearchWidgetConfigurator voiceSearchEnabled=$voiceSearchEnabled, duckAiEnabled=$duckAiEnabled" }
5350

@@ -63,7 +60,7 @@ class SearchWidgetConfigurator @Inject constructor(
6360
}
6461

6562
if (duckAiEnabled) {
66-
val pendingIntent = buildDuckAiPendingIntent(context, duckAiIntent!!)
63+
val pendingIntent = buildDuckAiPendingIntent(context)
6764
remoteViews.setOnClickPendingIntent(R.id.duckAi, pendingIntent)
6865
}
6966
}
@@ -79,8 +76,8 @@ class SearchWidgetConfigurator @Inject constructor(
7976

8077
private fun buildDuckAiPendingIntent(
8178
context: Context,
82-
intent: Intent,
8379
): PendingIntent {
80+
val intent = BrowserActivity.intent(context, openDuckChat = true).also { it.action = Intent.ACTION_VIEW }
8481
return PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
8582
}
8683
}

duckchat/duckchat-api/src/main/java/com/duckduckgo/duckchat/api/DuckChat.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package com.duckduckgo.duckchat.api
1818

19-
import android.content.Intent
2019
import android.net.Uri
2120

2221
/**
@@ -36,14 +35,6 @@ interface DuckChat {
3635
*/
3736
fun openDuckChat()
3837

39-
/**
40-
* Creates an Intent that can be used to launch the DuckChat WebView.
41-
* Does not actually open DuckChat, just prepares the Intent.
42-
*
43-
* @return Intent that can be used to open DuckChat, or null if DuckChat cannot be opened.
44-
*/
45-
suspend fun createDuckChatIntent(): Intent?
46-
4738
/**
4839
* Auto-prompts the DuckChat WebView with the provided [String] query.
4940
*/

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -380,21 +380,6 @@ class RealDuckChat @Inject constructor(
380380
openDuckChat(emptyMap())
381381
}
382382

383-
override suspend fun createDuckChatIntent(): Intent? {
384-
logcat { "Duck.ai: createDuckChatIntent" }
385-
if (!isDuckChatEnabled || !isDuckChatUserEnabled || !wasOpenedBefore()) {
386-
logcat { "Duck.ai: createDuckChatIntent. DuckChat is not enabled or opened before, returning null" }
387-
return null
388-
}
389-
390-
val parameters = addChatParameters("", autoPrompt = false)
391-
val url = appendParameters(parameters, duckChatLink)
392-
393-
return browserNav.openDuckChat(context, duckChatUrl = url, hasSessionActive = true)
394-
.apply {
395-
flags = Intent.FLAG_ACTIVITY_NEW_TASK
396-
}
397-
}
398383
override fun openDuckChatWithAutoPrompt(query: String) {
399384
logcat { "Duck.ai: openDuckChatWithAutoPrompt query $query" }
400385
val parameters = addChatParameters(query, autoPrompt = true)

0 commit comments

Comments
 (0)