From fd00b26f9b478ab54887c58be7723b02bb5a19d6 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 16 Oct 2016 15:58:44 +0200 Subject: [PATCH] add a helper function to determine if the file is an image --- .../filemanager/dialogs/PropertiesDialog.kt | 12 +++++++----- .../filepicker/models/FileDirItem.kt | 8 ++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt index 1010090b..bbc2d4c4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/dialogs/PropertiesDialog.kt @@ -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() diff --git a/library/src/main/kotlin/com/simplemobiletools/filepicker/models/FileDirItem.kt b/library/src/main/kotlin/com/simplemobiletools/filepicker/models/FileDirItem.kt index e5f508b3..e0eaf3b3 100644 --- a/library/src/main/kotlin/com/simplemobiletools/filepicker/models/FileDirItem.kt +++ b/library/src/main/kotlin/com/simplemobiletools/filepicker/models/FileDirItem.kt @@ -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 { @@ -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 + } }