Created
March 20, 2024 04:46
-
-
Save lethargicpanda/3614d643435b1665ccc17e94eb663908 to your computer and use it in GitHub Desktop.
Very basic compose scaffolding for Potassium.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun MainScreen(viewModel: ViewModel) { | |
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) | |
var bitmap by remember { mutableStateOf<Bitmap?>(null) } | |
val textResponse by viewModel.textGenerated.observeAsState() | |
val isGenerating by viewModel.isGenerating.observeAsState(false) | |
// Get your image | |
val resultLauncher = | |
rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult -> | |
if (result.resultCode == Activity.RESULT_OK) { | |
if (result?.data != null) { | |
bitmap = result.data?.extras?.get("data") as Bitmap | |
} | |
} | |
} | |
Column ( | |
Modifier.padding(12.dp) | |
) { | |
Text( | |
text = "potassium", | |
fontFamily = FontFamily(Font(R.font.scrabble)), | |
fontSize = 54.sp, | |
modifier = Modifier | |
.align(Alignment.CenterHorizontally) | |
.padding(4.dp) | |
) | |
Card( | |
border = BorderStroke( | |
2.dp, | |
MaterialTheme.colorScheme.primary | |
), | |
modifier = Modifier | |
.size( | |
width = 450.dp, | |
height = 450.dp | |
) | |
.align(Alignment.CenterHorizontally) | |
) { | |
bitmap?.let { | |
Image( | |
bitmap = it.asImageBitmap(), | |
contentDescription = "Picture", | |
contentScale = ContentScale.FillWidth, | |
modifier = Modifier.fillMaxSize() | |
) | |
} | |
} | |
Row (modifier = Modifier.align(Alignment.CenterHorizontally)){ | |
Button ( | |
onClick = { | |
resultLauncher.launch(cameraIntent) | |
}, | |
) { | |
Icon(Icons.Default.CameraAlt, contentDescription = "Camera") | |
} | |
Button ( | |
modifier = Modifier.padding(horizontal = 6.dp), | |
onClick = { | |
if (bitmap!=null) { | |
viewModel.generate(bitmap!!) | |
} | |
}, | |
enabled = !isGenerating | |
) { | |
Text(text = "Analyse tiles") | |
Icon(Icons.Default.Psychology, contentDescription = "Camera") | |
} | |
} | |
Spacer(modifier = Modifier.height(30.dp).padding(12.dp)) | |
if (isGenerating){ | |
Text( | |
text = "Thinking..." | |
) | |
} else { | |
MarkdownText( | |
markdown = textResponse?:"" | |
) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment