Skip to content

Commit

Permalink
Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai-Cristian Condrea committed Jun 29, 2024
1 parent fb6a9f5 commit c8be9b9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
applicationId = "com.d4rk.cleaner"
minSdk = 26
targetSdk = 34
versionCode = 76
versionCode = 77
versionName = "2.0.0"
archivesName = "${applicationId}-v${versionName}"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,12 @@ fun AnalyzeComposable() {
}

@Composable
fun FileCard(file : File , viewModel : HomeViewModel) {
fun FileCard(file: File, viewModel: HomeViewModel) {
val context = LocalContext.current
val fileExtension = getFileExtension(file.name)
val thumbnail = remember {
getVideoThumbnail(file.absolutePath, thumbnailWidth = 128, thumbnailHeight = 128)
}
Card(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -293,10 +296,9 @@ fun FileCard(file : File , viewModel : HomeViewModel) {
}

in context.resources.getStringArray(R.array.video_extensions).toList() -> {
val thumbnailBitmap = getVideoThumbnail(file.absolutePath)
if (thumbnailBitmap != null) {
if (thumbnail != null) {
Image(
bitmap = thumbnailBitmap.asImageBitmap(),
bitmap = thumbnail.asImageBitmap(),
contentDescription = file.name,
contentScale = ContentScale.Crop,
modifier = Modifier.fillMaxSize()
Expand Down Expand Up @@ -392,4 +394,4 @@ fun SelectAllComposable(
interactionSource = interactionSource ,
)
}
}
}
7 changes: 5 additions & 2 deletions app/src/main/kotlin/com/d4rk/cleaner/utils/ImageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import android.graphics.drawable.Drawable
import android.media.MediaMetadataRetriever
import com.d4rk.cleaner.R

fun getVideoThumbnail(videoPath: String): Bitmap? {
fun getVideoThumbnail(videoPath: String, thumbnailWidth: Int = 128, thumbnailHeight: Int = 128): Bitmap? {
val mediaMetadataRetriever = MediaMetadataRetriever()
try {
mediaMetadataRetriever.setDataSource(videoPath)
return mediaMetadataRetriever.getFrameAtTime(1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC) // Extract frame at 1 second
val bitmap = mediaMetadataRetriever.getFrameAtTime(1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC)
if (bitmap != null) {
return Bitmap.createScaledBitmap(bitmap, thumbnailWidth, thumbnailHeight, false)
}
} catch (_ : Exception) {

} finally {
Expand Down

0 comments on commit c8be9b9

Please sign in to comment.