Skip to content

Commit da910b1

Browse files
refactor: Adjust DatabaseListPopup layout and 'New' button behavior
I've incorporated your feedback for the system message database list pop-up: - First Pop-up (Database List Screen): - Card styling adjusted to minimize perceived border/margin, aligning with the second pop-up's appearance. The Card's containerColor is now set, and padding is internal. - Displays a fixed total of 15 rows. - The "New" button is now dynamically placed in the row immediately following the last data entry. - If the list is empty, the "New" button is in the first row. - If an entry is deleted, the "New" button row shifts upwards. - If all 15 rows are filled with data entries, the "New" button is not displayed. - Rows (data, "New" button, or empty placeholders) consistently use an alternating dark yellow background based on their display index.
1 parent cdba546 commit da910b1

1 file changed

Lines changed: 58 additions & 51 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/feature/multimodal/PhotoReasoningScreen.kt

Lines changed: 58 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -632,91 +632,98 @@ fun DatabaseListPopup(
632632
onDismissRequest = onDismissRequest,
633633
properties = DialogProperties(usePlatformDefaultWidth = false)
634634
) {
635-
Card( // Using Card for elevation and rounded corners by default
635+
Card(
636636
modifier = Modifier
637-
.fillMaxWidth(0.95f) // Fill 95% of width
638-
.fillMaxHeight(0.85f) // Fill 85% of height
639-
.padding(16.dp),
640-
shape = RoundedCornerShape(16.dp) // Explicitly define shape for consistency
637+
.fillMaxWidth(0.95f) // Fill 95% of screen width
638+
.fillMaxHeight(0.85f), // Fill 85% of screen height
639+
shape = RoundedCornerShape(16.dp),
640+
colors = CardDefaults.cardColors(containerColor = DarkYellow1)
641641
) {
642642
Column(
643643
modifier = Modifier
644-
.padding(16.dp)
644+
.padding(16.dp) // Padding for content *inside* the card
645645
.fillMaxSize()
646646
) {
647-
val displayRowCount = 10
647+
val displayRowCount = 15
648+
val newButtonRowIndex = entries.size // This is the index where the 'New' button row will appear
648649

649-
LazyColumn(modifier = Modifier.fillMaxSize()) { // Changed to fillMaxSize if it's the only direct child
650-
items(displayRowCount) { index ->
651-
val actualEntryIndex = index - 1 // For accessing `entries` list
650+
LazyColumn(modifier = Modifier.weight(1f)) { // Ensure LazyColumn takes available space
651+
items(displayRowCount) { rowIndex ->
652+
val currentAlternatingColor = if (rowIndex % 2 == 0) DarkYellow1 else DarkYellow2
652653

653-
if (index == 0) {
654-
// Row for "New" button
655-
Row(
656-
modifier = Modifier
657-
.fillMaxWidth()
658-
.background(DarkYellow1)
659-
.padding(8.dp), // Adjusted padding
660-
verticalAlignment = Alignment.CenterVertically
661-
) {
662-
Button(
663-
onClick = onNewClicked,
664-
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary),
665-
modifier = Modifier.padding(end = 8.dp)
666-
) {
667-
Text("New")
668-
}
669-
Text("Add a new system message guide", color = Color.Gray)
670-
}
671-
} else {
672-
// Subsequent rows for entries or empty placeholders
673-
if (actualEntryIndex < entries.size) {
674-
val entry = entries[actualEntryIndex]
654+
when {
655+
// Case 1: This row is for an actual entry
656+
rowIndex < entries.size -> {
657+
val entry = entries[rowIndex]
675658
Row(
676659
modifier = Modifier
677660
.fillMaxWidth()
678-
.background(if (actualEntryIndex % 2 == 0) DarkYellow1 else DarkYellow2)
679-
.padding(16.dp)
661+
.background(currentAlternatingColor)
662+
.padding(horizontal = 16.dp, vertical = 8.dp) // Consistent padding
680663
.clickable { onEntryClicked(entry) },
681664
verticalAlignment = Alignment.CenterVertically
682665
) {
683666
Text(
684667
text = entry.title,
685668
modifier = Modifier.weight(1f),
686-
color = Color.Black
669+
color = Color.Black,
670+
style = MaterialTheme.typography.bodyLarge // Slightly larger text for entries
687671
)
688-
Box { // Box anchor for the DropdownMenu
689-
IconButton(onClick = { entryMenuToShow = entry }) {
690-
Icon(
691-
Icons.Filled.MoreVert,
692-
contentDescription = "More options",
693-
tint = Color.Black
694-
)
672+
Box { // Anchor for DropdownMenu
673+
IconButton(onClick = { entryMenuToShow = entry }) { // entryMenuToShow state
674+
Icon(Icons.Filled.MoreVert, contentDescription = "More options", tint = Color.Black)
695675
}
696676
DropdownMenu(
697-
expanded = entryMenuToShow == entry,
698-
onDismissRequest = { entryMenuToShow = null }
677+
expanded = entryMenuToShow == entry, // entryMenuToShow state
678+
onDismissRequest = { entryMenuToShow = null } // entryMenuToShow state
699679
) {
700680
DropdownMenuItem(
701681
text = { Text("Delete") },
702682
onClick = {
703683
onDeleteClicked(entry)
704-
entryMenuToShow = null
684+
entryMenuToShow = null // entryMenuToShow state
705685
}
706686
)
707687
}
708688
}
709689
}
710-
} else {
711-
// Empty styled row
690+
}
691+
692+
// Case 2: This row is the "New" button row
693+
rowIndex == newButtonRowIndex -> {
694+
Row(
695+
modifier = Modifier
696+
.fillMaxWidth()
697+
.background(currentAlternatingColor)
698+
.padding(8.dp) // Slightly less vertical padding for button row
699+
.clickable(onClick = onNewClicked),
700+
verticalAlignment = Alignment.CenterVertically
701+
) {
702+
Button(
703+
onClick = onNewClicked,
704+
colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary),
705+
modifier = Modifier.padding(end = 8.dp)
706+
) {
707+
Text("New")
708+
}
709+
Text(
710+
"Add a new system message guide",
711+
color = Color.Black.copy(alpha = 0.6f),
712+
style = MaterialTheme.typography.bodyMedium
713+
)
714+
}
715+
}
716+
717+
// Case 3: This is an empty placeholder row
718+
else -> {
712719
Box(
713720
modifier = Modifier
714721
.fillMaxWidth()
715-
.height(56.dp) // Adjust height as needed, e.g., to match other rows
716-
.background(if (actualEntryIndex % 2 == 0) DarkYellow1 else DarkYellow2)
717-
.padding(16.dp)
722+
.height(56.dp) // Maintain consistent row height
723+
.background(currentAlternatingColor)
724+
.padding(16.dp) // Keep padding for visual consistency
718725
) {
719-
// Optional: Text("...", color = Color.LightGray.copy(alpha = 0.5f))
726+
// Empty, or a very subtle placeholder if desired
720727
}
721728
}
722729
}

0 commit comments

Comments
 (0)