colorgenerator as extension of Color
This commit is contained in:
		
							parent
							
								
									79ed70bb17
								
							
						
					
					
						commit
						00751aaf51
					
				
					 2 changed files with 13 additions and 5 deletions
				
			
		|  | @ -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,6 +2,8 @@ package be.ugent.sel.studeez.screens.subjects.form | ||||||
| 
 | 
 | ||||||
| import androidx.compose.runtime.MutableState | import androidx.compose.runtime.MutableState | ||||||
| import androidx.compose.runtime.mutableStateOf | 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.SelectedSubject | ||||||
| import be.ugent.sel.studeez.data.local.models.task.Subject | import be.ugent.sel.studeez.data.local.models.task.Subject | ||||||
| import be.ugent.sel.studeez.domain.LogService | import be.ugent.sel.studeez.domain.LogService | ||||||
|  | @ -10,7 +12,6 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations | ||||||
| import be.ugent.sel.studeez.screens.StudeezViewModel | import be.ugent.sel.studeez.screens.StudeezViewModel | ||||||
| import dagger.hilt.android.lifecycle.HiltViewModel | import dagger.hilt.android.lifecycle.HiltViewModel | ||||||
| import javax.inject.Inject | import javax.inject.Inject | ||||||
| import kotlin.random.Random |  | ||||||
| 
 | 
 | ||||||
| abstract class SubjectFormViewModel( | abstract class SubjectFormViewModel( | ||||||
|     protected val subjectDAO: SubjectDAO, |     protected val subjectDAO: SubjectDAO, | ||||||
|  | @ -43,12 +44,9 @@ class SubjectCreateFormViewModel @Inject constructor( | ||||||
|     override val uiState = mutableStateOf(SubjectFormUiState()) |     override val uiState = mutableStateOf(SubjectFormUiState()) | ||||||
| 
 | 
 | ||||||
|     fun onCreate(openAndPopUp: (String, String) -> Unit) { |     fun onCreate(openAndPopUp: (String, String) -> Unit) { | ||||||
|         val random = Random |  | ||||||
|         val mask: Long = (0x000000FFL shl random.nextInt(0, 3)).inv() |  | ||||||
|         val randomColor = random.nextLong(0xFF000000L, 0xFFFFFFFFL) and mask |  | ||||||
|         val newSubject = Subject( |         val newSubject = Subject( | ||||||
|             name = name, |             name = name, | ||||||
|             argb_color = randomColor, |             argb_color = Color.generateRandomArgb(), | ||||||
|         ) |         ) | ||||||
|         subjectDAO.saveSubject( |         subjectDAO.saveSubject( | ||||||
|             newSubject |             newSubject | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 brreynie
						brreynie