Skip to content

Commit 5c3fc8d

Browse files
author
Majid Arabi
committed
Fixed #2
1 parent c21a1fc commit 5c3fc8d

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

file-picker/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
package="ir.one_developer.file_picker">
44

55
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6+
<application android:requestLegacyExternalStorage="true"/>
67

78
</manifest>

file-picker/src/main/java/com/github/file_picker/adapter/ItemVH.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import com.bumptech.glide.request.RequestListener
1212
import com.bumptech.glide.request.target.Target
1313
import com.github.file_picker.FileType
1414
import com.github.file_picker.extension.getMusicCoverArt
15-
import com.github.file_picker.extension.pathName
15+
import com.github.file_picker.extension.lastPathTitle
1616
import com.github.file_picker.extension.size
1717
import com.github.file_picker.model.Media
1818
import ir.one_developer.file_picker.R
@@ -50,12 +50,12 @@ internal class ItemVH(
5050
item.file.getMusicCoverArt()
5151
}
5252
FileType.IMAGE -> {
53-
tvPath.text = item.file.pathName()
53+
tvPath.text = item.file.lastPathTitle()
5454
ivMediaIcon.setImageResource(R.drawable.ic_image)
5555
item.file
5656
}
5757
FileType.VIDEO -> {
58-
tvPath.text = item.file.pathName()
58+
tvPath.text = item.file.lastPathTitle()
5959
ivMediaIcon.setImageResource(R.drawable.ic_play)
6060
item.file
6161
}

file-picker/src/main/java/com/github/file_picker/extension/FileExt.kt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,23 @@ internal fun File.size(): String = when {
2929
*
3030
* @return
3131
*/
32-
internal fun File.pathName(): CharSequence {
32+
internal fun File.lastPathTitle(): CharSequence {
3333
val paths = path.split("/")
34-
paths.forEachIndexed { index, title ->
35-
if (index == paths.lastIndex - 1) {
36-
return title
37-
}
38-
}
34+
val titleIndex = paths.lastIndex - 1
35+
if (titleIndex >= 0) return paths[titleIndex]
3936
return ""
4037
}
4138

42-
/**
43-
* Is video
44-
*/
45-
internal val File.isVideo
46-
get() = this.name.isVideo()
47-
4839
/**
4940
* Get music cover art
5041
*
5142
* @return
5243
*/
53-
internal fun File.getMusicCoverArt(): Bitmap? {
44+
internal fun File.getMusicCoverArt(): Bitmap? = try {
5445
val mData = MediaMetadataRetriever()
5546
mData.setDataSource(path)
56-
return try {
57-
val art = mData.embeddedPicture
58-
BitmapFactory.decodeByteArray(art, 0, art?.size ?: 0)
59-
} catch (e: Exception) {
60-
null
61-
}
47+
val art = mData.embeddedPicture
48+
BitmapFactory.decodeByteArray(art, 0, art?.size ?: 0)
49+
} catch (e: Exception) {
50+
null
6251
}

0 commit comments

Comments
 (0)