update filepicker to 1.5.0 + minor cleanup
This commit is contained in:
parent
5a76dd5db2
commit
9d9b987abf
|
@ -41,7 +41,7 @@ dependencies {
|
|||
compile 'com.android.support:design:23.4.0'
|
||||
compile 'com.jakewharton:butterknife:8.0.1'
|
||||
compile 'com.github.bumptech.glide:glide:3.7.0'
|
||||
compile 'com.simplemobiletools:filepicker:1.4.4@aar'
|
||||
compile 'com.simplemobiletools:filepicker:1.5.0@aar'
|
||||
compile 'com.simplemobiletools:fileproperties:1.0.5@aar'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
|
||||
|
|
|
@ -23,6 +23,13 @@ import java.io.File
|
|||
class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
|
||||
var mBasePath = getInternalStoragePath()
|
||||
|
||||
companion object {
|
||||
private val STORAGE_PERMISSION = 1
|
||||
private val BACK_PRESS_TIMEOUT = 5000
|
||||
|
||||
private var mWasBackJustPressed: Boolean = false
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_main)
|
||||
|
@ -97,7 +104,7 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
|
||||
if (requestCode == STORAGE_PERMISSION) {
|
||||
if (grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
initRootFileManager()
|
||||
} else {
|
||||
toast(R.string.no_permissions)
|
||||
|
@ -129,11 +136,4 @@ class MainActivity : SimpleActivity(), ItemsFragment.ItemInteractionListener, Br
|
|||
openPath(pickedPath)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val STORAGE_PERMISSION = 1
|
||||
private val BACK_PRESS_TIMEOUT = 5000
|
||||
|
||||
private var mWasBackJustPressed: Boolean = false
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@ import com.bumptech.glide.Glide
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy
|
||||
import com.simplemobiletools.filemanager.R
|
||||
import com.simplemobiletools.filemanager.extensions.formatSize
|
||||
import com.simplemobiletools.filepicker.extensions.isGif
|
||||
import com.simplemobiletools.filepicker.models.FileDirItem
|
||||
import kotlinx.android.synthetic.main.list_item.view.*
|
||||
import java.io.File
|
||||
|
||||
class ItemsAdapter(context: Context, private val mItems: List<FileDirItem>) : BaseAdapter() {
|
||||
private val mInflater: LayoutInflater
|
||||
|
@ -51,7 +53,7 @@ class ItemsAdapter(context: Context, private val mItems: List<FileDirItem>) : Ba
|
|||
return view
|
||||
}
|
||||
|
||||
private fun getCacheStrategy(item: FileDirItem) = if (item.isGif()) DiskCacheStrategy.NONE else DiskCacheStrategy.RESULT
|
||||
private fun getCacheStrategy(item: FileDirItem) = if (File(item.path).isGif()) DiskCacheStrategy.NONE else DiskCacheStrategy.RESULT
|
||||
|
||||
private fun getChildrenCnt(item: FileDirItem): String {
|
||||
val children = item.children
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
package com.simplemobiletools.filemanager.extensions
|
||||
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.media.MediaMetadataRetriever
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
fun File.isGif() = name.toLowerCase().endsWith(".gif")
|
||||
fun File.isVideo() = getMimeType().startsWith("video")
|
||||
fun File.isAudio() = getMimeType().startsWith("audio")
|
||||
|
||||
fun File.isImage(): Boolean {
|
||||
val options = BitmapFactory.Options()
|
||||
options.inJustDecodeBounds = true
|
||||
BitmapFactory.decodeFile(path, options)
|
||||
return options.outWidth != -1 && options.outHeight != -1
|
||||
}
|
||||
|
||||
fun File.getMimeType(): String {
|
||||
try {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE)
|
||||
} catch (ignored: Exception) {
|
||||
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun File.getDuration(): String {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
||||
val timeInMillisec = java.lang.Long.parseLong(time)
|
||||
return getFormattedDuration((timeInMillisec / 1000).toInt())
|
||||
}
|
||||
|
||||
fun File.getArtist(): String? {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST)
|
||||
}
|
||||
|
||||
fun File.getAlbum(): String? {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM)
|
||||
}
|
||||
|
||||
fun File.getVideoResolution(): String {
|
||||
try {
|
||||
val retriever = MediaMetadataRetriever()
|
||||
retriever.setDataSource(path)
|
||||
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
|
||||
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
|
||||
return "$width x $height"
|
||||
} catch (ignored: Exception) {
|
||||
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
fun File.getImageResolution(): String {
|
||||
val bitmap: Bitmap? = BitmapFactory.decodeFile(path)
|
||||
if (bitmap == null)
|
||||
return ""
|
||||
|
||||
return "${bitmap.width} x ${bitmap.height}"
|
||||
}
|
||||
|
||||
private fun getFormattedDuration(duration: Int): String {
|
||||
val sb = StringBuilder(8)
|
||||
val hours = duration / (60 * 60)
|
||||
val minutes = duration % (60 * 60) / 60
|
||||
val seconds = duration % (60 * 60) % 60
|
||||
|
||||
if (duration > 3600) {
|
||||
sb.append(String.format(Locale.getDefault(), "%02d", hours)).append(":")
|
||||
}
|
||||
|
||||
sb.append(String.format(Locale.getDefault(), "%02d", minutes))
|
||||
sb.append(":").append(String.format(Locale.getDefault(), "%02d", seconds))
|
||||
return sb.toString()
|
||||
}
|
Loading…
Reference in New Issue