From 0136b557daa86d97cd041621fe9982127ca24508 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 15 Feb 2019 21:50:29 +0100 Subject: [PATCH] removing a few more functions related to special OTG file handling --- .../gallery/pro/activities/MainActivity.kt | 2 +- .../gallery/pro/adapters/DirectoryAdapter.kt | 43 +++++-------------- .../gallery/pro/extensions/Context.kt | 4 -- .../gallery/pro/helpers/MediaFetcher.kt | 18 ++------ 4 files changed, 15 insertions(+), 52 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt index 930b0fa6e..32493cdc1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/MainActivity.kt @@ -1034,7 +1034,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener { if (!File(it.path).exists()) { invalidDirs.add(it) } else if (it.path != config.tempFolderPath) { - val children = if (isPathOnOTG(it.path)) getOTGFolderChildrenNames(it.path) else File(it.path).list()?.asList() + val children = File(it.path).list()?.asList() val hasMediaFile = children?.any { it?.isMediaFile() == true } ?: false if (!hasMediaFile) { invalidDirs.add(it) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt index ee2e02594..cc8b1b52a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/adapters/DirectoryAdapter.kt @@ -320,20 +320,16 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList() val showHidden = activity.config.shouldShowHidden getSelectedPaths().forEach { - if (activity.isPathOnOTG(it)) { - paths.addAll(getOTGFilePaths(it, showHidden)) - } else if (it != FAVORITES) { - val filter = config.filterMedia - File(it).listFiles()?.filter { - !File(it.absolutePath).isDirectory && - it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) && - ((it.isImageFast() && filter and TYPE_IMAGES != 0) || - (it.isVideoFast() && filter and TYPE_VIDEOS != 0) || - (it.isGif() && filter and TYPE_GIFS != 0) || - (it.isRawFast() && filter and TYPE_RAWS != 0) || - (it.isSvg() && filter and TYPE_SVGS != 0)) - }?.mapTo(paths) { it.absolutePath } - } + val filter = config.filterMedia + File(it).listFiles()?.filter { + !File(it.absolutePath).isDirectory && + it.absolutePath.isMediaFile() && (showHidden || !it.name.startsWith('.')) && + ((it.isImageFast() && filter and TYPE_IMAGES != 0) || + (it.isVideoFast() && filter and TYPE_VIDEOS != 0) || + (it.isGif() && filter and TYPE_GIFS != 0) || + (it.isRawFast() && filter and TYPE_RAWS != 0) || + (it.isSvg() && filter and TYPE_SVGS != 0)) + }?.mapTo(paths) { it.absolutePath } } val fileDirItems = paths.map { FileDirItem(it, it.getFilenameFromPath()) } as ArrayList @@ -344,25 +340,6 @@ class DirectoryAdapter(activity: BaseSimpleActivity, var dirs: ArrayList { - val paths = ArrayList() - val filter = config.filterMedia - activity.getOTGFolderChildren(path)?.filter { it.name != null }?.forEach { - if (!it.isDirectory && - it.name!!.isMediaFile() && (showHidden || !it.name!!.startsWith('.')) && - ((it.name!!.isImageFast() && filter and TYPE_IMAGES != 0) || - (it.name!!.isVideoFast() && filter and TYPE_VIDEOS != 0) || - (it.name!!.isGif() && filter and TYPE_GIFS != 0) || - (it.name!!.isRawFast() && filter and TYPE_RAWS != 0) || - (it.name!!.isSvg() && filter and TYPE_SVGS != 0)) - ) { - val relativePath = it.uri.path.substringAfterLast("${activity.config.OTGPartition}:") - paths.add("${config.OTGPath}/$relativePath") - } - } - return paths - } - private fun askConfirmDelete() { when { config.isDeletePasswordProtectionOn -> activity.handleDeletePasswordProtection { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt index ff82c9b18..a7663f123 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/extensions/Context.kt @@ -594,10 +594,6 @@ fun Context.updateDBDirectory(directory: Directory, directoryDao: DirectoryDao) 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 }?.toMutableList() - fun Context.getFavoritePaths() = galleryDB.MediumDao().getFavoritePaths() as ArrayList // remove the "recycle_bin" from the file path prefix, replace it with real bin path /data/user... diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt index 84cebabbb..57c50e47b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/MediaFetcher.kt @@ -146,20 +146,10 @@ class MediaFetcher(val context: Context) { private fun addFolder(curFolders: ArrayList, folder: String) { curFolders.add(folder) - if (context.isPathOnOTG(folder)) { - val files = context.getOTGFolderChildren(folder) ?: return - for (file in files) { - if (file.isDirectory) { - val relativePath = file.uri.path.substringAfterLast("${context.config.OTGPartition}:") - addFolder(curFolders, "${context.config.OTGPath}/$relativePath") - } - } - } else { - val files = File(folder).listFiles() ?: return - for (file in files) { - if (file.isDirectory) { - addFolder(curFolders, file.absolutePath) - } + val files = File(folder).listFiles() ?: return + for (file in files) { + if (file.isDirectory) { + addFolder(curFolders, file.absolutePath) } } }