show only the wanted mime types at third party file picking intents

This commit is contained in:
tibbi 2022-07-03 11:39:22 +02:00
parent 61c4acc18b
commit f55727c4b3
4 changed files with 29 additions and 22 deletions

View File

@ -383,7 +383,7 @@ class MainActivity : SimpleActivity() {
it?.isGetRingtonePicker = isPickRingtoneIntent it?.isGetRingtonePicker = isPickRingtoneIntent
it?.isPickMultipleIntent = allowPickingMultipleIntent it?.isPickMultipleIntent = allowPickingMultipleIntent
it?.isGetContentIntent = isGetContentIntent it?.isGetContentIntent = isGetContentIntent
it?.getContentMimeType = getContentMimeType it?.wantedMimeType = getContentMimeType
} }
if (refreshRecents) { if (refreshRecents) {

View File

@ -205,21 +205,10 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
val lastModifieds = context!!.getFolderLastModifieds(path) val lastModifieds = context!!.getFolderLastModifieds(path)
for (file in files) { for (file in files) {
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false) val listItem = getListItemFromFile(file, isSortingBySize, lastModifieds, false)
if (fileDirItem != null) { if (listItem != null) {
val mimetype = file.getMimeType() if (isProperMimeType(wantedMimeType, file.absolutePath, file.isDirectory)) {
val isProperMimeType = if (getContentMimeType.isEmpty() || file.isDirectory) { items.add(listItem)
true
} else {
if (getContentMimeType.endsWith("/*")) {
mimetype.substringBefore("/").equals(getContentMimeType.substringBefore("/"), true)
} else {
mimetype.equals(getContentMimeType, true)
}
}
if (isProperMimeType) {
items.add(fileDirItem)
} }
} }
} }
@ -241,7 +230,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
} }
} }
private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap<String, Long>, getProperChildCount: Boolean): ListItem? { private fun getListItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap<String, Long>, getProperChildCount: Boolean): ListItem? {
val curPath = file.absolutePath val curPath = file.absolutePath
val curName = file.name val curName = file.name
if (!showHidden && curName.startsWith(".")) { if (!showHidden && curName.startsWith(".")) {
@ -272,7 +261,9 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
val listItems = ArrayList<ListItem>() val listItems = ArrayList<ListItem>()
fileDirItems.forEach { fileDirItems.forEach {
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false, false) 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 return listItems
} }
@ -374,7 +365,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
if (it.isDirectory) { if (it.isDirectory) {
if (it.name.contains(text, true)) { if (it.name.contains(text, true)) {
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false) val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false)
if (fileDirItem != null) { if (fileDirItem != null) {
files.add(fileDirItem) files.add(fileDirItem)
} }
@ -383,7 +374,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
files.addAll(searchFiles(text, it.absolutePath)) files.addAll(searchFiles(text, it.absolutePath))
} else { } else {
if (it.name.contains(text, true)) { if (it.name.contains(text, true)) {
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false) val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false)
if (fileDirItem != null) { if (fileDirItem != null) {
files.add(fileDirItem) files.add(fileDirItem)
} }

View File

@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.pro.fragments
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.widget.RelativeLayout import android.widget.RelativeLayout
import com.simplemobiletools.commons.extensions.getMimeType
import com.simplemobiletools.commons.extensions.isAudioFast import com.simplemobiletools.commons.extensions.isAudioFast
import com.simplemobiletools.commons.extensions.toast import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
@ -19,7 +20,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
var isGetContentIntent = false var isGetContentIntent = false
var isGetRingtonePicker = false var isGetRingtonePicker = false
var isPickMultipleIntent = false var isPickMultipleIntent = false
var getContentMimeType = "" var wantedMimeType = ""
protected fun clickedPath(path: String) { protected fun clickedPath(path: String) {
if (isGetContentIntent) { 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 setupFragment(activity: SimpleActivity)
abstract fun onResume(textColor: Int) abstract fun onResume(textColor: Int)

View File

@ -146,7 +146,9 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000 val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000
val fileDirItem = ListItem(path, name, false, 0, size, modified, false, false) val fileDirItem = ListItem(path, name, false, 0, size, modified, false, false)
if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) { if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) {
listItems.add(fileDirItem) if (isProperMimeType(wantedMimeType, path, false)) {
listItems.add(fileDirItem)
}
} }
} while (cursor.moveToNext()) } while (cursor.moveToNext())
} }