Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

color picker grid #118 #152

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 59 additions & 38 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 Down Expand Up @@ -42,7 +40,6 @@ 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
Expand All @@ -64,7 +61,13 @@ 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 = listOf(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use colorMap.chunked(colorsPerColumn) here.

colorMap.entries.take(colorsPerColumn),
colorMap.entries.drop(colorsPerColumn).take(colorsPerColumn),
colorMap.entries.drop(colorsPerColumn * 2)
)
// State to manage the rename dialog visibility
var showRenameDialog by remember { mutableStateOf(false) }
var symptomToRename by remember { mutableStateOf<Symptom?>(null) }
Expand All @@ -73,8 +76,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 @@ -193,39 +194,54 @@ fun ManageSymptom(
expanded = expanded,
onDismissRequest = { expanded = false },
modifier = Modifier
.width(50.dp)
.height(menuHeight)
.clip(RoundedCornerShape(100.dp))
.wrapContentSize()
) {
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
Row(
modifier = Modifier.wrapContentSize(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
colorColumns.forEach { columnColors ->
Column(
modifier = Modifier
.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
)
}
)
}
onSave()
},
text = {
Box(
modifier = Modifier
.size(25.dp)
.clip(RoundedCornerShape(26.dp))
.background(colorValue), // Use the color from the map
)
}
)
}
}
}
}
Expand All @@ -235,13 +251,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 +309,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