feat: add a time since chapter item (#316)

* feat: add a time since chapter item

* fix: this is the song that never ends
This commit is contained in:
TwistedUmbrellaX 2024-04-04 05:45:03 -04:00 committed by GitHub
parent 6bfadfa962
commit e1b968bfe0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 178 additions and 6 deletions

View file

@ -0,0 +1,22 @@
package ani.dantotsu.util
import android.os.CountDownTimer
// https://stackoverflow.com/a/40422151/461982
abstract class CountUpTimer protected constructor(
private val duration: Long
) : CountDownTimer(duration, INTERVAL_MS) {
abstract fun onTick(second: Int)
override fun onTick(msUntilFinished: Long) {
val second = ((duration - msUntilFinished) / 1000).toInt()
onTick(second)
}
override fun onFinish() {
onTick(duration / 1000)
}
companion object {
private const val INTERVAL_MS: Long = 1000
}
}