formatting GetMediaAsyncTask code, no real change

This commit is contained in:
tibbi 2023-02-05 16:28:17 +01:00
parent 2a94e9b811
commit 90a528fcd4
1 changed files with 21 additions and 13 deletions

View File

@ -2,17 +2,21 @@ package com.simplemobiletools.gallery.pro.asynctasks
import android.content.Context
import android.os.AsyncTask
import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.commons.helpers.FAVORITES
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
import com.simplemobiletools.gallery.pro.extensions.config
import com.simplemobiletools.gallery.pro.extensions.getFavoritePaths
import com.simplemobiletools.gallery.pro.helpers.*
import com.simplemobiletools.gallery.pro.models.Medium
import com.simplemobiletools.gallery.pro.models.ThumbnailItem
import java.util.*
class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage: Boolean = false, val isPickVideo: Boolean = false,
val showAll: Boolean, val callback: (media: ArrayList<ThumbnailItem>) -> Unit) :
AsyncTask<Void, Void, ArrayList<ThumbnailItem>>() {
class GetMediaAsynctask(
val context: Context, val mPath: String, val isPickImage: Boolean = false, val isPickVideo: Boolean = false,
val showAll: Boolean, val callback: (media: ArrayList<ThumbnailItem>) -> Unit
) :
AsyncTask<Void, Void, ArrayList<ThumbnailItem>>() {
private val mediaFetcher = MediaFetcher(context)
override fun doInBackground(vararg params: Void): ArrayList<ThumbnailItem> {
@ -20,12 +24,12 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
val folderGrouping = context.config.getFolderGrouping(pathToUse)
val folderSorting = context.config.getFolderSorting(pathToUse)
val getProperDateTaken = folderSorting and SORT_BY_DATE_TAKEN != 0 ||
folderGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 ||
folderGrouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0
folderGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 ||
folderGrouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0
val getProperLastModified = folderSorting and SORT_BY_DATE_MODIFIED != 0 ||
folderGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
folderGrouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
folderGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 ||
folderGrouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0
val getProperFileSize = folderSorting and SORT_BY_SIZE != 0
val favoritePaths = context.getFavoritePaths()
@ -37,16 +41,20 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
val foldersToScan = mediaFetcher.getFoldersToScan().filter { it != RECYCLE_BIN && it != FAVORITES && !context.config.isFolderProtected(it) }
val media = ArrayList<Medium>()
foldersToScan.forEach {
val newMedia = mediaFetcher.getFilesFrom(it, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize,
favoritePaths, getVideoDurations, lastModifieds, dateTakens.clone() as HashMap<String, Long>, null)
val newMedia = mediaFetcher.getFilesFrom(
it, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize,
favoritePaths, getVideoDurations, lastModifieds, dateTakens.clone() as HashMap<String, Long>, null
)
media.addAll(newMedia)
}
mediaFetcher.sortMedia(media, context.config.getFolderSorting(SHOW_ALL))
media
} else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths,
getVideoDurations, lastModifieds, dateTakens, null)
mediaFetcher.getFilesFrom(
mPath, isPickImage, isPickVideo, getProperDateTaken, getProperLastModified, getProperFileSize, favoritePaths,
getVideoDurations, lastModifieds, dateTakens, null
)
}
return mediaFetcher.groupMedia(media, pathToUse)