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