Skip to content

Commit

Permalink
Merge pull request #40 from sheikh-20/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sheikh-20 authored Apr 21, 2024
2 parents 9556372 + faa1332 commit 52e23bb
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ android {
applicationId = "com.application.moviesapp"
minSdk = 24
targetSdk = 33
versionCode = 2
versionName = "1.0.1"
versionCode = 3
versionName = "1.0.2"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.application.moviesapp.ui.detail

import android.app.Activity
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import android.widget.Toast
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -392,7 +393,11 @@ fun DetailScreen(modifier: Modifier = Modifier,
TabRow(selectedTabIndex = pager.currentPage) {
items.forEachIndexed { index, horizontalPagerContent ->
Tab(selected = pager.currentPage == index,
onClick = { /*TODO*/ },
onClick = {
coroutineScope.launch {
pager.animateScrollToPage(page = index)
}
},
text = {
Text(text = items[index].title)
})
Expand Down Expand Up @@ -769,7 +774,11 @@ fun DetailScreen(modifier: Modifier = Modifier,
TabRow(selectedTabIndex = pager.currentPage) {
items.forEachIndexed { index, horizontalPagerContent ->
Tab(selected = pager.currentPage == index,
onClick = { /*TODO*/ },
onClick = {
coroutineScope.launch {
pager.animateScrollToPage(page = index)
}
},
text = {
Text(text = items[index].title)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import com.application.moviesapp.ui.play.PlayActivity
import com.application.moviesapp.ui.play.Screen
import com.application.moviesapp.ui.theme.MoviesAppTheme
import com.application.moviesapp.ui.utility.getFileSize
import com.application.moviesapp.ui.utility.getVideoDuration
import com.application.moviesapp.ui.utility.toImageUrl
import com.application.moviesapp.ui.utility.toYoutubeDuration
import com.application.moviesapp.ui.viewmodel.DownloadUiState
Expand Down Expand Up @@ -171,7 +172,7 @@ private fun DownloadCard(modifier: Modifier = Modifier,
)

Text(
text = movie?.runtime.toString() ?: "",
text = movie?.runtime ?: movie?.filePath?.getVideoDuration(context as Activity) ?: "",
style = MaterialTheme.typography.bodyMedium
)

Expand All @@ -192,9 +193,7 @@ private fun DownloadCard(modifier: Modifier = Modifier,
}
}
}

}

}

@Preview(showBackground = true, showSystemUi = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,7 @@ private fun CustomPlayerUI(modifier: Modifier = Modifier,
Row(verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(8.dp)) {

IconButton(onClick = onDownloadClick) {
Icon(imageVector = Icons.Outlined.FileDownload,
contentDescription = null,
modifier = modifier.size(24.dp), tint = MaterialTheme.colorScheme.onPrimary)
}

IconButton(onClick = { onFullScreenModeClicked(isFullScreen.not()) }) {
Icon(imageVector = if (isFullScreen) Icons.Rounded.FullscreenExit else Icons.Rounded.Fullscreen,
contentDescription = null,
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/application/moviesapp/ui/utility/Utitlity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.application.moviesapp.ui.utility
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.media.MediaMetadataRetriever
import android.os.Build
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.runtime.Composable
Expand All @@ -13,6 +14,7 @@ import androidx.core.app.NotificationManagerCompat
import com.application.moviesapp.BuildConfig
import com.application.moviesapp.R
import com.application.moviesapp.domain.model.Stream
import timber.log.Timber
import java.io.File
import java.util.Locale
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -143,4 +145,22 @@ fun SetLanguage(language: String = "English (US)") {
val resources = LocalContext.current.resources
resources.updateConfiguration(configuration, resources.displayMetrics)

}

fun String.getVideoDuration(context: Context): String {

Timber.tag("MoviesApp").d(this)

val retriever = MediaMetadataRetriever()
retriever.setDataSource(File(context.filesDir, "output/$this").path)
val durationString = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
retriever.release()

return if (durationString?.toLong() != null) {
val seconds = durationString.toLong().div(1000)
val minutes = seconds / 60
val remainingSeconds = seconds % 60
println("Video duration: $minutes minutes and $remainingSeconds seconds")
"${minutes}m ${remainingSeconds}s"
} else ""
}

0 comments on commit 52e23bb

Please sign in to comment.