mirror of
https://github.com/home-assistant/android
synced 2024-07-22 10:54:12 +00:00
Add 'Manage assistants' button to native Assist (#3616)
This commit is contained in:
parent
48a7755e62
commit
2023268e37
|
@ -23,6 +23,7 @@ import dagger.hilt.android.AndroidEntryPoint
|
|||
import io.homeassistant.companion.android.BaseActivity
|
||||
import io.homeassistant.companion.android.assist.ui.AssistSheetView
|
||||
import io.homeassistant.companion.android.common.data.servers.ServerManager
|
||||
import io.homeassistant.companion.android.webview.WebViewActivity
|
||||
|
||||
@AndroidEntryPoint
|
||||
class AssistActivity : BaseActivity() {
|
||||
|
@ -90,6 +91,8 @@ class AssistActivity : BaseActivity() {
|
|||
)
|
||||
}
|
||||
|
||||
val fromFrontend = intent.getBooleanExtra(EXTRA_FROM_FRONTEND, false)
|
||||
|
||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||
setContent {
|
||||
MdcTheme {
|
||||
|
@ -103,9 +106,25 @@ class AssistActivity : BaseActivity() {
|
|||
conversation = viewModel.conversation,
|
||||
pipelines = viewModel.pipelines,
|
||||
inputMode = viewModel.inputMode,
|
||||
fromFrontend = intent.getBooleanExtra(EXTRA_FROM_FRONTEND, false),
|
||||
fromFrontend = fromFrontend,
|
||||
currentPipeline = viewModel.currentPipeline,
|
||||
onSelectPipeline = viewModel::changePipeline,
|
||||
onManagePipelines =
|
||||
if (fromFrontend && viewModel.userCanManagePipelines()) {
|
||||
{
|
||||
startActivity(
|
||||
WebViewActivity.newInstance(
|
||||
this,
|
||||
"config/voice-assistants/assistants"
|
||||
).apply {
|
||||
flags += Intent.FLAG_ACTIVITY_NEW_TASK // Delivers data in onNewIntent
|
||||
}
|
||||
)
|
||||
finish()
|
||||
}
|
||||
} else {
|
||||
null
|
||||
},
|
||||
onChangeInput = viewModel::onChangeInput,
|
||||
onTextInput = viewModel::onTextInput,
|
||||
onMicrophoneInput = viewModel::onMicrophoneInput,
|
||||
|
|
|
@ -127,6 +127,8 @@ class AssistViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun userCanManagePipelines(): Boolean = serverManager.getServer()?.user?.isAdmin == true
|
||||
|
||||
fun changePipeline(serverId: Int, id: String) = viewModelScope.launch {
|
||||
if (serverId == selectedServerId && id == selectedPipeline?.id) return@launch
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
|||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Divider
|
||||
import androidx.compose.material.DropdownMenu
|
||||
import androidx.compose.material.DropdownMenuItem
|
||||
import androidx.compose.material.ExperimentalMaterialApi
|
||||
|
@ -91,6 +92,7 @@ fun AssistSheetView(
|
|||
currentPipeline: AssistUiPipeline?,
|
||||
fromFrontend: Boolean,
|
||||
onSelectPipeline: (Int, String) -> Unit,
|
||||
onManagePipelines: (() -> Unit)?,
|
||||
onChangeInput: () -> Unit,
|
||||
onTextInput: (String) -> Unit,
|
||||
onMicrophoneInput: () -> Unit,
|
||||
|
@ -133,7 +135,8 @@ fun AssistSheetView(
|
|||
pipelines = pipelines,
|
||||
currentPipeline = currentPipeline,
|
||||
fromFrontend = fromFrontend,
|
||||
onSelectPipeline = onSelectPipeline
|
||||
onSelectPipeline = onSelectPipeline,
|
||||
onManagePipelines = onManagePipelines
|
||||
)
|
||||
LazyColumn(
|
||||
state = lazyListState,
|
||||
|
@ -169,7 +172,8 @@ fun AssistSheetHeader(
|
|||
pipelines: List<AssistUiPipeline>,
|
||||
currentPipeline: AssistUiPipeline?,
|
||||
fromFrontend: Boolean,
|
||||
onSelectPipeline: (Int, String) -> Unit
|
||||
onSelectPipeline: (Int, String) -> Unit,
|
||||
onManagePipelines: (() -> Unit)?
|
||||
) = Column(verticalArrangement = Arrangement.Center) {
|
||||
Text(
|
||||
text = stringResource(if (fromFrontend) commonR.string.assist else commonR.string.app_name),
|
||||
|
@ -219,6 +223,12 @@ fun AssistSheetHeader(
|
|||
)
|
||||
}
|
||||
}
|
||||
if (onManagePipelines != null) {
|
||||
Divider()
|
||||
DropdownMenuItem(onClick = { onManagePipelines() }) {
|
||||
Text(stringResource(commonR.string.assist_manage_pipelines))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1078,6 +1078,7 @@
|
|||
<string name="assist_error">Oops, an error has occurred</string>
|
||||
<string name="assist_how_can_i_assist">How can I assist?</string>
|
||||
<string name="assist_log_in">Log in to Home Assistant to start using Assist</string>
|
||||
<string name="assist_manage_pipelines">Manage assistants</string>
|
||||
<string name="assist_permission">To use Assist with your voice, allow Home Assistant to access the microphone</string>
|
||||
<string name="assist_pipeline">Assistant</string>
|
||||
<string name="assist_preferred_pipeline">Preferred assistant (%1$s)</string>
|
||||
|
|
Loading…
Reference in a new issue