add a helper function to determine if the file is an image

This commit is contained in:
tibbi 2016-10-16 15:58:44 +02:00
parent 424ca7dfb5
commit fd00b26f9b
2 changed files with 15 additions and 5 deletions

View File

@ -40,6 +40,8 @@ class PropertiesDialog : DialogFragment() {
properties_files_count_label.visibility = View.VISIBLE
properties_files_count.visibility = View.VISIBLE
properties_files_count.text = mFilesCnt.toString()
} else if (mItem.isImage()) {
}
val file = File(mItem.path)
@ -47,13 +49,13 @@ class PropertiesDialog : DialogFragment() {
}
return AlertDialog.Builder(context)
.setTitle(resources.getString(title))
.setView(infoView)
.setPositiveButton(R.string.ok, null)
.create()
.setTitle(resources.getString(title))
.setView(infoView)
.setPositiveButton(R.string.ok, null)
.create()
}
fun getItemSize(): String {
private fun getItemSize(): String {
if (mItem.isDirectory) {
mShowHidden = Config.newInstance(context).showHidden
return getDirectorySize(File(mItem.path)).formatSize()

View File

@ -1,5 +1,7 @@
package com.simplemobiletools.filepicker.models
import android.graphics.BitmapFactory
class FileDirItem(val path: String, val name: String, val isDirectory: Boolean, val children: Int, val size: Long) :
Comparable<FileDirItem> {
@ -16,4 +18,10 @@ class FileDirItem(val path: String, val name: String, val isDirectory: Boolean,
override fun toString(): String {
return "FileDirItem{name=$name, isDirectory=$isDirectory, path=$path, children=$children, size=$size}"
}
fun isImage(): Boolean {
val options = BitmapFactory.Options()
options.inJustDecodeBounds = true
return options.outWidth !== -1 && options.outHeight !== -1
}
}