mirror of
https://github.com/home-assistant/android
synced 2024-07-23 19:34:23 +00:00
Resume Assist voice input on new intent (as assistant app/brought to front) (#3692)
* Resume Assist voice input on new intent (as assistant app/brought to front) * Use constants for android.intent.action.ASSIST - android.intent.action.VOICE_ASSIST is marked as internal
This commit is contained in:
parent
605e6ec914
commit
e4f697fc3b
|
@ -146,4 +146,10 @@ class AssistActivity : BaseActivity() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
viewModel.onPause()
|
viewModel.onPause()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
this.intent = intent
|
||||||
|
viewModel.onNewIntent(intent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.homeassistant.companion.android.assist
|
package io.homeassistant.companion.android.assist
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Intent
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
@ -101,6 +102,18 @@ class AssistViewModel @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onNewIntent(intent: Intent?) {
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
(intent?.flags != null && intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) ||
|
||||||
|
intent?.action in listOf(Intent.ACTION_ASSIST, "android.intent.action.VOICE_ASSIST")
|
||||||
|
) &&
|
||||||
|
(inputMode == AssistInputMode.VOICE_ACTIVE || inputMode == AssistInputMode.VOICE_INACTIVE)
|
||||||
|
) {
|
||||||
|
onMicrophoneInput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun getInput(): AssistInputMode? = inputMode
|
override fun getInput(): AssistInputMode? = inputMode
|
||||||
|
|
||||||
override fun setInput(inputMode: AssistInputMode) {
|
override fun setInput(inputMode: AssistInputMode) {
|
||||||
|
|
|
@ -90,6 +90,7 @@
|
||||||
android:name=".conversation.ConversationActivity"
|
android:name=".conversation.ConversationActivity"
|
||||||
android:icon="@mipmap/ic_assist_launcher"
|
android:icon="@mipmap/ic_assist_launcher"
|
||||||
android:label="@string/ha_assist"
|
android:label="@string/ha_assist"
|
||||||
|
android:launchMode="singleTask"
|
||||||
android:exported="true">
|
android:exported="true">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
|
@ -78,6 +78,16 @@ class ConversationActivity : ComponentActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onNewIntent(intent: Intent?) {
|
||||||
|
super.onNewIntent(intent)
|
||||||
|
this.intent = intent
|
||||||
|
|
||||||
|
val launchIntent = conversationViewModel.onNewIntent(intent)
|
||||||
|
if (launchIntent) {
|
||||||
|
launchVoiceInputIntent()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun launchVoiceInputIntent() {
|
private fun launchVoiceInputIntent() {
|
||||||
val searchIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
|
val searchIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
|
||||||
putExtra(
|
putExtra(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.homeassistant.companion.android.conversation
|
package io.homeassistant.companion.android.conversation
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.content.Intent
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateListOf
|
import androidx.compose.runtime.mutableStateListOf
|
||||||
|
@ -99,6 +100,24 @@ class ConversationViewModel @Inject constructor(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return `true` if the voice input intent should be fired */
|
||||||
|
fun onNewIntent(intent: Intent?): Boolean {
|
||||||
|
if (
|
||||||
|
(
|
||||||
|
(intent?.flags != null && intent.flags and Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT != 0) ||
|
||||||
|
intent?.action in listOf(Intent.ACTION_ASSIST, "android.intent.action.VOICE_ASSIST")
|
||||||
|
) &&
|
||||||
|
inputMode != AssistInputMode.BLOCKED
|
||||||
|
) {
|
||||||
|
if (inputMode == AssistInputMode.TEXT) {
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
onMicrophoneInput()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
override fun getInput(): AssistInputMode = inputMode
|
override fun getInput(): AssistInputMode = inputMode
|
||||||
|
|
||||||
override fun setInput(inputMode: AssistInputMode) {
|
override fun setInput(inputMode: AssistInputMode) {
|
||||||
|
|
Loading…
Reference in a new issue