mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 08:18:00 +01:00
make sure to exclude .nomedia folders at "Show all folders content"
This commit is contained in:
parent
9272fbc3a3
commit
8d3125ca17
1 changed files with 39 additions and 1 deletions
|
@ -13,6 +13,7 @@ import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
import com.simplemobiletools.gallery.activities.SettingsActivity
|
import com.simplemobiletools.gallery.activities.SettingsActivity
|
||||||
import com.simplemobiletools.gallery.helpers.Config
|
import com.simplemobiletools.gallery.helpers.Config
|
||||||
import com.simplemobiletools.gallery.helpers.IMAGES
|
import com.simplemobiletools.gallery.helpers.IMAGES
|
||||||
|
import com.simplemobiletools.gallery.helpers.NOMEDIA
|
||||||
import com.simplemobiletools.gallery.helpers.VIDEOS
|
import com.simplemobiletools.gallery.helpers.VIDEOS
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
@ -70,6 +71,7 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
|
||||||
var isImage: Boolean
|
var isImage: Boolean
|
||||||
var isVideo: Boolean
|
var isVideo: Boolean
|
||||||
val excludedFolders = config.excludedFolders
|
val excludedFolders = config.excludedFolders
|
||||||
|
val noMediaFolders = getNoMediaFolders()
|
||||||
|
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
|
@ -109,8 +111,17 @@ fun Context.getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!showHidden && path.contains("/."))
|
if (!isExcluded) {
|
||||||
|
noMediaFolders.forEach {
|
||||||
|
if (path.startsWith(it)) {
|
||||||
|
isExcluded = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isExcluded && !showHidden && path.contains("/.")) {
|
||||||
isExcluded = true
|
isExcluded = true
|
||||||
|
}
|
||||||
|
|
||||||
if (!isExcluded) {
|
if (!isExcluded) {
|
||||||
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
|
@ -150,3 +161,30 @@ fun Context.getSortingForFolder(path: String): String {
|
||||||
else
|
else
|
||||||
"$sortValue ASC"
|
"$sortValue ASC"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getNoMediaFolders(): ArrayList<String> {
|
||||||
|
val folders = ArrayList<String>()
|
||||||
|
val noMediaCondition = "${MediaStore.Files.FileColumns.MEDIA_TYPE} = ${MediaStore.Files.FileColumns.MEDIA_TYPE_NONE}"
|
||||||
|
|
||||||
|
val uri = MediaStore.Files.getContentUri("external")
|
||||||
|
val columns = arrayOf(MediaStore.Files.FileColumns.DATA)
|
||||||
|
val where = "$noMediaCondition AND ${MediaStore.Files.FileColumns.TITLE} LIKE ?"
|
||||||
|
val args = arrayOf("%$NOMEDIA%")
|
||||||
|
var cursor: Cursor? = null
|
||||||
|
|
||||||
|
try {
|
||||||
|
cursor = contentResolver.query(uri, columns, where, args, null)
|
||||||
|
if (cursor?.moveToFirst() == true) {
|
||||||
|
do {
|
||||||
|
val path = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)) ?: continue
|
||||||
|
val noMediaFile = File(path)
|
||||||
|
if (noMediaFile.exists())
|
||||||
|
folders.add(noMediaFile.parent)
|
||||||
|
} while (cursor.moveToNext())
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
cursor?.close()
|
||||||
|
}
|
||||||
|
|
||||||
|
return folders
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue