Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add played progress indicator to video view #1028

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,25 @@ package dev.anilbeesetti.nextplayer.core.data.mappers

import dev.anilbeesetti.nextplayer.core.common.Utils
import dev.anilbeesetti.nextplayer.core.database.entities.AudioStreamInfoEntity
import dev.anilbeesetti.nextplayer.core.database.entities.MediumEntity
import dev.anilbeesetti.nextplayer.core.database.entities.SubtitleStreamInfoEntity
import dev.anilbeesetti.nextplayer.core.database.relations.MediumWithInfo
import dev.anilbeesetti.nextplayer.core.model.Video
import java.util.Date

fun MediumEntity.toVideo() = Video(
id = mediaStoreId,
path = path,
parentPath = parentPath,
duration = duration,
uriString = uriString,
displayName = name.substringBeforeLast("."),
nameWithExtension = name,
width = width,
height = height,
size = size,
dateModified = modified,
format = format,
thumbnailPath = thumbnailPath,
lastPlayedAt = lastPlayedTime?.let { Date(it) },
formattedDuration = Utils.formatDurationMillis(duration),
formattedFileSize = Utils.formatFileSize(size),
)

fun MediumWithInfo.toVideo() = Video(
id = mediumEntity.mediaStoreId,
path = mediumEntity.path,
parentPath = mediumEntity.parentPath,
duration = mediumEntity.duration,
uriString = mediumEntity.uriString,
displayName = mediumEntity.name.substringBeforeLast("."),
nameWithExtension = mediumEntity.name,
width = mediumEntity.width,
height = mediumEntity.height,
size = mediumEntity.size,
dateModified = mediumEntity.modified,
format = mediumEntity.format,
thumbnailPath = mediumEntity.thumbnailPath,
playbackPosition = mediumEntity.playbackPosition,
lastPlayedAt = mediumEntity.lastPlayedTime?.let { Date(it) },
formattedDuration = Utils.formatDurationMillis(mediumEntity.duration),
formattedFileSize = Utils.formatFileSize(mediumEntity.size),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class GetSortedVideosUseCaseTest {
val testVideoItems = listOf(
Video(
id = 1,
displayName = "A",
duration = 1000,
uriString = "content://media/external/video/media/1",
height = 1920,
Expand All @@ -138,7 +137,6 @@ val testVideoItems = listOf(
),
Video(
id = 2,
displayName = "B",
duration = 2000,
uriString = "content://media/external/video/media/2",
height = 1930,
Expand All @@ -149,7 +147,6 @@ val testVideoItems = listOf(
),
Video(
id = 3,
displayName = "C",
duration = 3000,
uriString = "content://media/external/video/media/3",
height = 1940,
Expand All @@ -160,7 +157,6 @@ val testVideoItems = listOf(
),
Video(
id = 4,
displayName = "D",
duration = 4000,
uriString = "content://media/external/video/media/4",
height = 1950,
Expand All @@ -171,7 +167,6 @@ val testVideoItems = listOf(
),
Video(
id = 5,
displayName = "E",
duration = 5000,
uriString = "content://media/external/video/media/5",
height = 1960,
Expand All @@ -182,7 +177,6 @@ val testVideoItems = listOf(
),
Video(
id = 6,
displayName = "F",
duration = 6000,
uriString = "content://media/external/video/media/6",
height = 1970,
Expand All @@ -193,7 +187,6 @@ val testVideoItems = listOf(
),
Video(
id = 7,
displayName = "G",
duration = 7000,
uriString = "content://media/external/video/media/7",
height = 1980,
Expand All @@ -204,7 +197,6 @@ val testVideoItems = listOf(
),
Video(
id = 8,
displayName = "H",
duration = 8000,
uriString = "content://media/external/video/media/8",
height = 1990,
Expand All @@ -215,7 +207,6 @@ val testVideoItems = listOf(
),
Video(
id = 9,
displayName = "I",
duration = 9000,
uriString = "content://media/external/video/media/9",
height = 2160,
Expand All @@ -226,7 +217,6 @@ val testVideoItems = listOf(
),
Video(
id = 10,
displayName = "J",
duration = 10000,
uriString = "content://media/external/video/media/10",
height = 2170,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ data class Video(
val parentPath: String = "",
val duration: Long,
val uriString: String,
val displayName: String,
val nameWithExtension: String,
val width: Int,
val height: Int,
val size: Long,
val playbackPosition: Long = 200,
val dateModified: Long = 0,
val formattedDuration: String = "",
val formattedFileSize: String = "",
Expand All @@ -25,6 +25,9 @@ data class Video(
val subtitleStreams: List<SubtitleStreamInfo> = emptyList(),
) : Serializable {

val displayName: String = nameWithExtension.substringBeforeLast(".")
val playedPercentage: Float = playbackPosition.toFloat() / duration.toFloat()

companion object {
val sample = Video(
id = 8,
Expand All @@ -33,12 +36,12 @@ data class Video(
uriString = "",
nameWithExtension = "Avengers Endgame (2019) BluRay x264.mp4",
duration = 1000,
displayName = "Avengers Endgame (2019) BluRay x264",
width = 1920,
height = 1080,
size = 1000,
formattedDuration = "29.36",
formattedFileSize = "320KB",
playbackPosition = 200,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Shawshank Redemption (1994) 720p BluRay x264.mp4",
duration = 1200,
displayName = "The Shawshank Redemption (1994) 720p BluRay x264",
width = 1280,
height = 720,
size = 1000,
Expand All @@ -25,7 +24,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Godfather (1972) 1080p BluRay x264.mp4",
duration = 1400,
displayName = "The Godfather (1972) 1080p BluRay x264",
width = 1920,
height = 1080,
size = 2000,
Expand All @@ -37,7 +35,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Dark Knight (2008) 2160p BluRay x264.mp4",
duration = 1500,
displayName = "The Dark Knight (2008) 2160p BluRay x264",
width = 3840,
height = 2160,
size = 3000,
Expand All @@ -49,7 +46,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Godfather: Part II (1974) 720p BluRay x264.mp4",
duration = 1350,
displayName = "The Godfather: Part II (1974) 720p BluRay x264",
width = 1280,
height = 720,
size = 4000,
Expand All @@ -61,7 +57,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Lord of the Rings: The Fellowship of the Ring (2001) 1080p BluRay x264.mp4",
duration = 1800,
displayName = "The Lord of the Rings: The Fellowship of the Ring (2001) 1080p BluRay x264",
width = 1920,
height = 1080,
size = 5000,
Expand All @@ -73,7 +68,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Lord of the Rings: The Two Towers (2002) 1080p BluRay x264.mp4",
duration = 2000,
displayName = "The Lord of the Rings: The Two Towers (2002) 1080p BluRay x264",
width = 1920,
height = 1080,
size = 6000,
Expand All @@ -85,7 +79,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "The Lord of the Rings: The Return of the King (2003) 1080p BluRay x264.mp4",
duration = 2100,
displayName = "The Lord of the Rings: The Return of the King (2003) 1080p BluRay x264",
width = 1920,
height = 1080,
size = 7000,
Expand All @@ -96,7 +89,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider<List<Video>
uriString = "",
nameWithExtension = "Star Wars: Episode IV - A New Hope (1977) 2160p BluRay x264.mp4",
duration = 1500,
displayName = "Star Wars: Episode IV - A New Hope (1977) 2160p BluRay x264",
width = 3840,
height = 2160,
size = 8000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Icon
import androidx.compose.material3.LinearProgressIndicator
import androidx.compose.material3.ListItemDefaults
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
Expand Down Expand Up @@ -97,6 +99,13 @@ fun VideoItem(
shape = MaterialTheme.shapes.extraSmall,
)
}

if (video.playedPercentage > 0) {
LinearProgressIndicator(
progress = { video.playedPercentage },
modifier = Modifier.align(Alignment.BottomCenter),
)
}
}
},
headlineContent = {
Expand Down
Loading