mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
remove some redundant code at gettig media by directories
This commit is contained in:
parent
75eb8c789a
commit
f6ee61a224
4 changed files with 3 additions and 28 deletions
|
@ -46,7 +46,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:3.18.14'
|
implementation 'com.simplemobiletools:commons:3.18.17'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.0'
|
||||||
implementation 'com.android.support:multidex:1.0.3'
|
implementation 'com.android.support:multidex:1.0.3'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -6,10 +6,10 @@ import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.OTG_PATH
|
import com.simplemobiletools.commons.helpers.OTG_PATH
|
||||||
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
|
||||||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||||
|
import com.simplemobiletools.commons.helpers.sumByLong
|
||||||
import com.simplemobiletools.gallery.R
|
import com.simplemobiletools.gallery.R
|
||||||
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
import com.simplemobiletools.gallery.extensions.checkAppendingHidden
|
||||||
import com.simplemobiletools.gallery.extensions.config
|
import com.simplemobiletools.gallery.extensions.config
|
||||||
import com.simplemobiletools.gallery.extensions.sumByLong
|
|
||||||
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
import com.simplemobiletools.gallery.helpers.MediaFetcher
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
import com.simplemobiletools.gallery.models.Medium
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
package com.simplemobiletools.gallery.extensions
|
|
||||||
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
fun <E> ArrayList<E>.sumByLong(selector: (E) -> Long) = map { selector(it) }.sum()
|
|
|
@ -12,8 +12,6 @@ import java.io.File
|
||||||
import java.util.LinkedHashMap
|
import java.util.LinkedHashMap
|
||||||
import kotlin.collections.ArrayList
|
import kotlin.collections.ArrayList
|
||||||
import kotlin.collections.HashSet
|
import kotlin.collections.HashSet
|
||||||
import kotlin.collections.component1
|
|
||||||
import kotlin.collections.component2
|
|
||||||
import kotlin.collections.set
|
import kotlin.collections.set
|
||||||
|
|
||||||
class MediaFetcher(val context: Context) {
|
class MediaFetcher(val context: Context) {
|
||||||
|
@ -21,25 +19,7 @@ class MediaFetcher(val context: Context) {
|
||||||
|
|
||||||
fun getMediaByDirectories(isPickVideo: Boolean, isPickImage: Boolean): HashMap<String, ArrayList<Medium>> {
|
fun getMediaByDirectories(isPickVideo: Boolean, isPickImage: Boolean): HashMap<String, ArrayList<Medium>> {
|
||||||
val media = getFilesFrom("", isPickImage, isPickVideo)
|
val media = getFilesFrom("", isPickImage, isPickVideo)
|
||||||
val excludedPaths = context.config.excludedFolders
|
return groupDirectories(media)
|
||||||
val includedPaths = context.config.includedFolders
|
|
||||||
val showHidden = context.config.shouldShowHidden
|
|
||||||
val directories = groupDirectories(media)
|
|
||||||
|
|
||||||
val removePaths = ArrayList<String>()
|
|
||||||
for ((path, curMedia) in directories) {
|
|
||||||
// make sure the path has uppercase letters wherever appropriate
|
|
||||||
val groupPath = File(curMedia.first().path).parent
|
|
||||||
if (!File(groupPath).exists() || !shouldFolderBeVisible(groupPath, excludedPaths, includedPaths, showHidden)) {
|
|
||||||
removePaths.add(groupPath.toLowerCase())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
removePaths.forEach {
|
|
||||||
directories.remove(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
return directories
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean): ArrayList<Medium> {
|
fun getFilesFrom(curPath: String, isPickImage: Boolean, isPickVideo: Boolean): ArrayList<Medium> {
|
||||||
|
|
Loading…
Reference in a new issue