diff --git a/app/src/main/java/com/mensinator/app/ManageSymptomDialog.kt b/app/src/main/java/com/mensinator/app/ManageSymptomDialog.kt index 2165787..7e7b80d 100644 --- a/app/src/main/java/com/mensinator/app/ManageSymptomDialog.kt +++ b/app/src/main/java/com/mensinator/app/ManageSymptomDialog.kt @@ -10,10 +10,8 @@ import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size -import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentSize import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape @@ -28,6 +26,7 @@ import androidx.compose.material3.DropdownMenu import androidx.compose.material3.DropdownMenuItem import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Switch import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.Text @@ -42,12 +41,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.unit.DpOffset import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.mensinator.app.data.DataSource @@ -64,6 +63,9 @@ fun ManageSymptom( val dbHelper = remember { PeriodDatabaseHelper(context) } var initialSymptoms = remember { dbHelper.getAllSymptoms() } var savedSymptoms by remember { mutableStateOf(initialSymptoms) } + val colorMap = DataSource(isDarkMode()).colorMap + val colorsPerColumn = colorMap.size / 3 + val colorColumns = colorMap.entries.chunked(colorsPerColumn) // State to manage the rename dialog visibility var showRenameDialog by remember { mutableStateOf(false) } @@ -73,8 +75,6 @@ fun ManageSymptom( var showDeleteDialog by remember { mutableStateOf(false) } var symptomToDelete by remember { mutableStateOf(null) } - val screenHeight = LocalConfiguration.current.screenHeightDp.dp - val menuHeight = screenHeight * 0.8f // 80% of the screen height Column( modifier = Modifier @@ -188,44 +188,63 @@ fun ManageSymptom( ) } } - - DropdownMenu( - expanded = expanded, - onDismissRequest = { expanded = false }, - modifier = Modifier - .width(50.dp) - .height(menuHeight) - .clip(RoundedCornerShape(100.dp)) + MaterialTheme( + shapes = MaterialTheme.shapes.copy(extraSmall = RoundedCornerShape(16.dp)) ) { - DataSource(isDarkMode()).colorMap.forEach { (colorName, colorValue) -> - //val keyColor = ResourceMapper.getStringResourceId(colorName) - DropdownMenuItem( - onClick = { - selectedColorName = colorName - expanded = false - val updatedSymptom = symptom.copy(color = colorName) - savedSymptoms = savedSymptoms.map { - if (it.id == symptom.id) updatedSymptom else it - } - // Save settings to the database - savedSymptoms.forEach { symptom -> - dbHelper.updateSymptom( - symptom.id, - symptom.active, - symptom.color - ) - } - onSave() - }, - text = { - Box( + DropdownMenu( + offset = DpOffset(x = (-50).dp, y = (10).dp), + expanded = expanded, + onDismissRequest = { expanded = false }, + modifier = Modifier + .wrapContentSize() + ) { + Row( + modifier = Modifier.wrapContentSize(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.Center + ) { + colorColumns.forEach { columnColors -> + Column( modifier = Modifier - .size(25.dp) - .clip(RoundedCornerShape(26.dp)) - .background(colorValue), // Use the color from the map - ) + .weight(1f) + .wrapContentSize() + ) { + columnColors.forEach { (colorName, colorValue) -> + DropdownMenuItem( + modifier = Modifier + .size(50.dp) + .clip(RoundedCornerShape(100.dp)), + onClick = { + selectedColorName = colorName + expanded = false + val updatedSymptom = + symptom.copy(color = colorName) + savedSymptoms = savedSymptoms.map { + if (it.id == symptom.id) updatedSymptom else it + } + // Save settings to the database + savedSymptoms.forEach { symptom -> + dbHelper.updateSymptom( + symptom.id, + symptom.active, + symptom.color + ) + } + onSave() + }, + text = { + Box( + modifier = Modifier + .size(25.dp) + .clip(RoundedCornerShape(26.dp)) + .background(colorValue) // Use the color from the map + ) + } + ) + } + } } - ) + } } } } @@ -235,13 +254,18 @@ fun ManageSymptom( Switch( checked = symptom.active == 1, onCheckedChange = { checked -> - val updatedSymptom = symptom.copy(active = if (checked) 1 else 0) + val updatedSymptom = + symptom.copy(active = if (checked) 1 else 0) savedSymptoms = savedSymptoms.map { if (it.id == symptom.id) updatedSymptom else it } // Save settings to the database savedSymptoms.forEach { symptom -> - dbHelper.updateSymptom(symptom.id, symptom.active, symptom.color) + dbHelper.updateSymptom( + symptom.id, + symptom.active, + symptom.color + ) } onSave() }, @@ -288,7 +312,7 @@ fun ManageSymptom( ) } -// Show the delete confirmation dialog + // Show the delete confirmation dialog if (showDeleteDialog) { AlertDialog( onDismissRequest = { diff --git a/app/src/main/java/com/mensinator/app/data/DataSource.kt b/app/src/main/java/com/mensinator/app/data/DataSource.kt index 185fa47..cc51717 100644 --- a/app/src/main/java/com/mensinator/app/data/DataSource.kt +++ b/app/src/main/java/com/mensinator/app/data/DataSource.kt @@ -22,7 +22,6 @@ class DataSource(isDarkTheme: Boolean) { "Orange" to Color(0xFFF2CBA6), "Black" to Color(0xFF212121), - "White" to Color(0xFFF5F5F5), "DarkGray" to Color(0xFFABABAB), "LightGray" to Color(0xFFDFDDDD), @@ -60,7 +59,6 @@ class DataSource(isDarkTheme: Boolean) { "DarkMagenta" to Color(0xFF513663), "DarkOrange" to Color(0xFF6B4B2E), - "Black" to Color(0xFF212121), "White" to Color(0xFFF5F5F5), "DarkGray" to Color(0xFF585858), "LightGray" to Color(0xFF8F8F8F)