diff --git a/app/src/main/java/com/wstxda/switchai/assistant/ChatGPTAssistant.kt b/app/src/main/java/com/wstxda/switchai/assistant/ChatGPTAssistant.kt index 3787edf..0d475da 100644 --- a/app/src/main/java/com/wstxda/switchai/assistant/ChatGPTAssistant.kt +++ b/app/src/main/java/com/wstxda/switchai/assistant/ChatGPTAssistant.kt @@ -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) } @@ -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 ) } @@ -47,4 +57,4 @@ class ChatGPTAssistant : AssistantActivity() { defaultActivity = "com.openai.chatgpt.MainActivity", voiceInputActivity = "com.openai.voice.assistant.AssistantActivity" ) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/wstxda/switchai/assistant/GeminiAssistant.kt b/app/src/main/java/com/wstxda/switchai/assistant/GeminiAssistant.kt index b89f22c..11d8754 100644 --- a/app/src/main/java/com/wstxda/switchai/assistant/GeminiAssistant.kt +++ b/app/src/main/java/com/wstxda/switchai/assistant/GeminiAssistant.kt @@ -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) } @@ -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")) + } + 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 ) } @@ -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" ) -} \ No newline at end of file +} diff --git a/app/src/main/java/com/wstxda/switchai/logic/AssistantLauncher.kt b/app/src/main/java/com/wstxda/switchai/logic/AssistantLauncher.kt index 8c30fce..d19fcdc 100644 --- a/app/src/main/java/com/wstxda/switchai/logic/AssistantLauncher.kt +++ b/app/src/main/java/com/wstxda/switchai/logic/AssistantLauncher.kt @@ -21,6 +21,7 @@ fun Context.onAssistantOpened() { fun Context.openAssistant( intents: List, errorMessage: Int, + storePackageName: String? = null, ): Boolean { intents.forEach { intent -> if (openAssistant(intent)) { @@ -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() } @@ -111,4 +112,4 @@ fun Context.openOnStore(packageName: String): Boolean { fun Context.showToast(message: Int) { Toast.makeText(this, message, Toast.LENGTH_SHORT).show() -} \ No newline at end of file +}