-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update widgets to match the changes in DuckChat interface #6624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,7 @@ import android.content.Context | |||||||
import android.content.Intent | ||||||||
import android.view.View | ||||||||
import android.widget.RemoteViews | ||||||||
import com.duckduckgo.app.browser.BrowserActivity | ||||||||
import com.duckduckgo.app.browser.R | ||||||||
import com.duckduckgo.app.systemsearch.SystemSearchActivity | ||||||||
import com.duckduckgo.common.utils.DispatcherProvider | ||||||||
|
@@ -41,13 +42,9 @@ class SearchWidgetConfigurator @Inject constructor( | |||||||
remoteViews: RemoteViews, | ||||||||
fromFavWidget: Boolean, | ||||||||
) { | ||||||||
val voiceSearchEnabled = withContext(dispatcherProvider.io()) { | ||||||||
voiceSearchAvailability.isVoiceSearchAvailable | ||||||||
val (voiceSearchEnabled, duckAiEnabled) = withContext(dispatcherProvider.io()) { | ||||||||
voiceSearchAvailability.isVoiceSearchAvailable to (duckChat.isEnabled() && duckChat.wasOpenedBefore()) | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The complex boolean expression for duckAiEnabled should be extracted to improve readability. Consider creating a separate variable or method for the DuckChat availability check. Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||
} | ||||||||
val duckAiIntent = withContext(dispatcherProvider.io()) { | ||||||||
duckChat.createDuckChatIntent() | ||||||||
} | ||||||||
val duckAiEnabled = duckAiIntent != null | ||||||||
|
||||||||
logcat { "SearchWidgetConfigurator voiceSearchEnabled=$voiceSearchEnabled, duckAiEnabled=$duckAiEnabled" } | ||||||||
|
||||||||
|
@@ -63,7 +60,7 @@ class SearchWidgetConfigurator @Inject constructor( | |||||||
} | ||||||||
|
||||||||
if (duckAiEnabled) { | ||||||||
val pendingIntent = buildDuckAiPendingIntent(context, duckAiIntent!!) | ||||||||
val pendingIntent = buildDuckAiPendingIntent(context) | ||||||||
remoteViews.setOnClickPendingIntent(R.id.duckAi, pendingIntent) | ||||||||
} | ||||||||
} | ||||||||
|
@@ -79,8 +76,8 @@ class SearchWidgetConfigurator @Inject constructor( | |||||||
|
||||||||
private fun buildDuckAiPendingIntent( | ||||||||
context: Context, | ||||||||
intent: Intent, | ||||||||
): PendingIntent { | ||||||||
val intent = BrowserActivity.intent(context, openDuckChat = true).also { it.action = Intent.ACTION_VIEW } | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Built the intent directly here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] The intent creation and action setting should be separated for better readability. Consider creating the intent first, then setting the action on a separate line.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||
return PendingIntent.getActivity(context, 2, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) | ||||||||
} | ||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,6 @@ | |
|
||
package com.duckduckgo.duckchat.api | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
|
||
/** | ||
|
@@ -36,14 +35,6 @@ interface DuckChat { | |
*/ | ||
fun openDuckChat() | ||
|
||
/** | ||
* Creates an Intent that can be used to launch the DuckChat WebView. | ||
* Does not actually open DuckChat, just prepares the Intent. | ||
* | ||
* @return Intent that can be used to open DuckChat, or null if DuckChat cannot be opened. | ||
*/ | ||
suspend fun createDuckChatIntent(): Intent? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed as it's not needed anymore. |
||
|
||
/** | ||
* Auto-prompts the DuckChat WebView with the provided [String] query. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -380,21 +380,6 @@ class RealDuckChat @Inject constructor( | |
openDuckChat(emptyMap()) | ||
} | ||
|
||
override suspend fun createDuckChatIntent(): Intent? { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed as it's not needed anymore. |
||
logcat { "Duck.ai: createDuckChatIntent" } | ||
if (!isDuckChatEnabled || !isDuckChatUserEnabled || !wasOpenedBefore()) { | ||
logcat { "Duck.ai: createDuckChatIntent. DuckChat is not enabled or opened before, returning null" } | ||
return null | ||
} | ||
|
||
val parameters = addChatParameters("", autoPrompt = false) | ||
val url = appendParameters(parameters, duckChatLink) | ||
|
||
return browserNav.openDuckChat(context, duckChatUrl = url, hasSessionActive = true) | ||
.apply { | ||
flags = Intent.FLAG_ACTIVITY_NEW_TASK | ||
} | ||
} | ||
override fun openDuckChatWithAutoPrompt(query: String) { | ||
logcat { "Duck.ai: openDuckChatWithAutoPrompt query $query" } | ||
val parameters = addChatParameters(query, autoPrompt = true) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️