button to regenerate color
This commit is contained in:
parent
00751aaf51
commit
4b09a8011c
4 changed files with 41 additions and 14 deletions
|
@ -123,9 +123,6 @@ dependencies {
|
||||||
implementation 'com.google.firebase:firebase-firestore-ktx'
|
implementation 'com.google.firebase:firebase-firestore-ktx'
|
||||||
implementation 'com.google.firebase:firebase-perf-ktx'
|
implementation 'com.google.firebase:firebase-perf-ktx'
|
||||||
implementation 'com.google.firebase:firebase-config-ktx'
|
implementation 'com.google.firebase:firebase-config-ktx'
|
||||||
|
|
||||||
// Colorpicker
|
|
||||||
implementation 'com.github.skydoves:colorpicker-compose:1.0.2'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow references to generate code
|
// Allow references to generate code
|
||||||
|
|
|
@ -1,20 +1,26 @@
|
||||||
package be.ugent.sel.studeez.screens.subjects.form
|
package be.ugent.sel.studeez.screens.subjects.form
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.material.OutlinedTextField
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
|
import androidx.compose.material.Button
|
||||||
|
import androidx.compose.material.ButtonDefaults
|
||||||
|
import androidx.compose.material.MaterialTheme
|
||||||
import androidx.compose.material.Text
|
import androidx.compose.material.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.stringResource
|
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
import be.ugent.sel.studeez.common.composable.BasicButton
|
import be.ugent.sel.studeez.common.composable.BasicButton
|
||||||
import be.ugent.sel.studeez.common.composable.DeleteButton
|
import be.ugent.sel.studeez.common.composable.DeleteButton
|
||||||
|
import be.ugent.sel.studeez.common.composable.LabelledInputField
|
||||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
||||||
import be.ugent.sel.studeez.common.ext.basicButton
|
import be.ugent.sel.studeez.common.ext.basicButton
|
||||||
import be.ugent.sel.studeez.common.ext.fieldModifier
|
import be.ugent.sel.studeez.common.ext.fieldModifier
|
||||||
|
import be.ugent.sel.studeez.common.ext.generateRandomArgb
|
||||||
import be.ugent.sel.studeez.resources
|
import be.ugent.sel.studeez.resources
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
import be.ugent.sel.studeez.R.string as AppText
|
||||||
|
|
||||||
|
@ -31,7 +37,7 @@ fun SubjectCreateRoute(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
onConfirm = { viewModel.onCreate(openAndPopUp) },
|
onConfirm = { viewModel.onCreate(openAndPopUp) },
|
||||||
onNameChange = viewModel::onNameChange,
|
onNameChange = viewModel::onNameChange,
|
||||||
onColorChange = {},
|
onColorChange = viewModel::onColorChange,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +54,7 @@ fun SubjectEditRoute(
|
||||||
uiState = uiState,
|
uiState = uiState,
|
||||||
onConfirm = { viewModel.onEdit(openAndPopUp) },
|
onConfirm = { viewModel.onEdit(openAndPopUp) },
|
||||||
onNameChange = viewModel::onNameChange,
|
onNameChange = viewModel::onNameChange,
|
||||||
onColorChange = {},
|
onColorChange = viewModel::onColorChange,
|
||||||
) {
|
) {
|
||||||
DeleteButton(text = AppText.delete_subject) {
|
DeleteButton(text = AppText.delete_subject) {
|
||||||
viewModel.onDelete(openAndPopUp)
|
viewModel.onDelete(openAndPopUp)
|
||||||
|
@ -63,7 +69,7 @@ fun SubjectForm(
|
||||||
uiState: SubjectFormUiState,
|
uiState: SubjectFormUiState,
|
||||||
onConfirm: () -> Unit,
|
onConfirm: () -> Unit,
|
||||||
onNameChange: (String) -> Unit,
|
onNameChange: (String) -> Unit,
|
||||||
onColorChange: (Color) -> Unit,
|
onColorChange: (Long) -> Unit,
|
||||||
extraButton: @Composable () -> Unit = {},
|
extraButton: @Composable () -> Unit = {},
|
||||||
) {
|
) {
|
||||||
SecondaryScreenTemplate(
|
SecondaryScreenTemplate(
|
||||||
|
@ -71,13 +77,13 @@ fun SubjectForm(
|
||||||
popUp = goBack,
|
popUp = goBack,
|
||||||
) {
|
) {
|
||||||
Column {
|
Column {
|
||||||
OutlinedTextField(
|
LabelledInputField(
|
||||||
singleLine = true,
|
singleLine = true,
|
||||||
value = uiState.name,
|
value = uiState.name,
|
||||||
onValueChange = onNameChange,
|
onNewValue = onNameChange,
|
||||||
placeholder = { Text(stringResource(id = AppText.name)) },
|
label = AppText.name,
|
||||||
modifier = Modifier.fieldModifier(),
|
|
||||||
)
|
)
|
||||||
|
ColorPicker(onColorChange, uiState)
|
||||||
BasicButton(
|
BasicButton(
|
||||||
text = AppText.confirm,
|
text = AppText.confirm,
|
||||||
modifier = Modifier.basicButton(),
|
modifier = Modifier.basicButton(),
|
||||||
|
@ -88,6 +94,27 @@ fun SubjectForm(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ColorPicker(
|
||||||
|
onColorChange: (Long) -> Unit,
|
||||||
|
uiState: SubjectFormUiState,
|
||||||
|
) {
|
||||||
|
Button(
|
||||||
|
onClick = { onColorChange(Color.generateRandomArgb()) },
|
||||||
|
modifier = Modifier
|
||||||
|
.fieldModifier(),
|
||||||
|
colors = ButtonDefaults.buttonColors(
|
||||||
|
backgroundColor = Color(uiState.color),
|
||||||
|
// contentColor = MaterialTheme.colors.onSurface.copy(alpha = 0.4f),
|
||||||
|
),
|
||||||
|
shape = RoundedCornerShape(4.dp),
|
||||||
|
// border = BorderStroke(1.dp, MaterialTheme.colors.onSurface.copy(alpha = 0.4f)),
|
||||||
|
elevation = null,
|
||||||
|
) {
|
||||||
|
Text(text = "Regenerate color")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun AddSubjectFormPreview() {
|
fun AddSubjectFormPreview() {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package be.ugent.sel.studeez.screens.subjects.form
|
package be.ugent.sel.studeez.screens.subjects.form
|
||||||
|
|
||||||
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import be.ugent.sel.studeez.common.ext.generateRandomArgb
|
||||||
|
|
||||||
data class SubjectFormUiState(
|
data class SubjectFormUiState(
|
||||||
val name: String = "",
|
val name: String = "",
|
||||||
val color: Long = 0xFFFFD200,
|
val color: Long = Color.generateRandomArgb(),
|
||||||
)
|
)
|
|
@ -46,7 +46,7 @@ class SubjectCreateFormViewModel @Inject constructor(
|
||||||
fun onCreate(openAndPopUp: (String, String) -> Unit) {
|
fun onCreate(openAndPopUp: (String, String) -> Unit) {
|
||||||
val newSubject = Subject(
|
val newSubject = Subject(
|
||||||
name = name,
|
name = name,
|
||||||
argb_color = Color.generateRandomArgb(),
|
argb_color = color,
|
||||||
)
|
)
|
||||||
subjectDAO.saveSubject(
|
subjectDAO.saveSubject(
|
||||||
newSubject
|
newSubject
|
||||||
|
|
Reference in a new issue