#40 timer info class and subclasses, used for display of a timer
This commit is contained in:
		
							parent
							
								
									66e68493e4
								
							
						
					
					
						commit
						0c183b9cc7
					
				
					 20 changed files with 210 additions and 27 deletions
				
			
		|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_functional | ||||||
|  | 
 | ||||||
|  | class FunctionalCustomTimer { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_functional | ||||||
|  | 
 | ||||||
|  | class FunctionalEndlessTimer { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_functional | ||||||
|  | 
 | ||||||
|  | class FunctionalPomodoroTimer { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_functional | ||||||
|  | 
 | ||||||
|  | class FunctionalTimer { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,3 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_functional | ||||||
|  | 
 | ||||||
|  | data class HoursMinutesSeconds() | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_functional | ||||||
|  | 
 | ||||||
|  | class Time { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,31 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
|  | 
 | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalPomodoroTimer | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  | 
 | ||||||
|  | class BreakTimerInfo( | ||||||
|  |     name: String, | ||||||
|  |     description: String, | ||||||
|  |     private val studyTime: Int, | ||||||
|  |     private val breakTime: Int, | ||||||
|  |     private val repeats: Int, | ||||||
|  |     id: String = "" | ||||||
|  | ):  TimerInfo(id, name, description) { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     override fun getFunctionalTimer(): FunctionalTimer { | ||||||
|  |         return FunctionalPomodoroTimer(studyTime, breakTime, repeats) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     override fun asJson() : Map<String, Any> { | ||||||
|  |         return mapOf( | ||||||
|  |             "type" to "break", | ||||||
|  |             "name" to name, | ||||||
|  |             "description" to description, | ||||||
|  |             "studyTime" to studyTime, | ||||||
|  |             "breakTime" to breakTime, | ||||||
|  |             "repeats" to repeats, | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -0,0 +1,27 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
|  | 
 | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalCustomTimer | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  | 
 | ||||||
|  | class CustomTimerInfo( | ||||||
|  |     name: String, | ||||||
|  |     description: String, | ||||||
|  |     private val studyTime: Int, | ||||||
|  |     id: String = "" | ||||||
|  | ):  TimerInfo(id, name, description) { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     override fun getFunctionalTimer(): FunctionalTimer { | ||||||
|  |         return FunctionalCustomTimer(studyTime) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     override fun asJson() : Map<String, Any> { | ||||||
|  |         return mapOf( | ||||||
|  |             "type" to "custom", | ||||||
|  |             "name" to name, | ||||||
|  |             "description" to description, | ||||||
|  |             "studyTime" to studyTime, | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -0,0 +1,25 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
|  | 
 | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalEndlessTimer | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  | 
 | ||||||
|  | class EndlessTimerInfo( | ||||||
|  |     name: String, | ||||||
|  |     description: String, | ||||||
|  |     id: String = "" | ||||||
|  | ):  TimerInfo(id, name, description) { | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     override fun getFunctionalTimer(): FunctionalTimer { | ||||||
|  |         return FunctionalEndlessTimer() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     override fun asJson() : Map<String, Any> { | ||||||
|  |         return mapOf( | ||||||
|  |             "type" to "endless", | ||||||
|  |             "name" to name, | ||||||
|  |             "description" to description | ||||||
|  |         ) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | @ -0,0 +1,26 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
|  | 
 | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_functional.FunctionalTimer | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Deze klasse stelt de de info van een timer weer. Elke timer heeft een id, naam en descriptie | ||||||
|  |  */ | ||||||
|  | abstract class TimerInfo( | ||||||
|  |     val id: String, | ||||||
|  |     val name: String, | ||||||
|  |     val description: String | ||||||
|  | ) { | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Geef de functionele timer terug die kan gebruikt worden tijden een sessie. | ||||||
|  |      */ | ||||||
|  |     abstract fun getFunctionalTimer(): FunctionalTimer | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Geef deze timer weer als json. Wordt gebruikt om terug op te slaan in de databank. | ||||||
|  |      * TODO implementaties hebben nog hardgecodeerde strings. | ||||||
|  |      */ | ||||||
|  |     abstract fun asJson(): Map<String, Any> | ||||||
|  | 
 | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | @ -0,0 +1,16 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
|  | 
 | ||||||
|  | import com.google.firebase.firestore.DocumentId | ||||||
|  | 
 | ||||||
|  | /** | ||||||
|  |  * Timers uit de databank (remote config en firestore) worden als eerste stap omgezet naar dit type. | ||||||
|  |  */ | ||||||
|  | data class TimerJson( | ||||||
|  |     val type: String = "", | ||||||
|  |     val name: String = "", | ||||||
|  |     val description: String = "", | ||||||
|  |     val studyTime: Int = 0, | ||||||
|  |     val breakTime: Int = 0, | ||||||
|  |     val repeats: Int = 0, | ||||||
|  |     @DocumentId val id: String = "" | ||||||
|  | ) | ||||||
|  | @ -0,0 +1,7 @@ | ||||||
|  | package be.ugent.sel.studeez.data.local.models.timer_info | ||||||
|  | 
 | ||||||
|  | enum class TimerType { | ||||||
|  |     BREAK, | ||||||
|  |     ENDLESS, | ||||||
|  |     CUSTOM | ||||||
|  | } | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.domain | ||||||
|  | 
 | ||||||
|  | interface ConfigurationService { | ||||||
|  | } | ||||||
|  | @ -1,27 +0,0 @@ | ||||||
| /* |  | ||||||
| Copyright 2022 Google LLC |  | ||||||
| 
 |  | ||||||
| Licensed under the Apache License, Version 2.0 (the "License"); |  | ||||||
| you may not use this file except in compliance with the License. |  | ||||||
| You may obtain a copy of the License at |  | ||||||
| 
 |  | ||||||
|     https://www.apache.org/licenses/LICENSE-2.0 |  | ||||||
| 
 |  | ||||||
| Unless required by applicable law or agreed to in writing, software |  | ||||||
| distributed under the License is distributed on an "AS IS" BASIS, |  | ||||||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |  | ||||||
| See the License for the specific language governing permissions and |  | ||||||
| limitations under the License. |  | ||||||
|  */ |  | ||||||
| 
 |  | ||||||
| package be.ugent.sel.studeez.domain |  | ||||||
| 
 |  | ||||||
| import com.google.firebase.perf.ktx.trace |  | ||||||
| import com.google.firebase.perf.metrics.Trace |  | ||||||
| 
 |  | ||||||
| /** |  | ||||||
|  * Trace a block with Firebase performance. |  | ||||||
|  * |  | ||||||
|  * Supports both suspend and regular methods. |  | ||||||
|  */ |  | ||||||
| inline fun <T> trace(name: String, block: Trace.() -> T): T = Trace.create(name).trace(block) |  | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.domain | ||||||
|  | 
 | ||||||
|  | interface TimerDAO { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.domain.implementation | ||||||
|  | 
 | ||||||
|  | class FirebaseConfigurationService { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.domain.implementation | ||||||
|  | 
 | ||||||
|  | class FirebaseTimerDAO { | ||||||
|  | } | ||||||
|  | @ -0,0 +1,33 @@ | ||||||
|  | package be.ugent.sel.studeez.domain.implementation | ||||||
|  | 
 | ||||||
|  | import be.ugent.sel.studeez.data.local.models.timer_info.* | ||||||
|  | import com.google.gson.Gson | ||||||
|  | import com.google.gson.reflect.TypeToken | ||||||
|  | 
 | ||||||
|  | class JsonToTimerConverter { | ||||||
|  | 
 | ||||||
|  |     private val timerInfoMap: Map<String, TimerFactory> = mapOf( | ||||||
|  |         "endless" to TimerFactory { EndlessTimerInfo(it.name, it.description) }, | ||||||
|  |         "custom" to TimerFactory { CustomTimerInfo(it.name, it.description, it.studyTime) }, | ||||||
|  |         "break" to TimerFactory { PomodoroTimerInfo( | ||||||
|  |             it.name, | ||||||
|  |             it.description, | ||||||
|  |             it.studyTime, | ||||||
|  |             it.breakTime, | ||||||
|  |             it.repeats | ||||||
|  |         ) } | ||||||
|  |     ) | ||||||
|  | 
 | ||||||
|  |     private fun getTimer(timerJson: TimerJson): TimerInfo{ | ||||||
|  |         return timerInfoMap.getValue(timerJson.type).makeTimer(timerJson) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fun convertToTimerInfoList(a: List<TimerJson>): List<TimerInfo> { | ||||||
|  |         return a.map(this::getTimer) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     fun jsonToTimerJsonList(json: String): List<TimerJson> { | ||||||
|  |         val type = object : TypeToken<List<TimerJson>>() {}.type | ||||||
|  |         return Gson().fromJson(json, type) | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | package be.ugent.sel.studeez.screens.timer_overview | ||||||
|  | 
 | ||||||
|  | @ -0,0 +1,4 @@ | ||||||
|  | package be.ugent.sel.studeez.screens.timer_overview | ||||||
|  | 
 | ||||||
|  | class TimerOverviewViewModel { | ||||||
|  | } | ||||||
		Reference in a new issue
	
	 lbarraga
						lbarraga