From af6121ec6382c956041833c6be76fcaa74d10ddb Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 25 May 2018 11:11:28 +0200 Subject: [PATCH] removing an redundant argument --- .../gallery/activities/MainActivity.kt | 2 +- .../gallery/asynctasks/GetMediaAsynctask.kt | 2 +- .../gallery/helpers/MediaFetcher.kt | 33 +++++-------------- 3 files changed, 10 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt index 6e7add788..4a29e4996 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/MainActivity.kt @@ -628,7 +628,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener { } } - val foldersToScan = mediaFetcher.getFoldersToScan("") + val foldersToScan = mediaFetcher.getFoldersToScan() dirs.forEach { foldersToScan.remove(it.path) } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt index 7f92fcfb4..6a5dee554 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/asynctasks/GetMediaAsynctask.kt @@ -15,7 +15,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage override fun doInBackground(vararg params: Void): ArrayList { val sorting = context.config.getFileSorting(mPath) return if (showAll) { - val foldersToScan = mediaFetcher.getFoldersToScan("") + val foldersToScan = mediaFetcher.getFoldersToScan() val media = ArrayList() for (folder in foldersToScan) { val newMedia = mediaFetcher.getFilesFrom(folder, isPickImage, isPickVideo, sorting) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index d94654dd6..a2bfa6c5c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -35,28 +35,24 @@ class MediaFetcher(val context: Context) { return curMedia } - fun getFoldersToScan(path: String): ArrayList { + fun getFoldersToScan(): ArrayList { val filterMedia = context.config.filterMedia val projection = arrayOf(MediaStore.Images.Media.DATA) val uri = MediaStore.Files.getContentUri("external") - val selection = "${getSelectionQuery(path, filterMedia)} ${MediaStore.Images.ImageColumns.BUCKET_ID} IS NOT NULL) GROUP BY (${MediaStore.Images.ImageColumns.BUCKET_ID}" - val selectionArgs = getSelectionArgsQuery(path, filterMedia).toTypedArray() + val selection = "${getSelectionQuery(filterMedia)} ${MediaStore.Images.ImageColumns.BUCKET_ID} IS NOT NULL) GROUP BY (${MediaStore.Images.ImageColumns.BUCKET_ID}" + val selectionArgs = getSelectionArgsQuery(filterMedia).toTypedArray() return try { val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null) - parseCursor(cursor, path) + parseCursor(cursor) } catch (e: Exception) { ArrayList() } } - private fun getSelectionQuery(path: String, filterMedia: Int): String { + private fun getSelectionQuery(filterMedia: Int): String { val query = StringBuilder() - if (path.isNotEmpty()) { - query.append("${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ? AND ") - } - query.append("(") if (filterMedia and TYPE_IMAGES != 0) { photoExtensions.forEach { @@ -79,13 +75,8 @@ class MediaFetcher(val context: Context) { return selectionQuery } - private fun getSelectionArgsQuery(path: String, filterMedia: Int): ArrayList { + private fun getSelectionArgsQuery(filterMedia: Int): ArrayList { val args = ArrayList() - if (path.isNotEmpty()) { - args.add("$path/%") - args.add("$path/%/%") - } - if (filterMedia and TYPE_IMAGES != 0) { photoExtensions.forEach { args.add("%$it") @@ -105,7 +96,7 @@ class MediaFetcher(val context: Context) { return args } - private fun parseCursor(cursor: Cursor, curPath: String): ArrayList { + private fun parseCursor(cursor: Cursor): ArrayList { val config = context.config val includedFolders = config.includedFolders var foldersToScan = ArrayList() @@ -123,20 +114,12 @@ class MediaFetcher(val context: Context) { } includedFolders.forEach { - if (curPath.isEmpty()) { - addFolder(foldersToScan, it) - } else if (curPath == it) { - foldersToScan.add(it) - } + addFolder(foldersToScan, it) } val showHidden = config.shouldShowHidden val excludedFolders = config.excludedFolders foldersToScan = foldersToScan.filter { it.shouldFolderBeVisible(excludedFolders, includedFolders, showHidden) } as ArrayList - if (config.isThirdPartyIntent && curPath.isNotEmpty()) { - foldersToScan.add(curPath) - } - return foldersToScan.distinctBy { it.getDistinctPath() } as ArrayList }