Skip to content

Commit

Permalink
feat: completed #32 and #30 and can now ask questions #26
Browse files Browse the repository at this point in the history
  • Loading branch information
ch3njust1n committed May 7, 2023
1 parent 6c591da commit 3844767
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
36 changes: 31 additions & 5 deletions android/app/src/main/java/co/rikin/geepee/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ class AppViewModel(private val speechToText: SpeechToText, private val context:
Log.d("Debug", context.getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).toString())
logger.logToFile("GeePee", message.content)
val apiActions = Json.decodeFromString<ApiActions>(message.content)
val commands = apiActions.actions.map { action ->
val commands = apiActions.actions.mapNotNull { action ->
when (action.component) {
"camera" -> {
val peripheral: Peripheral = when (action.subcomponent) {
"front" -> Peripheral.FrontCamera
"back" -> Peripheral.BackCamera
"cam-fr" -> Peripheral.FrontCamera
"cam-rr" -> Peripheral.BackCamera
else -> throw IllegalArgumentException("Invalid subcomponent value: ${action.subcomponent}")
}

Expand All @@ -154,19 +154,39 @@ class AppViewModel(private val speechToText: SpeechToText, private val context:
}
}

"unknown" -> {
if (action.ask != null) {
Command.AskCommand(
ask = action.ask,
description = action.action
)
} else {
logger.logToFile("GeePee", "UnsupportedCommand")
Command.UnsupportedCommand
}
}

else -> {
logger.logToFile("GeePee", "UnsupportedCommand")
Command.UnsupportedCommand
null
}
}
}
}.filterIsInstance<Command>()

val firstAskCommand = commands.firstOrNull { it is Command.AskCommand } as? Command.AskCommand

state = state.copy(
promptQueue = state.promptQueue.toMutableList().apply {
add(message)
toList()
},
promptDisplay = state.promptDisplay.dropLast(1),
promptDisplay = state.promptDisplay.dropLast(1).toMutableList().apply {
if (firstAskCommand != null) {
add(System(firstAskCommand.ask))
}
toList()
},
commandQueue = commands
)
}
Expand Down Expand Up @@ -243,6 +263,7 @@ data class ApiAction(
val component: String,
val action: String,
val subcomponent: String? = null,
val ask: String? = null,
@SerialName("package") val appPackage: String? = null,
@SerialName("parameters") val parameters: ActionParameters? = null,
)
Expand All @@ -265,6 +286,11 @@ sealed class Command(
override val description: String,
) : Command(description)

data class AskCommand(
val ask: String,
override val description: String,
) : Command(description)

data class SystemCommand(
val peripheral: Peripheral,
override val description: String,
Expand Down
6 changes: 6 additions & 0 deletions android/app/src/main/java/co/rikin/geepee/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ fun App() {
}
}

is Command.AskCommand -> {
// Add your logic here to handle the AskCommand
logger.logToFile("GeePee", "AskCommand")
viewModel.action(AppAction.Advance)
}

Command.UnsupportedCommand -> {
viewModel.action(AppAction.Advance)
}
Expand Down
1 change: 0 additions & 1 deletion android/app/src/main/java/co/rikin/geepee/ui/Initialize.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ class InitialPrompt(private val context: Context) {
promptUnknownAction() +
promptHttpOk()

logger.logToFile("InitPrompt", initPrompt)
return initPrompt
}
}

0 comments on commit 3844767

Please sign in to comment.