Merge branch 'development' into bugfixes
This commit is contained in:
		
						commit
						53993bb2f0
					
				
					 6 changed files with 49 additions and 12 deletions
				
			
		|  | @ -123,9 +123,6 @@ dependencies { | |||
|     implementation 'com.google.firebase:firebase-firestore-ktx' | ||||
|     implementation 'com.google.firebase:firebase-perf-ktx' | ||||
|     implementation 'com.google.firebase:firebase-config-ktx' | ||||
| 
 | ||||
|     // Colorpicker | ||||
|     implementation 'com.github.skydoves:colorpicker-compose:1.0.2' | ||||
| } | ||||
| 
 | ||||
| // Allow references to generate code | ||||
|  |  | |||
|  | @ -0,0 +1,10 @@ | |||
| package be.ugent.sel.studeez.common.ext | ||||
| 
 | ||||
| import androidx.compose.ui.graphics.Color | ||||
| import kotlin.random.Random | ||||
| 
 | ||||
| fun Color.Companion.generateRandomArgb(): Long { | ||||
|     val random = Random | ||||
|     val mask: Long = (0x000000FFL shl random.nextInt(0, 3)).inv() | ||||
|     return random.nextLong(0xFF000000L, 0xFFFFFFFFL) and mask | ||||
| } | ||||
|  | @ -2,7 +2,9 @@ package be.ugent.sel.studeez.screens.subjects.form | |||
| 
 | ||||
| import androidx.annotation.StringRes | ||||
| 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.Text | ||||
| import androidx.compose.runtime.Composable | ||||
| import androidx.compose.runtime.getValue | ||||
|  | @ -11,11 +13,15 @@ import androidx.compose.ui.Modifier | |||
| import androidx.compose.ui.graphics.Color | ||||
| import androidx.compose.ui.res.stringResource | ||||
| 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.DeleteButton | ||||
| import be.ugent.sel.studeez.common.composable.FormComposable | ||||
| import be.ugent.sel.studeez.common.composable.LabelledInputField | ||||
| import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate | ||||
| import be.ugent.sel.studeez.common.ext.basicButton | ||||
| import be.ugent.sel.studeez.common.ext.fieldModifier | ||||
| import be.ugent.sel.studeez.common.ext.generateRandomArgb | ||||
| import be.ugent.sel.studeez.resources | ||||
| import kotlinx.coroutines.launch | ||||
| import be.ugent.sel.studeez.R.string as AppText | ||||
|  | @ -33,7 +39,7 @@ fun SubjectCreateRoute( | |||
|         uiState = uiState, | ||||
|         onConfirm = { viewModel.onCreate(openAndPopUp) }, | ||||
|         onNameChange = viewModel::onNameChange, | ||||
|         onColorChange = {}, | ||||
|         onColorChange = viewModel::onColorChange, | ||||
|     ) | ||||
| } | ||||
| 
 | ||||
|  | @ -51,7 +57,7 @@ fun SubjectEditRoute( | |||
|         uiState = uiState, | ||||
|         onConfirm = { viewModel.onEdit(openAndPopUp) }, | ||||
|         onNameChange = viewModel::onNameChange, | ||||
|         onColorChange = {}, | ||||
|         onColorChange = viewModel::onColorChange, | ||||
|     ) { | ||||
|         DeleteButton(text = AppText.delete_subject) { | ||||
|             coroutineScope.launch { | ||||
|  | @ -68,7 +74,7 @@ fun SubjectForm( | |||
|     uiState: SubjectFormUiState, | ||||
|     onConfirm: () -> Unit, | ||||
|     onNameChange: (String) -> Unit, | ||||
|     onColorChange: (Color) -> Unit, | ||||
|     onColorChange: (Long) -> Unit, | ||||
|     extraButton: @Composable () -> Unit = {}, | ||||
| ) { | ||||
|     FormComposable( | ||||
|  | @ -76,13 +82,13 @@ fun SubjectForm( | |||
|         popUp = goBack, | ||||
|     ) { | ||||
|         Column { | ||||
|             OutlinedTextField( | ||||
|             LabelledInputField( | ||||
|                 singleLine = true, | ||||
|                 value = uiState.name, | ||||
|                 onValueChange = onNameChange, | ||||
|                 placeholder = { Text(stringResource(id = AppText.name)) }, | ||||
|                 modifier = Modifier.fieldModifier(), | ||||
|                 onNewValue = onNameChange, | ||||
|                 label = AppText.name, | ||||
|             ) | ||||
|             ColorPicker(onColorChange, uiState) | ||||
|             BasicButton( | ||||
|                 text = AppText.confirm, | ||||
|                 modifier = Modifier.basicButton(), | ||||
|  | @ -93,6 +99,24 @@ 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 = Color.White, | ||||
|         ), | ||||
|         shape = RoundedCornerShape(4.dp), | ||||
|     ) { | ||||
|         Text(text = stringResource(id = AppText.regenerate_color)) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @Preview | ||||
| @Composable | ||||
| fun AddSubjectFormPreview() { | ||||
|  |  | |||
|  | @ -1,6 +1,9 @@ | |||
| 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( | ||||
|     val name: String = "", | ||||
|     val color: Long = 0xFFFFD200, | ||||
|     val color: Long = Color.generateRandomArgb(), | ||||
| ) | ||||
|  | @ -2,6 +2,8 @@ package be.ugent.sel.studeez.screens.subjects.form | |||
| 
 | ||||
| import androidx.compose.runtime.MutableState | ||||
| import androidx.compose.runtime.mutableStateOf | ||||
| import androidx.compose.ui.graphics.Color | ||||
| import be.ugent.sel.studeez.common.ext.generateRandomArgb | ||||
| import be.ugent.sel.studeez.data.SelectedSubject | ||||
| import be.ugent.sel.studeez.data.local.models.task.Subject | ||||
| import be.ugent.sel.studeez.domain.LogService | ||||
|  |  | |||
|  | @ -46,6 +46,7 @@ | |||
|     <string name="delete_subject">Delete Subject</string> | ||||
|     <string name="delete_task">Delete Task</string> | ||||
|     <string name="view_tasks">View</string> | ||||
|     <string name="regenerate_color">Regenerate Color</string> | ||||
| 
 | ||||
|     <!-- Sessions --> | ||||
|     <string name="sessions_temp_description">Looks like you found the sessions screen! In here, your upcoming studying sessions with friends will be listed. You can accept invites or edit your own.</string> <!-- TODO Remove this description line once implemented. --> | ||||
|  |  | |||
		Reference in a new issue
	
	 brreynie
						brreynie