From 0c183b9cc752f7a773efb98923216bffe8decc07 Mon Sep 17 00:00:00 2001 From: lbarraga Date: Sun, 16 Apr 2023 23:20:38 +0200 Subject: [PATCH] #40 timer info class and subclasses, used for display of a timer --- .../timer_functional/FunctionalCustomTimer.kt | 4 +++ .../FunctionalEndlessTimer.kt | 4 +++ .../FunctionalPomodoroTimer.kt | 4 +++ .../timer_functional/FunctionalTimer.kt | 4 +++ .../timer_functional/HoursMinutesSeconds.kt | 3 ++ .../local/models/timer_functional/Time.kt | 4 +++ .../local/models/timer_info/BreakTimerInfo.kt | 31 +++++++++++++++++ .../models/timer_info/CustomTimerInfo.kt | 27 +++++++++++++++ .../models/timer_info/EndlessTimerInfo.kt | 25 ++++++++++++++ .../data/local/models/timer_info/TimerInfo.kt | 26 +++++++++++++++ .../data/local/models/timer_info/TimerJson.kt | 16 +++++++++ .../data/local/models/timer_info/TimerType.kt | 7 ++++ .../studeez/domain/ConfigurationService.kt | 4 +++ .../ugent/sel/studeez/domain/Performance.kt | 27 --------------- .../be/ugent/sel/studeez/domain/TimerDAO.kt | 4 +++ .../FirebaseConfigurationService.kt | 4 +++ .../domain/implementation/FirebaseTimerDAO.kt | 4 +++ .../domain/implementation/ToTimerConverter.kt | 33 +++++++++++++++++++ .../timer_overview/TimerOverviewScreen.kt | 2 ++ .../timer_overview/TimerOverviewViewModel.kt | 4 +++ 20 files changed, 210 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalCustomTimer.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalEndlessTimer.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalPomodoroTimer.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/HoursMinutesSeconds.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/Time.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/BreakTimerInfo.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/EndlessTimerInfo.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerInfo.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerJson.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerType.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/ConfigurationService.kt delete mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/Performance.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/TimerDAO.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseConfigurationService.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/domain/implementation/ToTimerConverter.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt create mode 100644 app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewViewModel.kt diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalCustomTimer.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalCustomTimer.kt new file mode 100644 index 0000000..abbb2a2 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalCustomTimer.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.data.local.models.timer_functional + +class FunctionalCustomTimer { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalEndlessTimer.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalEndlessTimer.kt new file mode 100644 index 0000000..c602f5c --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalEndlessTimer.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.data.local.models.timer_functional + +class FunctionalEndlessTimer { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalPomodoroTimer.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalPomodoroTimer.kt new file mode 100644 index 0000000..f9698be --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalPomodoroTimer.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.data.local.models.timer_functional + +class FunctionalPomodoroTimer { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt new file mode 100644 index 0000000..ba1989f --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/FunctionalTimer.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.data.local.models.timer_functional + +class FunctionalTimer { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/HoursMinutesSeconds.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/HoursMinutesSeconds.kt new file mode 100644 index 0000000..f651a68 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/HoursMinutesSeconds.kt @@ -0,0 +1,3 @@ +package be.ugent.sel.studeez.data.local.models.timer_functional + +data class HoursMinutesSeconds() diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/Time.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/Time.kt new file mode 100644 index 0000000..24e1245 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_functional/Time.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.data.local.models.timer_functional + +class Time { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/BreakTimerInfo.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/BreakTimerInfo.kt new file mode 100644 index 0000000..735f917 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/BreakTimerInfo.kt @@ -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 { + return mapOf( + "type" to "break", + "name" to name, + "description" to description, + "studyTime" to studyTime, + "breakTime" to breakTime, + "repeats" to repeats, + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt new file mode 100644 index 0000000..5e06536 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/CustomTimerInfo.kt @@ -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 { + return mapOf( + "type" to "custom", + "name" to name, + "description" to description, + "studyTime" to studyTime, + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/EndlessTimerInfo.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/EndlessTimerInfo.kt new file mode 100644 index 0000000..d459a4e --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/EndlessTimerInfo.kt @@ -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 { + return mapOf( + "type" to "endless", + "name" to name, + "description" to description + ) + } + +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerInfo.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerInfo.kt new file mode 100644 index 0000000..343e7e3 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerInfo.kt @@ -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 + +} + diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerJson.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerJson.kt new file mode 100644 index 0000000..37a7b9f --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerJson.kt @@ -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 = "" +) diff --git a/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerType.kt b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerType.kt new file mode 100644 index 0000000..20fb36d --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/data/local/models/timer_info/TimerType.kt @@ -0,0 +1,7 @@ +package be.ugent.sel.studeez.data.local.models.timer_info + +enum class TimerType { + BREAK, + ENDLESS, + CUSTOM +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/ConfigurationService.kt b/app/src/main/java/be/ugent/sel/studeez/domain/ConfigurationService.kt new file mode 100644 index 0000000..c20b772 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/ConfigurationService.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.domain + +interface ConfigurationService { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/Performance.kt b/app/src/main/java/be/ugent/sel/studeez/domain/Performance.kt deleted file mode 100644 index e987b37..0000000 --- a/app/src/main/java/be/ugent/sel/studeez/domain/Performance.kt +++ /dev/null @@ -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 trace(name: String, block: Trace.() -> T): T = Trace.create(name).trace(block) diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/TimerDAO.kt b/app/src/main/java/be/ugent/sel/studeez/domain/TimerDAO.kt new file mode 100644 index 0000000..5498696 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/TimerDAO.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.domain + +interface TimerDAO { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseConfigurationService.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseConfigurationService.kt new file mode 100644 index 0000000..1e11fd8 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseConfigurationService.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.domain.implementation + +class FirebaseConfigurationService { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt new file mode 100644 index 0000000..c0b0a26 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/FirebaseTimerDAO.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.domain.implementation + +class FirebaseTimerDAO { +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/domain/implementation/ToTimerConverter.kt b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/ToTimerConverter.kt new file mode 100644 index 0000000..1720d66 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/domain/implementation/ToTimerConverter.kt @@ -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 = 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): List { + return a.map(this::getTimer) + } + + fun jsonToTimerJsonList(json: String): List { + val type = object : TypeToken>() {}.type + return Gson().fromJson(json, type) + } +} \ No newline at end of file diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt new file mode 100644 index 0000000..f8c8f54 --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewScreen.kt @@ -0,0 +1,2 @@ +package be.ugent.sel.studeez.screens.timer_overview + diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewViewModel.kt new file mode 100644 index 0000000..62b30ab --- /dev/null +++ b/app/src/main/java/be/ugent/sel/studeez/screens/timer_overview/TimerOverviewViewModel.kt @@ -0,0 +1,4 @@ +package be.ugent.sel.studeez.screens.timer_overview + +class TimerOverviewViewModel { +} \ No newline at end of file