Make PreviewFrames fields non-null.

This commit is contained in:
Isira Seneviratne 2023-05-11 09:03:14 +05:30
parent 854ba87fc5
commit 04facb03df
2 changed files with 11 additions and 11 deletions

View File

@ -4,11 +4,11 @@ import kotlinx.serialization.Serializable
@Serializable @Serializable
data class PreviewFrames( data class PreviewFrames(
val urls: List<String>? = null, val urls: List<String>,
val frameWidth: Int? = null, val frameWidth: Int,
val frameHeight: Int? = null, val frameHeight: Int,
val totalCount: Int? = null, val totalCount: Int,
val durationPerFrame: Int? = null, val durationPerFrame: Long,
val framesPerPageX: Int? = null, val framesPerPageX: Int,
val framesPerPageY: Int? = null, val framesPerPageY: Int
) )

View File

@ -93,12 +93,12 @@ class SeekbarPreviewListener(
private fun getPreviewFrame(position: Long): PreviewFrame? { private fun getPreviewFrame(position: Long): PreviewFrame? {
var startPosition: Long = 0 var startPosition: Long = 0
// get the frames with the best quality // get the frames with the best quality
val frames = previewFrames.sortedBy { it.frameHeight }.lastOrNull() val frames = previewFrames.maxByOrNull { it.frameHeight }
frames?.urls?.forEach { url -> frames?.urls?.forEach { url ->
// iterate over all available positions and find the one matching the current position // iterate over all available positions and find the one matching the current position
for (y in 0 until frames.framesPerPageY!!) { for (y in 0 until frames.framesPerPageY) {
for (x in 0 until frames.framesPerPageX!!) { for (x in 0 until frames.framesPerPageX) {
val endPosition = startPosition + frames.durationPerFrame!!.toLong() val endPosition = startPosition + frames.durationPerFrame
if (position in startPosition until endPosition) { if (position in startPosition until endPosition) {
return PreviewFrame(url, x, y, frames.framesPerPageX, frames.framesPerPageY) return PreviewFrame(url, x, y, frames.framesPerPageX, frames.framesPerPageY)
} }