rely on noMedia files from MediaStore on a couple more places

This commit is contained in:
tibbi 2020-10-28 21:01:51 +01:00
parent eb9ca5df77
commit 4ef159e912
5 changed files with 22 additions and 21 deletions

View File

@ -77,7 +77,7 @@ android {
}
dependencies {
implementation 'com.simplemobiletools:commons:5.31.8'
implementation 'com.simplemobiletools:commons:5.31.13'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.19'

View File

@ -23,7 +23,6 @@ import androidx.recyclerview.widget.RecyclerView
import com.simplemobiletools.commons.dialogs.ConfirmationDialog
import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog
import com.simplemobiletools.commons.dialogs.FilePickerDialog
import com.simplemobiletools.commons.dialogs.NewAppsIconsDialog
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.models.FileDirItem
@ -903,6 +902,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
val hiddenString = getString(R.string.hidden)
val albumCovers = config.parseAlbumCovers()
val includedFolders = config.includedFolders
val noMediaFolders = getNoMediaFoldersSync()
val tempFolderPath = config.tempFolderPath
val getProperFileSize = config.directorySorting and SORT_BY_SIZE != 0
val favoritePaths = getFavoritePaths()
@ -937,7 +937,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
directory
} else {
createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize)
createDirectoryFromMedia(directory.path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize, noMediaFolders)
}
// we are looping through the already displayed folders looking for changes, do not do anything if nothing changed
@ -1043,7 +1043,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
}
}
val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, getProperFileSize)
val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, getProperFileSize, noMediaFolders)
dirs.add(newDir)
setupAdapter(dirs)

View File

@ -305,7 +305,7 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList<Directo
val includedFolders = activity.config.includedFolders
val hidden = activity.getString(R.string.hidden)
dirs.forEach {
it.name = activity.checkAppendingHidden(it.path, hidden, includedFolders)
it.name = activity.checkAppendingHidden(it.path, hidden, includedFolders, ArrayList())
}
listener?.updateDirectories(dirs.toMutableList() as ArrayList)
activity.runOnUiThread {

View File

@ -374,9 +374,9 @@ fun Context.storeDirectoryItems(items: ArrayList<Directory>) {
}
}
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>): String {
fun Context.checkAppendingHidden(path: String, hidden: String, includedFolders: MutableSet<String>, noMediaFolders: ArrayList<String>): String {
val dirName = getFolderNameFromPath(path)
return if (path.doesThisOrParentHaveNoMedia() && !path.isThisOrParentIncluded(includedFolders)) {
return if (path.doesThisOrParentHaveNoMedia(noMediaFolders) && !path.isThisOrParentIncluded(includedFolders)) {
"$dirName $hidden"
} else {
dirName
@ -524,10 +524,10 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
val includedPaths = config.includedFolders
val noMediaFolders = getNoMediaFoldersSync()
val folderNomediaStatuses = HashMap<String, Boolean>()
val folderNoMediaStatuses = HashMap<String, Boolean>()
var filteredDirectories = directories.filter {
it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNomediaStatuses, noMediaFolders) { path, hasNoMedia ->
folderNomediaStatuses[path] = hasNoMedia
it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden, folderNoMediaStatuses, noMediaFolders) { path, hasNoMedia ->
folderNoMediaStatuses[path] = hasNoMedia
}
} as ArrayList<Directory>
val filterMedia = config.filterMedia
@ -547,7 +547,7 @@ fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly:
val hiddenString = resources.getString(R.string.hidden)
filteredDirectories.forEach {
it.name = if (it.path.doesThisOrParentHaveNoMedia() && !it.path.isThisOrParentIncluded(includedPaths)) {
it.name = if (it.path.doesThisOrParentHaveNoMedia(noMediaFolders) && !it.path.isThisOrParentIncluded(includedPaths)) {
"${it.name.removeSuffix(hiddenString).trim()} $hiddenString"
} else {
it.name.removeSuffix(hiddenString).trim()
@ -813,7 +813,7 @@ fun Context.addPathToDB(path: String) {
}
fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>, albumCovers: ArrayList<AlbumCover>, hiddenString: String,
includedFolders: MutableSet<String>, getProperFileSize: Boolean): Directory {
includedFolders: MutableSet<String>, getProperFileSize: Boolean, noMediaFolders: ArrayList<String>): Directory {
val OTGPath = config.OTGPath
val grouped = MediaFetcher(this).groupMedia(curMedia, path)
var thumbnail: String? = null
@ -837,7 +837,7 @@ fun Context.createDirectoryFromMedia(path: String, curMedia: ArrayList<Medium>,
val defaultMedium = Medium(0, "", "", "", 0L, 0L, 0L, 0, 0, false, 0L)
val firstItem = curMedia.firstOrNull() ?: defaultMedium
val lastItem = curMedia.lastOrNull() ?: defaultMedium
val dirName = checkAppendingHidden(path, hiddenString, includedFolders)
val dirName = checkAppendingHidden(path, hiddenString, includedFolders, noMediaFolders)
val lastModified = if (isSortingAscending) Math.min(firstItem.modified, lastItem.modified) else Math.max(firstItem.modified, lastItem.modified)
val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken)
val size = if (getProperFileSize) curMedia.sumByLong { it.size } else 0L
@ -879,6 +879,7 @@ fun Context.updateDirectoryPath(path: String) {
val hiddenString = getString(R.string.hidden)
val albumCovers = config.parseAlbumCovers()
val includedFolders = config.includedFolders
val noMediaFolders = getNoMediaFoldersSync()
val sorting = config.getFolderSorting(path)
val grouping = config.getFolderGrouping(path)
@ -899,7 +900,7 @@ fun Context.updateDirectoryPath(path: String) {
val favoritePaths = getFavoritePaths()
val curMedia = mediaFetcher.getFilesFrom(path, getImagesOnly, getVideosOnly, getProperDateTaken, getProperLastModified, getProperFileSize,
favoritePaths, false, lastModifieds, dateTakens)
val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize)
val directory = createDirectoryFromMedia(path, curMedia, albumCovers, hiddenString, includedFolders, getProperFileSize, noMediaFolders)
updateDBDirectory(directory)
}

View File

@ -11,7 +11,7 @@ fun String.isThisOrParentExcluded(excludedPaths: MutableSet<String>) = excludedP
// cache which folders contain .nomedia files to avoid checking them over and over again
fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>, showHidden: Boolean,
folderNomediaStatuses: HashMap<String, Boolean>, noMediaFolders: ArrayList<String> = ArrayList(),
folderNoMediaStatuses: HashMap<String, Boolean>, noMediaFolders: ArrayList<String> = ArrayList(),
callback: (path: String, hasNoMedia: Boolean) -> Unit): Boolean {
if (isEmpty()) {
return false
@ -55,8 +55,8 @@ fun String.shouldFolderBeVisible(excludedPaths: MutableSet<String>, includedPath
for (i in 0 until count { it == '/' } - 1) {
curPath = curPath.substringBeforeLast('/')
val pathToCheck = "$curPath/${NOMEDIA}"
if (folderNomediaStatuses.contains(pathToCheck)) {
if (folderNomediaStatuses[pathToCheck] == true) {
if (folderNoMediaStatuses.contains(pathToCheck)) {
if (folderNoMediaStatuses[pathToCheck] == true) {
containsNoMediaOrDot = true
break
}