Skip to content

Commit

Permalink
Merge pull request #152 from klokidis/main
Browse files Browse the repository at this point in the history
color picker grid #118
  • Loading branch information
EmmaTellblom authored Oct 8, 2024
2 parents 2ee1e27 + ac1c266 commit 0b1edd7
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 45 deletions.
110 changes: 67 additions & 43 deletions app/src/main/java/com/mensinator/app/ManageSymptomDialog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) }
Expand All @@ -73,8 +75,6 @@ fun ManageSymptom(
var showDeleteDialog by remember { mutableStateOf(false) }
var symptomToDelete by remember { mutableStateOf<Symptom?>(null) }

val screenHeight = LocalConfiguration.current.screenHeightDp.dp
val menuHeight = screenHeight * 0.8f // 80% of the screen height

Column(
modifier = Modifier
Expand Down Expand Up @@ -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
)
}
)
}
}
}
)
}
}
}
}
Expand All @@ -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()
},
Expand Down Expand Up @@ -288,7 +312,7 @@ fun ManageSymptom(
)
}

// Show the delete confirmation dialog
// Show the delete confirmation dialog
if (showDeleteDialog) {
AlertDialog(
onDismissRequest = {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/com/mensinator/app/data/DataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 0b1edd7

Please sign in to comment.