git.iko.soy/opencode-android
on e37d1bb help sign in
70 lines 3.0 kB history raw
1package soy.iko.opencode.ui.chat
3import androidx.compose.foundation.clickable
4import androidx.compose.foundation.layout.Column
5import androidx.compose.foundation.layout.fillMaxWidth
6import androidx.compose.foundation.layout.heightIn
7import androidx.compose.foundation.layout.padding
8import androidx.compose.foundation.lazy.LazyColumn
9import androidx.compose.foundation.lazy.items
10import androidx.compose.material3.ExperimentalMaterial3Api
11import androidx.compose.material3.MaterialTheme
12import androidx.compose.material3.ModalBottomSheet
13import androidx.compose.material3.Text
14import androidx.compose.runtime.Composable
15import androidx.compose.ui.Modifier
16import androidx.compose.ui.unit.dp
17import soy.iko.opencode.data.model.ModelOption
19/** Bottom sheet that lists every provider/model and lets the user pick one. */
20@OptIn(ExperimentalMaterial3Api::class)
21@Composable
22fun ModelPickerSheet(
23 options: List<ModelOption>,
24 selected: ModelOption?,
25 onSelect: (ModelOption) -> Unit,
26 onDismiss: () -> Unit,
27) {
28 ModalBottomSheet(onDismissRequest = onDismiss) {
29 Text(
30 "Model",
31 style = MaterialTheme.typography.titleMedium,
32 modifier = Modifier.padding(start = 24.dp, end = 24.dp, bottom = 8.dp),
33 )
34 if (options.isEmpty()) {
35 Text(
36 "No models reported by the server.",
37 style = MaterialTheme.typography.bodyMedium,
38 color = MaterialTheme.colorScheme.onSurfaceVariant,
39 modifier = Modifier.padding(horizontal = 24.dp, vertical = 16.dp),
40 )
41 } else {
42 LazyColumn(modifier = Modifier.fillMaxWidth().heightIn(max = 420.dp)) {
43 items(options, key = { it.providerID + "/" + it.modelID }) { option ->
44 val isSelected = option.providerID == selected?.providerID &&
45 option.modelID == selected.modelID
46 Column(
47 modifier = Modifier
48 .fillMaxWidth()
49 .clickable {
50 onSelect(option)
51 onDismiss()
52 }
53 .padding(horizontal = 24.dp, vertical = 12.dp),
54 ) {
55 Text(
56 option.modelLabel,
57 style = MaterialTheme.typography.bodyLarge,
58 color = if (isSelected) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.onSurface,
59 )
60 Text(
61 option.providerLabel + if (isSelected) " ✓" else "",
62 style = MaterialTheme.typography.bodySmall,
63 color = MaterialTheme.colorScheme.onSurfaceVariant,
64 )
65 }
66 }
67 }
68 }
69 }