From 71a378d5bda1c9529cf2ebfb93dd95443a839317 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 26 Apr 2018 14:53:20 +0200 Subject: [PATCH] fix copying folders from OTG devices --- app/build.gradle | 2 +- .../gallery/adapters/DirectoryAdapter.kt | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b1ce3ff87..c17829920 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:3.19.20' + implementation 'com.simplemobiletools:commons:3.19.21' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt index 91d21b847..dc37d0e49 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/adapters/DirectoryAdapter.kt @@ -12,6 +12,7 @@ import com.simplemobiletools.commons.dialogs.ConfirmationDialog import com.simplemobiletools.commons.dialogs.PropertiesDialog import com.simplemobiletools.commons.dialogs.RenameItemDialog import com.simplemobiletools.commons.extensions.* +import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.models.FileDirItem import com.simplemobiletools.commons.views.FastScroller import com.simplemobiletools.commons.views.MyRecyclerView @@ -279,10 +280,14 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() selectedPositions.forEach { - val dir = File(dirs[it].path) - val childrenFiles = dir.listFiles()?.filter { !activity.getIsPathDirectory(it.absolutePath) && it.absolutePath.isImageVideoGif() }?.map { it.absolutePath } - ?: ArrayList() - paths.addAll(childrenFiles) + val childrenPaths = ArrayList() + val path = dirs[it].path + if (path.startsWith(OTG_PATH)) { + paths.addAll(getOTGFilePaths(path)) + } else { + File(path).list()?.filter { !activity.getIsPathDirectory(it) && it.isImageVideoGif() }?.mapTo(childrenPaths, { it }) + } + paths.addAll(childrenPaths) } val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList @@ -293,6 +298,17 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList { + val paths = ArrayList() + activity.getOTGFolderChildren(path)?.forEach { + if (!it.isDirectory && it.name.isImageVideoGif()) { + val relativePath = it.uri.path.substringAfterLast("${activity.config.OTGPartition}:") + paths.add("$OTG_PATH$relativePath") + } + } + return paths + } + private fun askConfirmDelete() { if (config.skipDeleteConfirmation) { deleteFiles()