This commit is contained in:
@@ -7,6 +7,11 @@ import androidx.lifecycle.DefaultLifecycleObserver
|
|||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import farm.hobbs.clippyauto.VoiceLoop
|
import farm.hobbs.clippyauto.VoiceLoop
|
||||||
import farm.hobbs.clippyauto.matrix.MatrixRestClient
|
import farm.hobbs.clippyauto.matrix.MatrixRestClient
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.SupervisorJob
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Android Auto session — manages the lifecycle of a Clippy voice interaction.
|
* Android Auto session — manages the lifecycle of a Clippy voice interaction.
|
||||||
@@ -16,6 +21,7 @@ class ClippySession : Session(), DefaultLifecycleObserver {
|
|||||||
|
|
||||||
private var voiceLoop: VoiceLoop? = null
|
private var voiceLoop: VoiceLoop? = null
|
||||||
private var screen: ClippyScreen? = null
|
private var screen: ClippyScreen? = null
|
||||||
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||||
|
|
||||||
// TODO: Move to SharedPreferences via SetupActivity
|
// TODO: Move to SharedPreferences via SetupActivity
|
||||||
companion object {
|
companion object {
|
||||||
@@ -42,15 +48,15 @@ class ClippySession : Session(), DefaultLifecycleObserver {
|
|||||||
matrixClient = matrixClient,
|
matrixClient = matrixClient,
|
||||||
roomId = ROOM_ID,
|
roomId = ROOM_ID,
|
||||||
clippyUserId = CLIPPY_USER,
|
clippyUserId = CLIPPY_USER,
|
||||||
onStateChange = { state, status ->
|
onStateChange = { _, status ->
|
||||||
screen?.updateStatus(status)
|
screen?.updateStatus(status)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// Login then initialize voice loop
|
// Login then initialize voice loop
|
||||||
kotlinx.coroutines.CoroutineScope(kotlinx.coroutines.Dispatchers.IO).launch {
|
scope.launch {
|
||||||
val loggedIn = matrixClient.login(MATRIX_USER, MATRIX_PASS)
|
val loggedIn = matrixClient.login(MATRIX_USER, MATRIX_PASS)
|
||||||
kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
if (loggedIn) {
|
if (loggedIn) {
|
||||||
voiceLoop?.initialize()
|
voiceLoop?.initialize()
|
||||||
voiceLoop?.startSession()
|
voiceLoop?.startSession()
|
||||||
|
|||||||
Reference in New Issue
Block a user