diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt index 6a0bd407..7edcee0d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt @@ -383,7 +383,7 @@ class MainActivity : SimpleActivity() { it?.isGetRingtonePicker = isPickRingtoneIntent it?.isPickMultipleIntent = allowPickingMultipleIntent it?.isGetContentIntent = isGetContentIntent - it?.getContentMimeType = getContentMimeType + it?.wantedMimeType = getContentMimeType } if (refreshRecents) { diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt index c2d25507..1e54d042 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt @@ -205,21 +205,10 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF val lastModifieds = context!!.getFolderLastModifieds(path) for (file in files) { - val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false) - if (fileDirItem != null) { - val mimetype = file.getMimeType() - val isProperMimeType = if (getContentMimeType.isEmpty() || file.isDirectory) { - true - } else { - if (getContentMimeType.endsWith("/*")) { - mimetype.substringBefore("/").equals(getContentMimeType.substringBefore("/"), true) - } else { - mimetype.equals(getContentMimeType, true) - } - } - - if (isProperMimeType) { - items.add(fileDirItem) + val listItem = getListItemFromFile(file, isSortingBySize, lastModifieds, false) + if (listItem != null) { + if (isProperMimeType(wantedMimeType, file.absolutePath, file.isDirectory)) { + items.add(listItem) } } } @@ -241,7 +230,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF } } - private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap, getProperChildCount: Boolean): ListItem? { + private fun getListItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap, getProperChildCount: Boolean): ListItem? { val curPath = file.absolutePath val curName = file.name if (!showHidden && curName.startsWith(".")) { @@ -272,7 +261,9 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF val listItems = ArrayList() fileDirItems.forEach { val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false, false) - listItems.add(listItem) + if (isProperMimeType(wantedMimeType, it.path, it.isDirectory)) { + listItems.add(listItem) + } } return listItems } @@ -374,7 +365,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF if (it.isDirectory) { if (it.name.contains(text, true)) { - val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, HashMap(), false) + val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false) if (fileDirItem != null) { files.add(fileDirItem) } @@ -383,7 +374,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF files.addAll(searchFiles(text, it.absolutePath)) } else { if (it.name.contains(text, true)) { - val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, HashMap(), false) + val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap(), false) if (fileDirItem != null) { files.add(fileDirItem) } diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt index 910f6775..9fb4c21b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt @@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.pro.fragments import android.content.Context import android.util.AttributeSet import android.widget.RelativeLayout +import com.simplemobiletools.commons.extensions.getMimeType import com.simplemobiletools.commons.extensions.isAudioFast import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST @@ -19,7 +20,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) var isGetContentIntent = false var isGetRingtonePicker = false var isPickMultipleIntent = false - var getContentMimeType = "" + var wantedMimeType = "" protected fun clickedPath(path: String) { if (isGetContentIntent) { @@ -35,6 +36,19 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet) } } + protected fun isProperMimeType(wantedMimeType: String, path: String, isDirectory: Boolean): Boolean { + return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) { + true + } else { + val fileMimeType = path.getMimeType() + if (wantedMimeType.endsWith("/*")) { + fileMimeType.substringBefore("/").equals(wantedMimeType.substringBefore("/"), true) + } else { + fileMimeType.equals(wantedMimeType, true) + } + } + } + abstract fun setupFragment(activity: SimpleActivity) abstract fun onResume(textColor: Int) diff --git a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt index 0d13d83e..8945e201 100644 --- a/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt @@ -146,7 +146,9 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000 val fileDirItem = ListItem(path, name, false, 0, size, modified, false, false) if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) { - listItems.add(fileDirItem) + if (isProperMimeType(wantedMimeType, path, false)) { + listItems.add(fileDirItem) + } } } while (cursor.moveToNext()) }