Skip to content

Commit f55727c

Browse files
committed
show only the wanted mime types at third party file picking intents
1 parent 61c4acc commit f55727c

File tree

4 files changed

+29
-22
lines changed

4 files changed

+29
-22
lines changed

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/activities/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class MainActivity : SimpleActivity() {
383383
it?.isGetRingtonePicker = isPickRingtoneIntent
384384
it?.isPickMultipleIntent = allowPickingMultipleIntent
385385
it?.isGetContentIntent = isGetContentIntent
386-
it?.getContentMimeType = getContentMimeType
386+
it?.wantedMimeType = getContentMimeType
387387
}
388388

389389
if (refreshRecents) {

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/ItemsFragment.kt

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -205,21 +205,10 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
205205
val lastModifieds = context!!.getFolderLastModifieds(path)
206206

207207
for (file in files) {
208-
val fileDirItem = getFileDirItemFromFile(file, isSortingBySize, lastModifieds, false)
209-
if (fileDirItem != null) {
210-
val mimetype = file.getMimeType()
211-
val isProperMimeType = if (getContentMimeType.isEmpty() || file.isDirectory) {
212-
true
213-
} else {
214-
if (getContentMimeType.endsWith("/*")) {
215-
mimetype.substringBefore("/").equals(getContentMimeType.substringBefore("/"), true)
216-
} else {
217-
mimetype.equals(getContentMimeType, true)
218-
}
219-
}
220-
221-
if (isProperMimeType) {
222-
items.add(fileDirItem)
208+
val listItem = getListItemFromFile(file, isSortingBySize, lastModifieds, false)
209+
if (listItem != null) {
210+
if (isProperMimeType(wantedMimeType, file.absolutePath, file.isDirectory)) {
211+
items.add(listItem)
223212
}
224213
}
225214
}
@@ -241,7 +230,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
241230
}
242231
}
243232

244-
private fun getFileDirItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap<String, Long>, getProperChildCount: Boolean): ListItem? {
233+
private fun getListItemFromFile(file: File, isSortingBySize: Boolean, lastModifieds: HashMap<String, Long>, getProperChildCount: Boolean): ListItem? {
245234
val curPath = file.absolutePath
246235
val curName = file.name
247236
if (!showHidden && curName.startsWith(".")) {
@@ -272,7 +261,9 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
272261
val listItems = ArrayList<ListItem>()
273262
fileDirItems.forEach {
274263
val listItem = ListItem(it.path, it.name, it.isDirectory, it.children, it.size, it.modified, false, false)
275-
listItems.add(listItem)
264+
if (isProperMimeType(wantedMimeType, it.path, it.isDirectory)) {
265+
listItems.add(listItem)
266+
}
276267
}
277268
return listItems
278269
}
@@ -374,7 +365,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
374365

375366
if (it.isDirectory) {
376367
if (it.name.contains(text, true)) {
377-
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false)
368+
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false)
378369
if (fileDirItem != null) {
379370
files.add(fileDirItem)
380371
}
@@ -383,7 +374,7 @@ class ItemsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF
383374
files.addAll(searchFiles(text, it.absolutePath))
384375
} else {
385376
if (it.name.contains(text, true)) {
386-
val fileDirItem = getFileDirItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false)
377+
val fileDirItem = getListItemFromFile(it, isSortingBySize, HashMap<String, Long>(), false)
387378
if (fileDirItem != null) {
388379
files.add(fileDirItem)
389380
}

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/MyViewPagerFragment.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.simplemobiletools.filemanager.pro.fragments
33
import android.content.Context
44
import android.util.AttributeSet
55
import android.widget.RelativeLayout
6+
import com.simplemobiletools.commons.extensions.getMimeType
67
import com.simplemobiletools.commons.extensions.isAudioFast
78
import com.simplemobiletools.commons.extensions.toast
89
import com.simplemobiletools.commons.helpers.VIEW_TYPE_LIST
@@ -19,7 +20,7 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
1920
var isGetContentIntent = false
2021
var isGetRingtonePicker = false
2122
var isPickMultipleIntent = false
22-
var getContentMimeType = ""
23+
var wantedMimeType = ""
2324

2425
protected fun clickedPath(path: String) {
2526
if (isGetContentIntent) {
@@ -35,6 +36,19 @@ abstract class MyViewPagerFragment(context: Context, attributeSet: AttributeSet)
3536
}
3637
}
3738

39+
protected fun isProperMimeType(wantedMimeType: String, path: String, isDirectory: Boolean): Boolean {
40+
return if (wantedMimeType.isEmpty() || wantedMimeType == "*/*" || isDirectory) {
41+
true
42+
} else {
43+
val fileMimeType = path.getMimeType()
44+
if (wantedMimeType.endsWith("/*")) {
45+
fileMimeType.substringBefore("/").equals(wantedMimeType.substringBefore("/"), true)
46+
} else {
47+
fileMimeType.equals(wantedMimeType, true)
48+
}
49+
}
50+
}
51+
3852
abstract fun setupFragment(activity: SimpleActivity)
3953

4054
abstract fun onResume(textColor: Int)

app/src/main/kotlin/com/simplemobiletools/filemanager/pro/fragments/RecentsFragment.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ class RecentsFragment(context: Context, attributeSet: AttributeSet) : MyViewPage
146146
val modified = cursor.getLongValue(FileColumns.DATE_MODIFIED) * 1000
147147
val fileDirItem = ListItem(path, name, false, 0, size, modified, false, false)
148148
if ((showHidden || !name.startsWith(".")) && activity?.getDoesFilePathExist(path) == true) {
149-
listItems.add(fileDirItem)
149+
if (isProperMimeType(wantedMimeType, path, false)) {
150+
listItems.add(fileDirItem)
151+
}
150152
}
151153
} while (cursor.moveToNext())
152154
}

0 commit comments

Comments
 (0)