Handle EXTRA_MIME_TYPES in get content intents

This commit is contained in:
Ensar Sarajčić 2023-08-24 16:00:39 +02:00
parent c9585bbe63
commit a3036b1b39
4 changed files with 15 additions and 5 deletions

View File

@ -30,11 +30,21 @@ class ViewPagerAdapter(val activity: SimpleActivity, val tabsToShow: ArrayList<I
} else {
""
}
val passedExtraMimeTypes = activity.intent.getStringArrayExtra(Intent.EXTRA_MIME_TYPES)
val extraMimeTypes = if (isGetContentIntent && passedExtraMimeTypes != null) {
passedExtraMimeTypes
} else {
null
}
this.isGetRingtonePicker = isPickRingtoneIntent
this.isPickMultipleIntent = allowPickingMultipleIntent
this.isGetContentIntent = isGetContentIntent
this.wantedMimeType = getContentMimeType
if (extraMimeTypes != null) {
this.wantedMimeTypes = extraMimeTypes.toList()
} else {
this.wantedMimeTypes = listOf(getContentMimeType)
}
this.updateIsCreateDocumentIntent(isCreateDocumentIntent)
setupFragment(activity)

View File

@ -225,7 +225,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
for (file in files) {
val listItem = getListItemFromFile(file, isSortingBySize, lastModifieds, false)
if (listItem != null) {
if (isProperMimeType(wantedMimeType, file.absolutePath, file.isDirectory)) {
if (wantedMimeTypes.any { isProperMimeType(it, file.absolutePath, file.isDirectory) }) {
items.add(listItem)
}
}
@ -279,7 +279,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
val listItems = ArrayList<ListItem>()
fileDirItems.forEach {
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false, false)
if (isProperMimeType(wantedMimeType, it.path, it.isDirectory)) {
if (wantedMimeTypes.any { mimeType -> isProperMimeType(mimeType, it.path, it.isDirectory) }) {
listItems.add(listItem)
}
}

View File

@ -26,7 +26,7 @@ abstract class MyViewPagerFragment<BINDING : MyViewPagerFragment.InnerBinding>(c
var isGetContentIntent = false
var isGetRingtonePicker = false
var isPickMultipleIntent = false
var wantedMimeType = ""
var wantedMimeTypes = listOf("")
protected var isCreateDocumentIntent = false
protected lateinit var innerBinding: BINDING

View File

@ -179,7 +179,7 @@ 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) {
if (isProperMimeType(wantedMimeType, path, false)) {
if (wantedMimeTypes.any { isProperMimeType(it, path, false) }) {
listItems.add(fileDirItem)
}
}