CI / check (push) Canceled after 0s
- New agent chat (Agents tab FAB, route new-agent): GET /devices for the devices linked now; a device chip, an optional folder (empty = the device's first root, the server's rule) and the mode (manual/edit/auto/plan) go into POST /chats as kind/device/directory/mode. No device linked: a sentence saying how. An open agent chat's mode is a chip too. - Attach: Take a photo (TakePicture into a FileProvider cache file, deleted once uploaded; no CAMERA permission), Choose photos (PickMultipleVisualMedia), Choose files. - Copy under every reply (its text steps) and user message; Rename chat in the menu. - The new chat's effort is held until the first message and sent with it (EffortChip called PATCH, which needs a chat, so the choice was dropped). - Follow the reply while it streams, decided when the person's own scroll comes to rest; the first scroll goes to the real last item (the "older" row shifted the index by one). - ui/Errors.kt explain(): the server's sentence for a refusal, one "cannot be reached" sentence for UnknownHost/Connect/SocketTimeout/NoRouteToHost, used everywhere an error was shown raw. - A failed send hands its text and attachments back to the composer. A replaced follow's CancellationException is no longer shown as an error. A refused stream re-reads the chat. - The chat list reloads on resume (quietly if rows are shown) and offers Try again. - Strings: 15 new; Rename chat, Copy message, Copied., Save, Try again, Device and Auto from the server's catalogue, the rest translated in strings_own.json. "Plan" was the price plan in de/fr/hu (Tarif/Forfait/Csomag) and "Manual" untranslated: own entries fix both. - ClientTest: an agent chat's body, a plain chat's, and what counts as unreachable. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
131 lines
5.3 KiB
Kotlin
131 lines
5.3 KiB
Kotlin
package eu.llembas.android
|
|
|
|
import android.Manifest
|
|
import android.content.Intent
|
|
import android.content.pm.PackageManager
|
|
import android.os.Build
|
|
import android.os.Bundle
|
|
import androidx.activity.ComponentActivity
|
|
import androidx.activity.compose.setContent
|
|
import androidx.activity.enableEdgeToEdge
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
import androidx.compose.material3.Surface
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.LaunchedEffect
|
|
import androidx.compose.runtime.collectAsState
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.key
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.navigation.compose.NavHost
|
|
import androidx.navigation.compose.composable
|
|
import androidx.navigation.compose.rememberNavController
|
|
import eu.llembas.android.auth.Instance
|
|
import eu.llembas.android.auth.Prefs
|
|
import eu.llembas.android.push.Notifications
|
|
import eu.llembas.android.ui.chat.ChatScreen
|
|
import eu.llembas.android.ui.chats.ChatsScreen
|
|
import eu.llembas.android.ui.files.FilesScreen
|
|
import eu.llembas.android.ui.settings.SettingsScreen
|
|
import eu.llembas.android.ui.signin.SignInScreen
|
|
import eu.llembas.android.ui.theme.LembasTheme
|
|
import kotlinx.coroutines.flow.map
|
|
|
|
private data class Loaded(val instance: Instance?)
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
/** A chat a notification, the assistant or a share asked to open; consumed once. */
|
|
private val opening = mutableStateOf<String?>(null)
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
enableEdgeToEdge()
|
|
super.onCreate(savedInstanceState)
|
|
take(intent)
|
|
if (Build.VERSION.SDK_INT >= 33 &&
|
|
ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED
|
|
) {
|
|
requestPermissions(arrayOf(Manifest.permission.POST_NOTIFICATIONS), 1)
|
|
}
|
|
setContent {
|
|
val prefs by lembas.instances.prefs.collectAsState(initial = Prefs())
|
|
LembasTheme(prefs.theme) {
|
|
Surface(Modifier.fillMaxSize()) { Root(opening.value) { opening.value = null } }
|
|
}
|
|
}
|
|
}
|
|
|
|
override fun onNewIntent(intent: Intent) {
|
|
super.onNewIntent(intent)
|
|
take(intent)
|
|
}
|
|
|
|
private fun take(intent: Intent?) {
|
|
intent?.getStringExtra(Notifications.EXTRA_CHAT)?.let { opening.value = it }
|
|
}
|
|
|
|
@Composable
|
|
private fun Root(open: String?, opened: () -> Unit) {
|
|
// null while the store is read; then the instance in use, which may be none.
|
|
val loaded by remember { lembas.instances.active.map { Loaded(it) } }.collectAsState(initial = null)
|
|
val instance = loaded?.instance
|
|
when {
|
|
loaded == null -> Box(Modifier.fillMaxSize())
|
|
|
|
instance == null -> SignInScreen()
|
|
|
|
else -> key(instance.id) {
|
|
val nav = rememberNavController()
|
|
LaunchedEffect(open) {
|
|
open?.let {
|
|
nav.navigate("chat/$it")
|
|
opened()
|
|
}
|
|
}
|
|
NavHost(nav, startDestination = "chats") {
|
|
composable("chats") {
|
|
ChatsScreen(
|
|
onOpen = { nav.navigate("chat/$it") },
|
|
onNew = { nav.navigate("new") },
|
|
onNewAgent = { nav.navigate("new-agent") },
|
|
onSettings = { nav.navigate("settings") },
|
|
onFiles = { nav.navigate("files") },
|
|
)
|
|
}
|
|
composable("new") {
|
|
ChatScreen(
|
|
chatId = null,
|
|
onBack = { nav.popBackStack() },
|
|
onOpened = { id ->
|
|
nav.navigate("chat/$id") { popUpTo("new") { inclusive = true } }
|
|
},
|
|
)
|
|
}
|
|
composable("new-agent") {
|
|
ChatScreen(
|
|
chatId = null,
|
|
agent = true,
|
|
onBack = { nav.popBackStack() },
|
|
onOpened = { id ->
|
|
nav.navigate("chat/$id") { popUpTo("new-agent") { inclusive = true } }
|
|
},
|
|
)
|
|
}
|
|
composable("chat/{id}") { entry ->
|
|
ChatScreen(chatId = entry.arguments?.getString("id"), onBack = { nav.popBackStack() })
|
|
}
|
|
composable("files") { FilesScreen(onBack = { nav.popBackStack() }) }
|
|
composable("settings") {
|
|
SettingsScreen(onBack = { nav.popBackStack() }, onAddInstance = { nav.navigate("add") })
|
|
}
|
|
// Signing in to one more instance makes it the one in use, which starts a
|
|
// fresh navigation for it (the `key` above).
|
|
composable("add") { SignInScreen(onDone = { nav.popBackStack("chats", inclusive = false) }) }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|