From 9d9b987abf6da733849318b4994ef2cc6d5f74e5 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 20 Nov 2016 16:45:38 +0100 Subject: [PATCH] update filepicker to 1.5.0 + minor cleanup --- app/build.gradle | 2 +- .../filemanager/activities/MainActivity.kt | 16 ++-- .../filemanager/adapters/ItemsAdapter.kt | 4 +- .../filemanager/extensions/file.kt | 85 ------------------- 4 files changed, 12 insertions(+), 95 deletions(-) delete mode 100644 app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/file.kt diff --git a/app/build.gradle b/app/build.gradle index 48ae0bde..2e30f6d0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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" diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt index 35f86e3d..e417953f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/activities/MainActivity.kt @@ -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 - } } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt index 7a6fe922..d94c863d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/adapters/ItemsAdapter.kt @@ -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) : BaseAdapter() { private val mInflater: LayoutInflater @@ -51,7 +53,7 @@ class ItemsAdapter(context: Context, private val mItems: List) : 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 diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/file.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/file.kt deleted file mode 100644 index f9b77e71..00000000 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/extensions/file.kt +++ /dev/null @@ -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() -}