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:
parent
6bfadfa962
commit
e1b968bfe0
6 changed files with 178 additions and 6 deletions
22
app/src/main/java/ani/dantotsu/util/CountUpTimer.kt
Normal file
22
app/src/main/java/ani/dantotsu/util/CountUpTimer.kt
Normal 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
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue