From 5237c93f02a99f423cd95c937eb6ca4b7c6f6fc1 Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Fri, 9 Aug 2024 13:51:00 +0530 Subject: [PATCH 1/3] add played progress indicator to video view --- .../anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt | 2 ++ .../java/dev/anilbeesetti/nextplayer/core/model/Video.kt | 4 ++++ .../feature/videopicker/composables/VideoItem.kt | 9 +++++++++ 3 files changed, 15 insertions(+) diff --git a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt index 6198208a5..a4a505ab8 100644 --- a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt +++ b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt @@ -22,6 +22,7 @@ fun MediumEntity.toVideo() = Video( dateModified = modified, format = format, thumbnailPath = thumbnailPath, + playbackPosition = playbackPosition, lastPlayedAt = lastPlayedTime?.let { Date(it) }, formattedDuration = Utils.formatDurationMillis(duration), formattedFileSize = Utils.formatFileSize(size), @@ -41,6 +42,7 @@ fun MediumWithInfo.toVideo() = Video( 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), diff --git a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt index 5bb371fc6..41a1462cc 100644 --- a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt +++ b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt @@ -14,6 +14,7 @@ data class Video( val width: Int, val height: Int, val size: Long, + val playbackPosition: Long = 200, val dateModified: Long = 0, val formattedDuration: String = "", val formattedFileSize: String = "", @@ -25,6 +26,8 @@ data class Video( val subtitleStreams: List = emptyList(), ) : Serializable { + val playedPercentage: Float = playbackPosition.toFloat() / duration.toFloat() + companion object { val sample = Video( id = 8, @@ -39,6 +42,7 @@ data class Video( size = 1000, formattedDuration = "29.36", formattedFileSize = "320KB", + playbackPosition = 200, ) } } diff --git a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt index c3beb0b76..cbf839d15 100644 --- a/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt +++ b/feature/videopicker/src/main/java/dev/anilbeesetti/nextplayer/feature/videopicker/composables/VideoItem.kt @@ -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 @@ -97,6 +99,13 @@ fun VideoItem( shape = MaterialTheme.shapes.extraSmall, ) } + + if (video.playedPercentage > 0) { + LinearProgressIndicator( + progress = { video.playedPercentage }, + modifier = Modifier.align(Alignment.BottomCenter), + ) + } } }, headlineContent = { From eec20ad356243e2c528fe186dc389ba999e07b4d Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Fri, 9 Aug 2024 13:53:46 +0530 Subject: [PATCH 2/3] remove unused method --- .../nextplayer/core/data/mappers/ToVideo.kt | 22 ------------------- .../nextplayer/core/model/Video.kt | 3 +-- .../VideoPickerPreviewParameterProvider.kt | 8 ------- 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt index a4a505ab8..2f3a81230 100644 --- a/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt +++ b/core/data/src/main/java/dev/anilbeesetti/nextplayer/core/data/mappers/ToVideo.kt @@ -2,39 +2,17 @@ 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, - playbackPosition = playbackPosition, - 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, diff --git a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt index 41a1462cc..00cdff06c 100644 --- a/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt +++ b/core/model/src/main/java/dev/anilbeesetti/nextplayer/core/model/Video.kt @@ -9,7 +9,6 @@ data class Video( val parentPath: String = "", val duration: Long, val uriString: String, - val displayName: String, val nameWithExtension: String, val width: Int, val height: Int, @@ -26,6 +25,7 @@ data class Video( val subtitleStreams: List = emptyList(), ) : Serializable { + val displayName: String = nameWithExtension.substringBeforeLast(".") val playedPercentage: Float = playbackPosition.toFloat() / duration.toFloat() companion object { @@ -36,7 +36,6 @@ 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, diff --git a/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/preview/VideoPickerPreviewParameterProvider.kt b/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/preview/VideoPickerPreviewParameterProvider.kt index a7fd5bb56..39af271cc 100644 --- a/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/preview/VideoPickerPreviewParameterProvider.kt +++ b/core/ui/src/main/java/dev/anilbeesetti/nextplayer/core/ui/preview/VideoPickerPreviewParameterProvider.kt @@ -13,7 +13,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, @@ -25,7 +24,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider uriString = "", nameWithExtension = "The Godfather (1972) 1080p BluRay x264.mp4", duration = 1400, - displayName = "The Godfather (1972) 1080p BluRay x264", width = 1920, height = 1080, size = 2000, @@ -37,7 +35,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, @@ -49,7 +46,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, @@ -61,7 +57,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, @@ -73,7 +68,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, @@ -85,7 +79,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, @@ -96,7 +89,6 @@ class VideoPickerPreviewParameterProvider : PreviewParameterProvider 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, From 5a95fa18d2e30c7ae7d7e3ab9d0e5b9b954cb2ed Mon Sep 17 00:00:00 2001 From: Anil Kumar Beesetti Date: Fri, 9 Aug 2024 14:24:12 +0530 Subject: [PATCH 3/3] fix tests --- .../core/domain/GetSortedVideosUseCaseTest.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/core/domain/src/test/java/dev/anilbeesetti/nextplayer/core/domain/GetSortedVideosUseCaseTest.kt b/core/domain/src/test/java/dev/anilbeesetti/nextplayer/core/domain/GetSortedVideosUseCaseTest.kt index d5bd11c3d..9e3325f01 100644 --- a/core/domain/src/test/java/dev/anilbeesetti/nextplayer/core/domain/GetSortedVideosUseCaseTest.kt +++ b/core/domain/src/test/java/dev/anilbeesetti/nextplayer/core/domain/GetSortedVideosUseCaseTest.kt @@ -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, @@ -138,7 +137,6 @@ val testVideoItems = listOf( ), Video( id = 2, - displayName = "B", duration = 2000, uriString = "content://media/external/video/media/2", height = 1930, @@ -149,7 +147,6 @@ val testVideoItems = listOf( ), Video( id = 3, - displayName = "C", duration = 3000, uriString = "content://media/external/video/media/3", height = 1940, @@ -160,7 +157,6 @@ val testVideoItems = listOf( ), Video( id = 4, - displayName = "D", duration = 4000, uriString = "content://media/external/video/media/4", height = 1950, @@ -171,7 +167,6 @@ val testVideoItems = listOf( ), Video( id = 5, - displayName = "E", duration = 5000, uriString = "content://media/external/video/media/5", height = 1960, @@ -182,7 +177,6 @@ val testVideoItems = listOf( ), Video( id = 6, - displayName = "F", duration = 6000, uriString = "content://media/external/video/media/6", height = 1970, @@ -193,7 +187,6 @@ val testVideoItems = listOf( ), Video( id = 7, - displayName = "G", duration = 7000, uriString = "content://media/external/video/media/7", height = 1980, @@ -204,7 +197,6 @@ val testVideoItems = listOf( ), Video( id = 8, - displayName = "H", duration = 8000, uriString = "content://media/external/video/media/8", height = 1990, @@ -215,7 +207,6 @@ val testVideoItems = listOf( ), Video( id = 9, - displayName = "I", duration = 9000, uriString = "content://media/external/video/media/9", height = 2160, @@ -226,7 +217,6 @@ val testVideoItems = listOf( ), Video( id = 10, - displayName = "J", duration = 10000, uriString = "content://media/external/video/media/10", height = 2170,