Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Majid Arabi committed May 26, 2022
2 parents f9d3e11 + 5c3fc8d commit 0ba9f2c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion file-picker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ afterEvaluate {
from components.release
groupId = 'com.github.majidarabi'
artifactId = 'file-picker'
version = '0.0.9'
version = '0.1.0'
}
}
}
Expand Down
1 change: 1 addition & 0 deletions file-picker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
package="ir.one_developer.file_picker">

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

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 0ba9f2c

Please sign in to comment.