Skip to content

Commit

Permalink
Added documentation to CountdownManager.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
leahlud committed Dec 5, 2023
1 parent 8198124 commit 1da88c0
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class CountdownManager(val listener: CountDownListener) {
}

private var times = listOf(eventStartTime, hackingStartTime, hackingEndTime)

// placeholders in case design team decides to change this
private val titles = listOf("HACKILLINOIS BEGINS IN", "HACKING BEGINS IN", "HACKING ENDS IN", "MEMORIES MADE")

private var timer: CountDownTimer? = null
Expand All @@ -36,28 +34,32 @@ class CountdownManager(val listener: CountDownListener) {
private val refreshRateMs = 500L

fun start() {
// find current state of the countdown in terms of timestamps
while (state < times.size && times[state].isBeforeNow()) {
state++
}
startTimer()
}

private fun startTimer() {
// if past the last timestamp, don't start another timer
if (state >= times.size) {
listener.updateTitle(titles[state])

listener.updateTitle(titles[titles.size - 1]) // set to be last title
return
}
listener.updateTitle(titles[state])

// else set the current title and start timer until next timestamp
listener.updateTitle(titles[state])
val millisTillTimerFinishes = times[state].timeUntilMs()

timer = object : CountDownTimer(millisTillTimerFinishes, refreshRateMs) {
// update the time on each tick
override fun onTick(millisUntilFinished: Long) {
val timeUntil = times[state].timeUntilMs()
listener.updateTime(timeUntil)
}

// increment the state when timer is finished
override fun onFinish() {
state++
startTimer()
Expand Down

0 comments on commit 1da88c0

Please sign in to comment.