mirror of
https://github.com/SimpleMobileTools/Simple-File-Manager.git
synced 2025-04-24 07:07:22 +02:00
simplify some property getting
This commit is contained in:
parent
f866f01ddf
commit
4b80fbd26b
@ -43,19 +43,19 @@ class PropertiesDialog : DialogFragment() {
|
|||||||
} else if (mItem.isImage()) {
|
} else if (mItem.isImage()) {
|
||||||
properties_resolution_label.visibility = View.VISIBLE
|
properties_resolution_label.visibility = View.VISIBLE
|
||||||
properties_resolution.visibility = View.VISIBLE
|
properties_resolution.visibility = View.VISIBLE
|
||||||
properties_resolution.text = mItem.imageResolution
|
properties_resolution.text = mItem.getImageResolution()
|
||||||
} else if (mItem.isAudio(context)) {
|
} else if (mItem.isAudio()) {
|
||||||
properties_duration_label.visibility = View.VISIBLE
|
properties_duration_label.visibility = View.VISIBLE
|
||||||
properties_duration.visibility = View.VISIBLE
|
properties_duration.visibility = View.VISIBLE
|
||||||
properties_duration.text = mItem.getDuration(context)
|
properties_duration.text = mItem.getDuration()
|
||||||
} else if (mItem.isVideo(context)) {
|
} else if (mItem.isVideo()) {
|
||||||
properties_duration_label.visibility = View.VISIBLE
|
properties_duration_label.visibility = View.VISIBLE
|
||||||
properties_duration.visibility = View.VISIBLE
|
properties_duration.visibility = View.VISIBLE
|
||||||
properties_duration.text = mItem.getDuration(context)
|
properties_duration.text = mItem.getDuration()
|
||||||
|
|
||||||
properties_resolution_label.visibility = View.VISIBLE
|
properties_resolution_label.visibility = View.VISIBLE
|
||||||
properties_resolution.visibility = View.VISIBLE
|
properties_resolution.visibility = View.VISIBLE
|
||||||
properties_resolution.text = mItem.getVideoResolution(context)
|
properties_resolution.text = mItem.getVideoResolution()
|
||||||
}
|
}
|
||||||
|
|
||||||
val file = File(mItem.path)
|
val file = File(mItem.path)
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
package com.simplemobiletools.filepicker.models
|
package com.simplemobiletools.filepicker.models
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.BitmapFactory
|
import android.graphics.BitmapFactory
|
||||||
import android.media.MediaMetadataRetriever
|
import android.media.MediaMetadataRetriever
|
||||||
import android.net.Uri
|
|
||||||
import java.io.File
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class FileDirItem(val path: String, val name: String, val isDirectory: Boolean, val children: Int, val size: Long) :
|
class FileDirItem(val path: String, val name: String, val isDirectory: Boolean, val children: Int, val size: Long) :
|
||||||
@ -32,18 +29,18 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
|
|||||||
return options.outWidth != -1 && options.outHeight != -1
|
return options.outWidth != -1 && options.outHeight != -1
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isVideo(context: Context): Boolean {
|
fun isVideo(): Boolean {
|
||||||
return getMimeType(context).startsWith("video")
|
return getMimeType().startsWith("video")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isAudio(context: Context): Boolean {
|
fun isAudio(): Boolean {
|
||||||
return getMimeType(context).startsWith("audio")
|
return getMimeType().startsWith("audio")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getMimeType(context: Context): String {
|
fun getMimeType(): String {
|
||||||
try {
|
try {
|
||||||
val retriever = MediaMetadataRetriever()
|
val retriever = MediaMetadataRetriever()
|
||||||
retriever.setDataSource(context, Uri.fromFile(File(path)))
|
retriever.setDataSource(path)
|
||||||
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE)
|
return retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_MIMETYPE)
|
||||||
} catch (ignored: Exception) {
|
} catch (ignored: Exception) {
|
||||||
|
|
||||||
@ -51,18 +48,18 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getDuration(context: Context): String {
|
fun getDuration(): String {
|
||||||
val retriever = MediaMetadataRetriever()
|
val retriever = MediaMetadataRetriever()
|
||||||
retriever.setDataSource(context, Uri.fromFile(File(path)))
|
retriever.setDataSource(path)
|
||||||
val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
val time = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
|
||||||
val timeInMillisec = java.lang.Long.parseLong(time)
|
val timeInMillisec = java.lang.Long.parseLong(time)
|
||||||
return getFormattedDuration((timeInMillisec / 1000).toInt())
|
return getFormattedDuration((timeInMillisec / 1000).toInt())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVideoResolution(context: Context): String {
|
fun getVideoResolution(): String {
|
||||||
try {
|
try {
|
||||||
val retriever = MediaMetadataRetriever()
|
val retriever = MediaMetadataRetriever()
|
||||||
retriever.setDataSource(context, Uri.fromFile(File(path)))
|
retriever.setDataSource(path)
|
||||||
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
|
val width = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_WIDTH)
|
||||||
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
|
val height = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_VIDEO_HEIGHT)
|
||||||
return "$width x $height"
|
return "$width x $height"
|
||||||
@ -72,8 +69,7 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
val imageResolution: String
|
fun getImageResolution(): String {
|
||||||
get () {
|
|
||||||
val bitmap: Bitmap? = BitmapFactory.decodeFile(path)
|
val bitmap: Bitmap? = BitmapFactory.decodeFile(path)
|
||||||
if (bitmap == null)
|
if (bitmap == null)
|
||||||
return ""
|
return ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user