Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.wstxda.switchai.assistant

import android.content.Intent
import androidx.core.net.toUri
import com.wstxda.switchai.R
import com.wstxda.switchai.activity.AssistantActivity
import com.wstxda.switchai.logic.PreferenceHelper
import com.wstxda.switchai.logic.openAssistant
import com.wstxda.switchai.logic.openAssistantShizuku
import com.wstxda.switchai.utils.AssistantProperties
import com.wstxda.switchai.utils.Constants

class ChatGPTAssistant : AssistantActivity() {
private val preferences by lazy { PreferenceHelper(this) }
Expand All @@ -30,8 +33,15 @@ class ChatGPTAssistant : AssistantActivity() {
}

private fun openChatGPT() {
val intents = buildList {
if (preferences.getBoolean(Constants.VOICE_INPUT_PREF_KEY, true)) {
add(Intent(Intent.ACTION_VIEW, "https://chatgpt.com/voice".toUri())
.setPackage(Companion.packageName))
}
add(createChatGPTIntent())
}
openAssistant(
intents = listOf(createChatGPTIntent()),
intents = intents,
errorMessage = R.string.assistant_application_not_found
)
}
Expand All @@ -47,4 +57,4 @@ class ChatGPTAssistant : AssistantActivity() {
defaultActivity = "com.openai.chatgpt.MainActivity",
voiceInputActivity = "com.openai.voice.assistant.AssistantActivity"
)
}
}
17 changes: 14 additions & 3 deletions app/src/main/java/com/wstxda/switchai/assistant/GeminiAssistant.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.wstxda.switchai.assistant

import android.content.Intent
import androidx.core.net.toUri
import com.wstxda.switchai.R
import com.wstxda.switchai.activity.AssistantActivity
import com.wstxda.switchai.logic.PreferenceHelper
import com.wstxda.switchai.logic.openAssistant
import com.wstxda.switchai.logic.openAssistantShizuku
import com.wstxda.switchai.utils.AssistantProperties
import com.wstxda.switchai.utils.Constants

class GeminiAssistant : AssistantActivity() {
private val preferences by lazy { PreferenceHelper(this) }
Expand All @@ -30,9 +33,17 @@ class GeminiAssistant : AssistantActivity() {
}

private fun openGemini() {
val intents = buildList {
if (preferences.getBoolean(Constants.VOICE_INPUT_PREF_KEY, true)) {
add(Intent(Intent.ACTION_VIEW, "https://gemini.google.com/app?target=live".toUri())
.setPackage("com.google.android.googlequicksearchbox"))
Comment thread
random-ua marked this conversation as resolved.
Resolved
}
add(createGeminiIntent())
}
openAssistant(
intents = listOf(createGeminiIntent()),
errorMessage = R.string.assistant_application_not_found
intents = intents,
errorMessage = R.string.assistant_application_not_found,
storePackageName = Companion.packageName
)
}

Expand All @@ -47,4 +58,4 @@ class GeminiAssistant : AssistantActivity() {
defaultActivity = "com.google.android.apps.search.assistant.surfaces.voice.robin.main.MainActivity",
voiceInputActivity = "com.google.android.apps.search.assistant.surfaces.voice.robin.ui.floaty.activity.FloatyActivity"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fun Context.onAssistantOpened() {
fun Context.openAssistant(
intents: List<Intent>,
errorMessage: Int,
storePackageName: String? = null,
): Boolean {
intents.forEach { intent ->
if (openAssistant(intent)) {
Expand All @@ -29,7 +30,7 @@ fun Context.openAssistant(
}
}

val pkg = intents.firstNotNullOfOrNull { intent ->
val pkg = storePackageName ?: intents.firstNotNullOfOrNull { intent ->
(intent.component?.packageName ?: intent.`package`)?.takeIf { it.isNotBlank() }
} ?: runCatching {
(this::class.companionObjectInstance as? AssistantProperties)?.packageName?.takeIf { it.isNotBlank() }
Expand Down Expand Up @@ -111,4 +112,4 @@ fun Context.openOnStore(packageName: String): Boolean {

fun Context.showToast(message: Int) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
Loading