From 5c3fc8d1c82e3e8647b6517f1900b6e217ad2b2d Mon Sep 17 00:00:00 2001 From: Majid Arabi Date: Thu, 26 May 2022 16:05:45 +0430 Subject: [PATCH] Fixed #2 --- file-picker/src/main/AndroidManifest.xml | 1 + .../com/github/file_picker/adapter/ItemVH.kt | 6 ++--- .../github/file_picker/extension/FileExt.kt | 27 ++++++------------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/file-picker/src/main/AndroidManifest.xml b/file-picker/src/main/AndroidManifest.xml index 47dc55a..27a5330 100644 --- a/file-picker/src/main/AndroidManifest.xml +++ b/file-picker/src/main/AndroidManifest.xml @@ -3,5 +3,6 @@ package="ir.one_developer.file_picker"> + \ No newline at end of file diff --git a/file-picker/src/main/java/com/github/file_picker/adapter/ItemVH.kt b/file-picker/src/main/java/com/github/file_picker/adapter/ItemVH.kt index d08205b..98dc52f 100644 --- a/file-picker/src/main/java/com/github/file_picker/adapter/ItemVH.kt +++ b/file-picker/src/main/java/com/github/file_picker/adapter/ItemVH.kt @@ -12,7 +12,7 @@ import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.target.Target import com.github.file_picker.FileType import com.github.file_picker.extension.getMusicCoverArt -import com.github.file_picker.extension.pathName +import com.github.file_picker.extension.lastPathTitle import com.github.file_picker.extension.size import com.github.file_picker.model.Media import ir.one_developer.file_picker.R @@ -50,12 +50,12 @@ internal class ItemVH( item.file.getMusicCoverArt() } FileType.IMAGE -> { - tvPath.text = item.file.pathName() + tvPath.text = item.file.lastPathTitle() ivMediaIcon.setImageResource(R.drawable.ic_image) item.file } FileType.VIDEO -> { - tvPath.text = item.file.pathName() + tvPath.text = item.file.lastPathTitle() ivMediaIcon.setImageResource(R.drawable.ic_play) item.file } diff --git a/file-picker/src/main/java/com/github/file_picker/extension/FileExt.kt b/file-picker/src/main/java/com/github/file_picker/extension/FileExt.kt index 3847f18..f23a95f 100644 --- a/file-picker/src/main/java/com/github/file_picker/extension/FileExt.kt +++ b/file-picker/src/main/java/com/github/file_picker/extension/FileExt.kt @@ -29,34 +29,23 @@ internal fun File.size(): String = when { * * @return */ -internal fun File.pathName(): CharSequence { +internal fun File.lastPathTitle(): CharSequence { val paths = path.split("/") - paths.forEachIndexed { index, title -> - if (index == paths.lastIndex - 1) { - return title - } - } + val titleIndex = paths.lastIndex - 1 + if (titleIndex >= 0) return paths[titleIndex] return "" } -/** - * Is video - */ -internal val File.isVideo - get() = this.name.isVideo() - /** * Get music cover art * * @return */ -internal fun File.getMusicCoverArt(): Bitmap? { +internal fun File.getMusicCoverArt(): Bitmap? = try { val mData = MediaMetadataRetriever() mData.setDataSource(path) - return try { - val art = mData.embeddedPicture - BitmapFactory.decodeByteArray(art, 0, art?.size ?: 0) - } catch (e: Exception) { - null - } + val art = mData.embeddedPicture + BitmapFactory.decodeByteArray(art, 0, art?.size ?: 0) +} catch (e: Exception) { + null } \ No newline at end of file