Created
January 3, 2024 15:59
-
-
Save maq796113/185f0ffcf1c4df2b88311973330a2584 to your computer and use it in GitHub Desktop.
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 PhotoBottomSheetContent( | |
bitmaps: List<Bitmap>, | |
context: Context, | |
geminiAIViewModel: GeminiAIViewModel1 = hiltViewModel(), | |
modifier: Modifier, | |
) { | |
val uiState by geminiAIViewModel.uiState.collectAsStateWithLifecycle() | |
val scope = rememberCoroutineScope() | |
if (bitmaps.isEmpty()) { | |
Box( | |
modifier = modifier | |
.padding(16.dp), | |
contentAlignment = Alignment.Center | |
) { | |
Text("There are no photos yet") | |
} | |
} else { | |
//recomposition | |
if (uiState.isLoading) { //if isLoading true, the progress indicator should pop up on the sheet | |
Box(contentAlignment = Alignment.Center) { | |
CircularProgressIndicator(modifier.fillMaxSize()) | |
} | |
} else { | |
LazyVerticalStaggeredGrid( | |
columns = StaggeredGridCells.Fixed(2), | |
horizontalArrangement = Arrangement.spacedBy(16.dp), | |
verticalItemSpacing = 16.dp, | |
contentPadding = PaddingValues(16.dp), | |
modifier = modifier | |
) { | |
items(bitmaps) { bitmap -> | |
Image( | |
bitmap = bitmap.asImageBitmap(), | |
contentDescription = null, | |
modifier = Modifier | |
.clip(RoundedCornerShape(10.dp)) | |
.clickable { | |
geminiAIViewModel.initializeLoading() | |
//I want recomposition from this point | |
//I want a progress indicator working | |
//the following line of code should run after isLoading is true | |
geminiAIViewModel.prompt(bitmap) | |
val bytes = ByteArrayOutputStream() | |
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, bytes) | |
val path = MediaStore.Images.Media.insertImage( | |
context.contentResolver, | |
bitmap, | |
"SelectedImage", | |
null | |
) | |
geminiAIViewModel.getSelectedBitmap(Uri.parse(path)) | |
geminiAIViewModel.saveSession() | |
//the following line of code should run after isLoading is false | |
val intent = Intent(context, GeminiAIActivity::class.java) | |
context.startActivity(intent) | |
} | |
) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment