#65 functional timer abstract class and subclasses
This commit is contained in:
		
							parent
							
								
									89eda17bc2
								
							
						
					
					
						commit
						d7f316675c
					
				
					 6 changed files with 97 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,16 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
class FunctionalCustomTimer {
 | 
			
		||||
class FunctionalCustomTimer(studyTime: Int): FunctionalTimer(studyTime) {
 | 
			
		||||
 | 
			
		||||
    override fun tick() {
 | 
			
		||||
        if (time.getTime() == 0) {
 | 
			
		||||
            view = "Done!"
 | 
			
		||||
        } else {
 | 
			
		||||
            time.minOne()
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun hasEnded(): Boolean {
 | 
			
		||||
        return time.getTime() == 0
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,12 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
class FunctionalEndlessTimer {
 | 
			
		||||
class FunctionalEndlessTimer() : FunctionalTimer(0){
 | 
			
		||||
 | 
			
		||||
    override fun hasEnded(): Boolean {
 | 
			
		||||
        return false
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun tick() {
 | 
			
		||||
        time.plusOne()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,34 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
class FunctionalPomodoroTimer {
 | 
			
		||||
class FunctionalPomodoroTimer(
 | 
			
		||||
    private var studyTime: Int,
 | 
			
		||||
    private var breakTime: Int, repeats: Int
 | 
			
		||||
): FunctionalTimer(studyTime) {
 | 
			
		||||
 | 
			
		||||
    private var breaksRemaining = repeats
 | 
			
		||||
    private var isInBreak = false
 | 
			
		||||
 | 
			
		||||
    override fun tick() {
 | 
			
		||||
        if (time.getTime() == 0 && breaksRemaining == 0){
 | 
			
		||||
            view = "Done!"
 | 
			
		||||
            return
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (time.getTime() == 0) {
 | 
			
		||||
            if (isInBreak) {
 | 
			
		||||
                breaksRemaining--
 | 
			
		||||
                view = "Focus! ($breaksRemaining breaks remaining)"
 | 
			
		||||
                time.setTime(studyTime)
 | 
			
		||||
            } else {
 | 
			
		||||
                view = "Take a break!"
 | 
			
		||||
                time.setTime(breakTime)
 | 
			
		||||
            }
 | 
			
		||||
            isInBreak = !isInBreak
 | 
			
		||||
        }
 | 
			
		||||
        time.minOne()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    override fun hasEnded(): Boolean {
 | 
			
		||||
        return breaksRemaining == 0 && time.getTime() == 0
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,19 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
class FunctionalTimer {
 | 
			
		||||
abstract class FunctionalTimer(initialValue: Int) {
 | 
			
		||||
    protected val time: Time = Time(initialValue)
 | 
			
		||||
    protected var view: String = "Focus"
 | 
			
		||||
 | 
			
		||||
    fun getHoursMinutesSeconds(): HoursMinutesSeconds {
 | 
			
		||||
        return time.getAsHMS()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun getViewString(): String {
 | 
			
		||||
        return view
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    abstract fun tick()
 | 
			
		||||
 | 
			
		||||
    abstract fun hasEnded(): Boolean
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,3 +1,3 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
data class HoursMinutesSeconds()
 | 
			
		||||
data class HoursMinutesSeconds(val hours: Int, val minutes: Int, val seconds: Int)
 | 
			
		||||
| 
						 | 
				
			
			@ -1,4 +1,30 @@
 | 
			
		|||
package be.ugent.sel.studeez.data.local.models.timer_functional
 | 
			
		||||
 | 
			
		||||
class Time {
 | 
			
		||||
class Time(initialTime: Int) {
 | 
			
		||||
 | 
			
		||||
    private var time = initialTime
 | 
			
		||||
 | 
			
		||||
    fun minOne() {
 | 
			
		||||
        time--
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun plusOne() {
 | 
			
		||||
        time++
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun setTime(newTime: Int) {
 | 
			
		||||
        time = newTime
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun getTime(): Int {
 | 
			
		||||
        return time
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun getAsHMS(): HoursMinutesSeconds {
 | 
			
		||||
        val hours: Int = time / (60 * 60)
 | 
			
		||||
        val minutes: Int = (time / (60)) % 60
 | 
			
		||||
        val seconds: Int = time % 60
 | 
			
		||||
        return HoursMinutesSeconds(hours, minutes, seconds)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in a new issue