#30 hierarchical edit screen structure
This commit is contained in:
		
							parent
							
								
									dfbc99ba38
								
							
						
					
					
						commit
						e592a6acc0
					
				
					 4 changed files with 114 additions and 6 deletions
				
			
		|  | @ -1,4 +1,58 @@ | ||||||
| package be.ugent.sel.studeez.screens.timer_edit | package be.ugent.sel.studeez.screens.timer_edit.editScreens | ||||||
|  | 
 | ||||||
|  | import androidx.compose.foundation.layout.Column | ||||||
|  | import androidx.compose.foundation.layout.fillMaxHeight | ||||||
|  | import androidx.compose.foundation.layout.fillMaxWidth | ||||||
|  | import androidx.compose.foundation.rememberScrollState | ||||||
|  | import androidx.compose.foundation.verticalScroll | ||||||
|  | import androidx.compose.material.OutlinedTextField | ||||||
|  | import androidx.compose.material.Text | ||||||
|  | import androidx.compose.runtime.Composable | ||||||
|  | import androidx.compose.ui.Alignment | ||||||
|  | import androidx.compose.ui.Modifier | ||||||
|  | import be.ugent.sel.studeez.R | ||||||
|  | import be.ugent.sel.studeez.common.composable.BasicButton | ||||||
|  | import be.ugent.sel.studeez.common.composable.LabelledInputField | ||||||
|  | import be.ugent.sel.studeez.common.ext.basicButton | ||||||
|  | import be.ugent.sel.studeez.common.ext.fieldModifier | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_info.TimerInfo | ||||||
|  | 
 | ||||||
|  | abstract class AbstractTimerEditScreen(private val timerInfo: TimerInfo) { | ||||||
|  | 
 | ||||||
|  |     @Composable | ||||||
|  |     operator fun invoke(onSaveClick: (TimerInfo) -> Unit) { | ||||||
|  |         // TODO klassen hierarchie voor uistate | ||||||
|  |         // TODO klassen extras implementeren | ||||||
|  | 
 | ||||||
|  |         Column( | ||||||
|  |             modifier = Modifier.fillMaxWidth().fillMaxHeight(), | ||||||
|  |             horizontalAlignment = Alignment.CenterHorizontally | ||||||
|  |         ) { | ||||||
|  | 
 | ||||||
|  |             // Fields that every timer shares (ommited id) | ||||||
|  |             LabelledInputField( | ||||||
|  |                 value = timerInfo.name, | ||||||
|  |                 onNewValue = {}, | ||||||
|  |                 label = R.string.name | ||||||
|  |             ) | ||||||
|  |             LabelledInputField( | ||||||
|  |                 value = timerInfo.description, | ||||||
|  |                 onNewValue = {}, | ||||||
|  |                 label = R.string.description, | ||||||
|  |                 singleLine = false | ||||||
|  |             ) | ||||||
|  | 
 | ||||||
|  |             ExtraFields() | ||||||
|  | 
 | ||||||
|  |             BasicButton(R.string.save, Modifier.basicButton()) { | ||||||
|  |                 onSaveClick(timerInfo) | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Composable | ||||||
|  |     open fun ExtraFields() { | ||||||
|  |         // By default no extra fields, unless overwritten by subclass. | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
| abstract class AbstractTimerEditScreen { |  | ||||||
| } | } | ||||||
|  | @ -1,4 +1,29 @@ | ||||||
| package be.ugent.sel.studeez.screens.timer_edit.editScreens | package be.ugent.sel.studeez.screens.timer_edit.editScreens | ||||||
| 
 | 
 | ||||||
| class BreakTimerEditScreen { | import androidx.compose.runtime.* | ||||||
|  | import be.ugent.sel.studeez.common.composable.TimePickerButton | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.Time | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_info.PomodoroTimerInfo | ||||||
|  | 
 | ||||||
|  | class BreakTimerEditScreen( | ||||||
|  |     private val breakTimerInfo: PomodoroTimerInfo | ||||||
|  | ): AbstractTimerEditScreen(breakTimerInfo) { | ||||||
|  | 
 | ||||||
|  |     @Composable | ||||||
|  |     override fun ExtraFields() { | ||||||
|  |         // If the user presses the OK button on the timepicker, the time in the button should change | ||||||
|  |         var studyTime: Int by remember { mutableStateOf(breakTimerInfo.studyTime) } | ||||||
|  |         var breakTime: Int by remember { mutableStateOf(breakTimerInfo.breakTime) } | ||||||
|  | 
 | ||||||
|  |         val breakHms: HoursMinutesSeconds = Time(breakTime).getAsHMS() | ||||||
|  |         val studyHms: HoursMinutesSeconds = Time(studyTime).getAsHMS() | ||||||
|  |         TimePickerButton(studyHms) { _, hour, minute -> | ||||||
|  |             studyTime = hour * 60 * 60 + minute * 60 | ||||||
|  |         } | ||||||
|  |         TimePickerButton(breakHms) { _, hour, minute -> | ||||||
|  |             breakTime = hour * 60 * 60 + minute * 60 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  | @ -1,4 +1,31 @@ | ||||||
| package be.ugent.sel.studeez.screens.timer_edit | package be.ugent.sel.studeez.screens.timer_edit.editScreens | ||||||
|  | 
 | ||||||
|  | import androidx.compose.runtime.* | ||||||
|  | import androidx.compose.ui.tooling.preview.Preview | ||||||
|  | import be.ugent.sel.studeez.common.composable.TimePickerButton | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.HoursMinutesSeconds | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.Time | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_info.CustomTimerInfo | ||||||
|  | 
 | ||||||
|  | class CustomTimerEditScreen(private val customTimerInfo: CustomTimerInfo): AbstractTimerEditScreen(customTimerInfo) { | ||||||
|  | 
 | ||||||
|  |     @Composable | ||||||
|  |     override fun ExtraFields() { | ||||||
|  |         // If the user presses the OK button on the timepicker, the time in the button should change | ||||||
|  |         var studyTime by remember { mutableStateOf(customTimerInfo.studyTime) } | ||||||
|  | 
 | ||||||
|  |         val hms: HoursMinutesSeconds = Time(studyTime).getAsHMS() | ||||||
|  |         TimePickerButton(hms) { _, hour, minute -> | ||||||
|  |             studyTime = hour * 60 * 60 + minute * 60 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| class CustomTimerEditScreen { | } | ||||||
|  | 
 | ||||||
|  | @Preview | ||||||
|  | @Composable | ||||||
|  | fun TimePickerPreview() { | ||||||
|  |     val customTimerInfo = CustomTimerInfo("custom", "my description", 25) | ||||||
|  |     CustomTimerEditScreen(customTimerInfo).ExtraFields() | ||||||
| } | } | ||||||
|  | @ -1,4 +1,6 @@ | ||||||
| package be.ugent.sel.studeez.screens.timer_edit.editScreens | package be.ugent.sel.studeez.screens.timer_edit.editScreens | ||||||
| 
 | 
 | ||||||
| class EndlessTimerEditScreen { | import be.ugent.sel.studeez.data.local.models.timer_info.EndlessTimerInfo | ||||||
|  | 
 | ||||||
|  | class EndlessTimerEditScreen(endlessTimerInfo: EndlessTimerInfo): AbstractTimerEditScreen(endlessTimerInfo) { | ||||||
| } | } | ||||||
		Reference in a new issue
	
	 lbarraga
						lbarraga