Leanback: update formatstring to also use hours

This commit is contained in:
Felix 2020-04-10 15:28:28 +02:00
parent b2188b8c19
commit 4e8d5fb371

View file

@ -157,7 +157,7 @@ class ChaosflixSeekDataProvider(
Log.d(TAG, "Thumb size: ${thumb.width}x${thumb.height}")
val seconds = positions[index] / 1000
val time = String.format("%d:%02d:%02d",(seconds / 3600) ,(seconds / 60) % 60, seconds % 60)
val time = formatTime(seconds)
drawStringToBitmap(thumb, time)
val duration = System.currentTimeMillis() - startTime
@ -166,6 +166,17 @@ class ChaosflixSeekDataProvider(
return thumb
}
private fun formatTime(seconds: Long): String {
val s = seconds % 60
val m = (seconds / 60) % 60
val h = seconds / 3600
return if(h > 0){
String.format("%d:%02d:%02d", h, m, s)
} else {
String.format("%d:%02d", m, s)
}
}
private fun drawStringToBitmap(thumb: Bitmap, time: String) {
val canvas = Canvas(thumb)
val paint = Paint()
@ -192,7 +203,7 @@ class ChaosflixSeekDataProvider(
private fun createDummyThumbnail(index: Int): Bitmap {
val seconds = positions[index] / 1000
val time = String.format("%d:%02d", seconds / 60, seconds % 60)
val time = formatTime(seconds)
val bitmap = Bitmap.createBitmap(THUMB_WIDTH, THUMB_HEIGHT, Bitmap.Config.ARGB_8888)
drawStringToBitmap(bitmap, time)