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
data class PreviewFrames(
val urls: List<String>? = null,
val frameWidth: Int? = null,
val frameHeight: Int? = null,
val totalCount: Int? = null,
val durationPerFrame: Int? = null,
val framesPerPageX: Int? = null,
val framesPerPageY: Int? = null,
val urls: List<String>,
val frameWidth: Int,
val frameHeight: Int,
val totalCount: Int,
val durationPerFrame: Long,
val framesPerPageX: Int,
val framesPerPageY: Int
)

View File

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