Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
feat: revamp UI with Gemini-style home screen and left navigation drawer
Durganshu Mishra945f1d6956ea
diff --git a/app/src/main/java/com/gotcha/MainActivity.kt b/app/src/main/java/com/gotcha/MainActivity.ktindex 3cd664c..ce87329 100644--- a/app/src/main/java/com/gotcha/MainActivity.kt+++ b/app/src/main/java/com/gotcha/MainActivity.kt@@ -14,14 +14,18 @@ import androidx.activity.compose.setContentimport androidx.activity.result.contract.ActivityResultContractsimport androidx.activity.viewModelsimport androidx.compose.foundation.layout.fillMaxSize+import androidx.compose.material3.DrawerValueimport androidx.compose.material3.MaterialTheme+import androidx.compose.material3.ModalNavigationDrawerimport androidx.compose.material3.Surface+import androidx.compose.material3.rememberDrawerStateimport androidx.compose.runtime.Composableimport androidx.compose.runtime.LaunchedEffectimport androidx.compose.runtime.collectAsStateimport androidx.compose.runtime.getValueimport androidx.compose.runtime.mutableStateOfimport androidx.compose.runtime.remember+import androidx.compose.runtime.rememberCoroutineScopeimport androidx.compose.runtime.setValueimport androidx.compose.ui.Modifierimport androidx.lifecycle.lifecycleScope@@ -36,8 +40,8 @@ import com.gotcha.service.AssistiveBallServiceimport com.gotcha.service.GotchaDeviceAdminReceiverimport com.gotcha.tools.ScreenPerceptionimport com.gotcha.tools.ToolResult+import com.gotcha.ui.AppDrawerContentimport com.gotcha.ui.ChatScreen-import com.gotcha.ui.SessionsScreenimport com.gotcha.ui.SettingsScreenimport com.gotcha.ui.theme.GotchaThemeimport kotlinx.coroutines.Dispatchers@@ -46,7 +50,7 @@ import kotlinx.coroutines.withContextimport kotlinx.serialization.json.JsonPrimitiveimport android.provider.Settings as AndroidSettings-enum class Route { SESSIONS, CHAT, SETTINGS }+enum class Route { HOME, SETTINGS }class MainActivity : ComponentActivity() {@@ -261,13 +265,23 @@ class MainActivity : ComponentActivity() {val sessions by chatViewModel.sessions.collectAsState()var currentRoute by remember {- mutableStateOf(if (settingsRepository.load().isConfigured) Route.SESSIONS else Route.SETTINGS)+ mutableStateOf(if (settingsRepository.load().isConfigured) Route.HOME else Route.SETTINGS)}- var previousRoute by remember { mutableStateOf(Route.SESSIONS) }var assistiveBallOn by remember { mutableStateOf(settingsRepository.load().assistiveBallEnabled) }+ val drawerState = rememberDrawerState(DrawerValue.Closed)+ val scope = rememberCoroutineScope()LaunchedEffect(Unit) { chatViewModel.refreshSettings() }+ // Keep the drawer's session list fresh: on open, and after a run finishes+ // (picks up the auto-generated title once the first exchange is saved).+ LaunchedEffect(drawerState.isOpen) {+ if (drawerState.isOpen) chatViewModel.refreshSessions()+ }+ LaunchedEffect(state.isBusy) {+ if (!state.isBusy) chatViewModel.refreshSessions()+ }+// Track the service's real state so the toggle updates when the ball is// hidden from its own overlay menu (which stops the service directly).LaunchedEffect(Unit) {@@ -279,117 +293,127 @@ class MainActivity : ComponentActivity() {// Honor the assistive ball's "Open Chat" option.LaunchedEffect(openChatRequested) {if (openChatRequested) {- currentRoute = Route.CHAT+ currentRoute = Route.HOMEopenChatRequested = false}}- when (currentRoute) {- Route.SETTINGS -> {- BackHandler { currentRoute = previousRoute }- SettingsScreen(- initial = settingsRepository.load(),- onSave = { settings ->- settingsRepository.save(settings)- chatViewModel.refreshSettings()- currentRoute = Route.SESSIONS- },- onTestConnection = ::testConnection,- onClearLlmCache = {- LLMClient(- apiKey = "unused",- baseUrl = "http://localhost/",- context = this@MainActivity- ).clearCache()- },- onClearDebugScreenshots = {- val baseDir = java.io.File("/storage/emulated/0/Gotcha")- if (baseDir.exists()) {- baseDir.walkTopDown()- .filter { it.isFile && it.name.startsWith("screenshot_overlay_") }- .forEach { it.delete() }- }- },- onBack = { currentRoute = previousRoute },- onRefreshAudioModels = { s ->- withContext(Dispatchers.IO) {- val ttsApi = AudioApi(s.ttsApiBaseUrl.ifBlank { s.baseUrl }, s.apiKey)- val ttsAll = ttsApi.listAudioModels()- val ttsModels = ttsAll.filter { it.category == ModelCategory.TTS }- val sttModels = if (s.sttApiBaseUrl.isNotBlank() && s.sttApiBaseUrl != s.ttsApiBaseUrl) {- val sttApi = AudioApi(s.sttApiBaseUrl, s.apiKey)- sttApi.listAudioModels().filter { it.category == ModelCategory.STT }- } else {- ttsAll.filter { it.category == ModelCategory.STT }- }- Pair(ttsModels, sttModels)- }- },- onRefreshChatModels = { s ->- withContext(Dispatchers.IO) {- val client = LLMClient(- apiKey = s.apiKey,- baseUrl = s.baseUrl,- model = s.model,- context = this@MainActivity,- apiTimeoutSeconds = s.apiTimeoutSeconds- )- client.listModels()- }- },- packageName = packageName- )- }- Route.SESSIONS -> {- SessionsScreen(+ ModalNavigationDrawer(+ drawerState = drawerState,+ gesturesEnabled = currentRoute == Route.HOME || drawerState.isOpen,+ drawerContent = {+ AppDrawerContent(sessions = sessions,+ activeSessionId = state.activeSessionId,+ onNewChat = {+ scope.launch { drawerState.close() }+ chatViewModel.openSession(null)+ currentRoute = Route.HOME+ },onSessionClick = { id ->+ scope.launch { drawerState.close() }chatViewModel.openSession(id)- currentRoute = Route.CHAT+ currentRoute = Route.HOME},onDeleteSession = chatViewModel::deleteSession,- onNewChat = {- chatViewModel.openSession(null)- currentRoute = Route.CHAT- },onOpenSettings = {- previousRoute = Route.SESSIONS+ scope.launch { drawerState.close() }currentRoute = Route.SETTINGS- },- assistiveBallEnabled = assistiveBallOn,- onToggleAssistiveBall = { enabled ->- assistiveBallOn = setAssistiveBall(enabled)})}- Route.CHAT -> {- BackHandler {- chatViewModel.refreshSessions()- currentRoute = Route.SESSIONS+ ) {+ when (currentRoute) {+ Route.SETTINGS -> {+ BackHandler { currentRoute = Route.HOME }+ SettingsScreen(+ initial = settingsRepository.load(),+ onSave = { settings ->+ settingsRepository.save(settings)+ chatViewModel.refreshSettings()+ currentRoute = Route.HOME+ },+ onTestConnection = ::testConnection,+ onClearLlmCache = {+ LLMClient(+ apiKey = "unused",+ baseUrl = "http://localhost/",+ context = this@MainActivity+ ).clearCache()+ },+ onClearDebugScreenshots = {+ val baseDir = java.io.File("/storage/emulated/0/Gotcha")+ if (baseDir.exists()) {+ baseDir.walkTopDown()+ .filter { it.isFile && it.name.startsWith("screenshot_overlay_") }+ .forEach { it.delete() }+ }+ },+ onBack = { currentRoute = Route.HOME },+ onRefreshAudioModels = { s ->+ withContext(Dispatchers.IO) {+ val ttsApi = AudioApi(s.ttsApiBaseUrl.ifBlank { s.baseUrl }, s.apiKey)+ val ttsAll = ttsApi.listAudioModels()+ val ttsModels = ttsAll.filter { it.category == ModelCategory.TTS }+ val sttModels = if (s.sttApiBaseUrl.isNotBlank() && s.sttApiBaseUrl != s.ttsApiBaseUrl) {+ val sttApi = AudioApi(s.sttApiBaseUrl, s.apiKey)+ sttApi.listAudioModels().filter { it.category == ModelCategory.STT }+ } else {+ ttsAll.filter { it.category == ModelCategory.STT }+ }+ Pair(ttsModels, sttModels)+ }+ },+ onRefreshChatModels = { s ->+ withContext(Dispatchers.IO) {+ val client = LLMClient(+ apiKey = s.apiKey,+ baseUrl = s.baseUrl,+ model = s.model,+ context = this@MainActivity,+ apiTimeoutSeconds = s.apiTimeoutSeconds+ )+ client.listModels()+ }+ },+ packageName = packageName+ )+ }+ Route.HOME -> {+ // Back from an active chat returns to a fresh home (new session,+ // new greeting); on an empty home the default back exits the app.+ BackHandler(enabled = state.messages.isNotEmpty() && !state.isBusy) {+ chatViewModel.openSession(null)+ }+ ChatScreen(+ state = state,+ onSend = { text, imageBase64 -> chatViewModel.sendMessage(text, imageBase64) },+ onStop = chatViewModel::stopAgent,+ onConfirm = chatViewModel::confirmPendingActions,+ onAnswer = chatViewModel::submitAnswer,+ onOpenDrawer = { scope.launch { drawerState.open() } },+ onOpenSettings = { currentRoute = Route.SETTINGS },+ sessionTitle = sessions.firstOrNull { it.id == state.activeSessionId }?.title,+ assistiveBallEnabled = assistiveBallOn,+ onToggleAssistiveBall = { enabled ->+ assistiveBallOn = setAssistiveBall(enabled)+ },+ onPickImage = { uri -> chatViewModel.loadImageBase64(uri) },+ onSwitchAgent = chatViewModel::switchAgent,+ onSpeak = chatViewModel::speak,+ onStartListening = chatViewModel::startListening,+ onStopRecording = chatViewModel::stopRecording,+ onExportChat = chatViewModel::exportChat+ )}- ChatScreen(- state = state,- onSend = { text, imageBase64 -> chatViewModel.sendMessage(text, imageBase64) },- onStop = chatViewModel::stopAgent,- onConfirm = chatViewModel::confirmPendingActions,- onAnswer = chatViewModel::submitAnswer,- onBack = {- chatViewModel.refreshSessions()- currentRoute = Route.SESSIONS- },- onOpenSettings = {- previousRoute = Route.CHAT- currentRoute = Route.SETTINGS- },- onPickImage = { uri -> chatViewModel.loadImageBase64(uri) },- onSwitchAgent = chatViewModel::switchAgent,- onSpeak = chatViewModel::speak,- onStartListening = chatViewModel::startListening,- onStopRecording = chatViewModel::stopRecording,- onExportChat = chatViewModel::exportChat- )}}++ // Composed last so this innermost enabled handler wins back dispatch:+ // back closes an open drawer before any other navigation.+ BackHandler(enabled = drawerState.isOpen) {+ scope.launch { drawerState.close() }+ }}/** Cheap "ping" request to validate credentials (Phase 6). */diff --git a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt b/app/src/main/java/com/gotcha/agent/ChatViewModel.ktindex 4b6b5fe..bb0cf45 100644--- a/app/src/main/java/com/gotcha/agent/ChatViewModel.kt+++ b/app/src/main/java/com/gotcha/agent/ChatViewModel.kt@@ -133,20 +133,13 @@ class ChatViewModel(application: Application) : AndroidViewModel(application), AScreenPerception.appContext = applicationrefreshSettings()viewModelScope.launch {- val sessions = historyRepository.listSessions()- if (sessions.isNotEmpty()) {- val latest = sessions.first()- agentEngine.sessionId = latest.id- agentEngine.tokenCount = latest.tokenCount- agentEngine.history.addAll(latest.messages)- } else {- agentEngine.sessionId = java.util.UUID.randomUUID().toString()- agentEngine.tokenCount = 0- }+ // Always start on a fresh session so the home screen greets with an+ // empty chat; past sessions remain one tap away in the drawer.+ agentEngine.sessionId = java.util.UUID.randomUUID().toString()+ agentEngine.tokenCount = 0agentEngine.setupWorkingDir()_uiState.update { it.copy(activeSessionId = agentEngine.sessionId) }updateContextUsage()- rebuildUiMessages()refreshSessions()}}diff --git a/app/src/main/java/com/gotcha/ui/ChatScreen.kt b/app/src/main/java/com/gotcha/ui/ChatScreen.ktindex 7ac51d4..dde8e90 100644--- a/app/src/main/java/com/gotcha/ui/ChatScreen.kt+++ b/app/src/main/java/com/gotcha/ui/ChatScreen.kt@@ -20,12 +20,13 @@ import androidx.compose.foundation.lazy.rememberLazyListStateimport androidx.compose.foundation.shape.CircleShapeimport androidx.compose.foundation.shape.RoundedCornerShapeimport androidx.compose.material.icons.Icons-import androidx.compose.material.icons.filled.ArrowBackimport androidx.compose.material.icons.filled.Close+import androidx.compose.material.icons.filled.Menuimport androidx.compose.material.icons.filled.Micimport androidx.compose.material.icons.filled.Sendimport androidx.compose.material.icons.filled.Shareimport androidx.compose.material.icons.filled.Stop+import androidx.compose.material.icons.outlined.Adjustimport androidx.compose.material3.AlertDialogimport androidx.compose.material3.Buttonimport androidx.compose.material3.ButtonDefaults@@ -54,6 +55,7 @@ import androidx.compose.ui.draw.clipimport androidx.compose.ui.graphics.Colorimport androidx.compose.ui.graphics.asImageBitmapimport androidx.compose.ui.layout.ContentScale+import androidx.compose.ui.text.style.TextAlignimport androidx.compose.ui.text.style.TextOverflowimport androidx.compose.ui.unit.dpimport com.gotcha.agent.ChatUiState@@ -69,8 +71,11 @@ fun ChatScreen(onStop: () -> Unit,onConfirm: (Boolean) -> Unit,onAnswer: (String?) -> Unit,- onBack: () -> Unit,+ onOpenDrawer: () -> Unit,onOpenSettings: () -> Unit,+ sessionTitle: String? = null,+ assistiveBallEnabled: Boolean = false,+ onToggleAssistiveBall: (Boolean) -> Unit = {},onPickImage: (Uri) -> String?,onSwitchAgent: () -> Unit,onSpeak: (String) -> Unit = {},@@ -78,6 +83,7 @@ fun ChatScreen(onStopRecording: () -> Unit = {},onExportChat: () -> Unit = {}) {+ val isHome = state.messages.isEmpty()var input by rememberSaveable { mutableStateOf("") }var pendingImageUri by rememberSaveable { mutableStateOf<Uri?>(null) }var pendingImageBase64 by rememberSaveable { mutableStateOf<String?>(null) }@@ -106,39 +112,79 @@ fun ChatScreen(Scaffold(topBar = {TopAppBar(- title = { Text("Gotcha") },+ title = {+ Text(+ if (isHome) "Gotcha" else (sessionTitle ?: "Gotcha"),+ maxLines = 1,+ overflow = TextOverflow.Ellipsis+ )+ },navigationIcon = {- IconButton(onClick = onBack, enabled = !state.isBusy) {- Icon(Icons.Default.ArrowBack, contentDescription = "Back")+ IconButton(onClick = onOpenDrawer) {+ Icon(Icons.Default.Menu, contentDescription = "Open menu")}},actions = {- FilterChip(- selected = state.activeAgent == AgentMode.OPERATOR,- onClick = onSwitchAgent,- label = { Text(state.activeAgent.name) },- enabled = !state.isBusy- )- IconButton(onClick = onExportChat, enabled = !state.isBusy) {- Icon(Icons.Default.Share, contentDescription = "Export chat")+ if (isHome) {+ IconButton(onClick = { onToggleAssistiveBall(!assistiveBallEnabled) }) {+ Icon(+ Icons.Outlined.Adjust,+ contentDescription = if (assistiveBallEnabled) {+ "Turn off assistive ball"+ } else {+ "Turn on assistive ball"+ },+ tint = if (assistiveBallEnabled) {+ MaterialTheme.colorScheme.primary+ } else {+ MaterialTheme.colorScheme.onSurfaceVariant+ }+ )+ }+ } else {+ FilterChip(+ selected = state.activeAgent == AgentMode.OPERATOR,+ onClick = onSwitchAgent,+ label = { Text(state.activeAgent.name) },+ enabled = !state.isBusy+ )+ IconButton(onClick = onExportChat, enabled = !state.isBusy) {+ Icon(Icons.Default.Share, contentDescription = "Export chat")+ }}- TextButton(onClick = onOpenSettings) { Text("Settings") }})}) { padding ->Column(modifier = Modifier.fillMaxSize().padding(padding)) {- LinearProgressIndicator(- progress = { state.contextUsagePercent },- modifier = Modifier.fillMaxWidth(),- color = if (state.contextUsagePercent > 0.8f) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary- )- LazyColumn(- state = listState,- modifier = Modifier.weight(1f).fillMaxWidth()- ) {- items(state.messages, key = { it.id }) { message ->- MessageBubble(message = message, onSpeak = onSpeak)+ if (!isHome) {+ LinearProgressIndicator(+ progress = { state.contextUsagePercent },+ modifier = Modifier.fillMaxWidth(),+ color = if (state.contextUsagePercent > 0.8f) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.primary+ )+ }+ if (isHome) {+ val greeting = rememberSaveable(state.activeSessionId) { HOME_GREETINGS.random() }+ Box(+ modifier = Modifier.weight(1f).fillMaxWidth().padding(horizontal = 32.dp),+ contentAlignment = Alignment.Center+ ) {+ Text(+ greeting,+ style = MaterialTheme.typography.headlineMedium,+ textAlign = TextAlign.Center,+ color = MaterialTheme.colorScheme.onSurfaceVariant+ )+ }+ } else {+ LazyColumn(+ state = listState,+ modifier = Modifier.weight(1f).fillMaxWidth()+ ) {+ items(state.messages, key = { it.id }) { message ->+ MessageBubble(message = message, onSpeak = onSpeak)+ }}}diff --git a/app/src/main/java/com/gotcha/ui/SessionsScreen.kt b/app/src/main/java/com/gotcha/ui/SessionsScreen.ktdeleted file mode 100644index b605871..0000000--- a/app/src/main/java/com/gotcha/ui/SessionsScreen.kt+++ /dev/null@@ -1,180 +0,0 @@-package com.gotcha.ui--import androidx.compose.foundation.clickable-import androidx.compose.foundation.layout.Box-import androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.Row-import androidx.compose.foundation.layout.Spacer-import androidx.compose.foundation.layout.fillMaxSize-import androidx.compose.foundation.layout.fillMaxWidth-import androidx.compose.foundation.layout.height-import androidx.compose.foundation.layout.padding-import androidx.compose.foundation.layout.width-import androidx.compose.foundation.lazy.LazyColumn-import androidx.compose.foundation.lazy.items-import androidx.compose.material.icons.Icons-import androidx.compose.material.icons.filled.Add-import androidx.compose.material.icons.filled.Delete-import androidx.compose.material.icons.filled.Settings-import androidx.compose.material.icons.outlined.Adjust-import androidx.compose.material3.AlertDialog-import androidx.compose.material3.Button-import androidx.compose.material3.ButtonDefaults-import androidx.compose.material3.ExperimentalMaterial3Api-import androidx.compose.material3.FloatingActionButton-import androidx.compose.material3.Icon-import androidx.compose.material3.IconButton-import androidx.compose.material3.MaterialTheme-import androidx.compose.material3.Scaffold-import androidx.compose.material3.Text-import androidx.compose.material3.TextButton-import androidx.compose.material3.TopAppBar-import androidx.compose.runtime.Composable-import androidx.compose.runtime.getValue-import androidx.compose.runtime.mutableStateOf-import androidx.compose.runtime.remember-import androidx.compose.runtime.setValue-import androidx.compose.ui.Alignment-import androidx.compose.ui.Modifier-import androidx.compose.ui.text.style.TextOverflow-import androidx.compose.ui.unit.dp-import com.gotcha.data.ChatSession-import java.text.SimpleDateFormat-import java.util.Date-import java.util.Locale--@OptIn(ExperimentalMaterial3Api::class)-@Composable-fun SessionsScreen(- sessions: List<ChatSession>,- onSessionClick: (String) -> Unit,- onDeleteSession: (String) -> Unit,- onNewChat: () -> Unit,- onOpenSettings: () -> Unit,- assistiveBallEnabled: Boolean = false,- onToggleAssistiveBall: (Boolean) -> Unit = {}-) {- var sessionToDelete by remember { mutableStateOf<String?>(null) }-- Scaffold(- topBar = {- TopAppBar(- title = { Text("Chats") },- actions = {- IconButton(onClick = { onToggleAssistiveBall(!assistiveBallEnabled) }) {- Icon(- Icons.Outlined.Adjust,- contentDescription = if (assistiveBallEnabled) {- "Turn off assistive ball"- } else {- "Turn on assistive ball"- },- tint = if (assistiveBallEnabled) {- MaterialTheme.colorScheme.primary- } else {- MaterialTheme.colorScheme.onSurfaceVariant- }- )- }- IconButton(onClick = onOpenSettings) {- Icon(Icons.Default.Settings, contentDescription = "Settings")- }- }- )- },- floatingActionButton = {- FloatingActionButton(onClick = onNewChat) {- Icon(Icons.Default.Add, contentDescription = "New Chat")- }- }- ) { padding ->- if (sessions.isEmpty()) {- Box(modifier = Modifier.fillMaxSize().padding(padding), contentAlignment = Alignment.Center) {- Text("No chats yet. Tap + to start a new chat.", style = MaterialTheme.typography.bodyLarge)- }- } else {- LazyColumn(modifier = Modifier.fillMaxSize().padding(padding)) {- items(sessions, key = { it.id }) { session ->- SessionRow(- session = session,- onClick = { onSessionClick(session.id) },- onDelete = { sessionToDelete = session.id }- )- }- }- }- }-- sessionToDelete?.let { id ->- val title = sessions.find { it.id == id }?.title ?: "this chat"- AlertDialog(- onDismissRequest = { sessionToDelete = null },- title = { Text("Delete Chat?") },- text = { Text("Are you sure you want to permanently delete \"$title\"? This action cannot be undone.") },- confirmButton = {- Button(- onClick = {- onDeleteSession(id)- sessionToDelete = null- },- colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.error)- ) {- Text("Delete")- }- },- dismissButton = {- TextButton(onClick = { sessionToDelete = null }) {- Text("Cancel")- }- }- )- }-}--@Composable-fun SessionRow(- session: ChatSession,- onClick: () -> Unit,- onDelete: () -> Unit-) {- val df = SimpleDateFormat("MMM d, HH:mm", Locale.getDefault())- val dateStr = df.format(Date(session.lastModified))-- Row(- modifier = Modifier- .fillMaxWidth()- .clickable(onClick = onClick)- .padding(horizontal = 16.dp, vertical = 12.dp),- verticalAlignment = Alignment.CenterVertically- ) {- Column(modifier = Modifier.weight(1f)) {- Text(- text = session.title,- style = MaterialTheme.typography.titleMedium,- maxLines = 1,- overflow = TextOverflow.Ellipsis- )- Spacer(modifier = Modifier.height(4.dp))- Row(verticalAlignment = Alignment.CenterVertically) {- Text(- text = dateStr,- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant- )- Spacer(modifier = Modifier.width(8.dp))- Text(- text = "• ${session.tokenCount} tokens",- style = MaterialTheme.typography.bodySmall,- color = MaterialTheme.colorScheme.onSurfaceVariant- )- }- }- IconButton(onClick = onDelete) {- Icon(- imageVector = Icons.Default.Delete,- contentDescription = "Delete Chat",- tint = MaterialTheme.colorScheme.error- )- }- }-}