make sure folder inclusion is recursive on OTG too

This commit is contained in:
tibbi 2018-04-26 13:59:24 +02:00
parent c0f600c451
commit a24050c98d
3 changed files with 20 additions and 7 deletions

View file

@ -760,7 +760,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
if (!getDoesFilePathExist(it.path)) { if (!getDoesFilePathExist(it.path)) {
invalidDirs.add(it) invalidDirs.add(it)
} else { } else {
val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildren(it.path) else File(it.path).list()?.asList() val children = if (it.path.startsWith(OTG_PATH)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList()
val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false val hasMediaFile = children?.any { it.isImageVideoGif() } ?: false
if (!hasMediaFile) { if (!hasMediaFile) {
invalidDirs.add(it) invalidDirs.add(it)
@ -777,8 +777,6 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
} }
} }
private fun getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()?.map { it.name }?.toList()
private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList() private fun getCurrentlyDisplayedDirs() = getRecyclerAdapter()?.dirs ?: ArrayList()
private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: "" private fun getBubbleTextItem(index: Int) = getRecyclerAdapter()?.dirs?.getOrNull(index)?.getBubbleText() ?: ""

View file

@ -326,3 +326,7 @@ fun Context.updateDBMediaPath(oldPath: String, newPath: String) {
fun Context.updateDBDirectory(directory: Directory) { fun Context.updateDBDirectory(directory: Directory) {
galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types) galleryDB.DirectoryDao().updateDirectory(directory.path, directory.tmb, directory.mediaCnt, directory.modified, directory.taken, directory.size, directory.types)
} }
fun Context.getOTGFolderChildren(path: String) = getDocumentFile(path)?.listFiles()
fun Context.getOTGFolderChildrenNames(path: String) = getOTGFolderChildren(path)?.map { it.name }?.toList()

View file

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.photoExtensions import com.simplemobiletools.commons.helpers.photoExtensions
import com.simplemobiletools.commons.helpers.videoExtensions import com.simplemobiletools.commons.helpers.videoExtensions
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getOTGFolderChildren
import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible import com.simplemobiletools.gallery.extensions.shouldFolderBeVisible
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import java.io.File import java.io.File
@ -143,6 +144,15 @@ class MediaFetcher(val context: Context) {
private fun addFolder(curFolders: ArrayList<String>, folder: String) { private fun addFolder(curFolders: ArrayList<String>, folder: String) {
curFolders.add(folder) curFolders.add(folder)
if (folder.startsWith(OTG_PATH)) {
val files = context.getOTGFolderChildren(folder) ?: return
for (file in files) {
if (file.isDirectory) {
val relativePath = file.uri.path.substringAfterLast("${context.config.OTGPartition}:")
addFolder(curFolders, "$OTG_PATH$relativePath")
}
}
} else {
val files = File(folder).listFiles() ?: return val files = File(folder).listFiles() ?: return
for (file in files) { for (file in files) {
if (file.isDirectory) { if (file.isDirectory) {
@ -150,6 +160,7 @@ class MediaFetcher(val context: Context) {
} }
} }
} }
}
private fun fetchFolderContent(path: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList<Medium> { private fun fetchFolderContent(path: String, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int): ArrayList<Medium> {
return if (path.startsWith(OTG_PATH)) { return if (path.startsWith(OTG_PATH)) {