make sure only the appropriate media files are shown at third party intents

This commit is contained in:
tibbi 2018-04-22 22:01:05 +02:00
parent d0f4f0d403
commit 37c31f813b
3 changed files with 41 additions and 31 deletions

View file

@ -274,8 +274,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
}
mIsGettingDirs = true
val getImagesOnly = mIsPickImageIntent || mIsGetImageContentIntent
val getVideosOnly = mIsPickVideoIntent || mIsGetVideoContentIntent
if (!mLoadedInitialPhotos) {
getCachedDirectories {
getCachedDirectories(getVideosOnly, getImagesOnly) {
if (it.isNotEmpty()) {
gotDirectories(it, true)
}
@ -288,7 +291,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
mLoadedInitialPhotos = true
mCurrAsyncTask?.stopFetching()
mCurrAsyncTask = GetDirectoriesAsynctask(applicationContext, mIsPickVideoIntent || mIsGetVideoContentIntent, mIsPickImageIntent || mIsGetImageContentIntent) {
mCurrAsyncTask = GetDirectoriesAsynctask(applicationContext, getVideosOnly, getImagesOnly) {
mCurrAsyncTask = null
gotDirectories(addTempFolderIfNeeded(it), false)
}

View file

@ -456,7 +456,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
mIsGettingMedia = true
if (!mLoadedInitialPhotos) {
getCachedMedia(mPath) {
getCachedMedia(mPath, mIsGetVideoIntent, mIsGetImageIntent) {
if (it.isEmpty()) {
media_refresh_layout.isRefreshing = true
} else {

View file

@ -245,7 +245,7 @@ fun Context.loadJpg(path: String, target: MySquareImageView, cropThumbnails: Boo
builder.apply(options).transition(DrawableTransitionOptions.withCrossFade()).into(target)
}
fun Context.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
fun Context.getCachedDirectories(getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList<Directory>) -> Unit) {
Thread {
val directoryDao = galleryDB.DirectoryDao()
val directories = directoryDao.getAll() as ArrayList<Directory>
@ -254,11 +254,16 @@ fun Context.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
val includedPaths = config.includedFolders
var filteredDirectories = directories.filter { it.path.shouldFolderBeVisible(excludedPaths, includedPaths, shouldShowHidden) } as ArrayList<Directory>
val filterMedia = config.filterMedia
filteredDirectories = filteredDirectories.filter {
(filterMedia and TYPE_IMAGES != 0 && it.types and TYPE_IMAGES != 0) ||
(filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) ||
(filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0)
} as ArrayList<Directory>
filteredDirectories = (when {
getVideosOnly -> filteredDirectories.filter { it.types and TYPE_VIDEOS != 0 }
getImagesOnly -> filteredDirectories.filter { it.types and TYPE_IMAGES != 0 }
else -> filteredDirectories.filter {
(filterMedia and TYPE_IMAGES != 0 && it.types and TYPE_IMAGES != 0) ||
(filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) ||
(filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0)
}
}) as ArrayList<Directory>
callback(filteredDirectories)
@ -266,30 +271,32 @@ fun Context.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
}.start()
}
fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit) {
Thread {
val mediumDao = galleryDB.MediumDao()
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium>
val shouldShowHidden = config.shouldShowHidden
var filteredMedia = media
if (!shouldShowHidden) {
filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList<Medium>
}
fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImagesOnly: Boolean = false, callback: (ArrayList<Medium>) -> Unit) =
Thread {
val mediumDao = galleryDB.MediumDao()
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium>
val shouldShowHidden = config.shouldShowHidden
var filteredMedia = media
if (!shouldShowHidden) {
filteredMedia = media.filter { !it.name.startsWith('.') } as ArrayList<Medium>
}
val filterMedia = config.filterMedia
filteredMedia = filteredMedia.filter {
(filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) ||
(filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) ||
(filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS)
} as ArrayList<Medium>
val filterMedia = config.filterMedia
filteredMedia = (when {
getVideosOnly -> filteredMedia.filter { it.type == TYPE_VIDEOS }
getImagesOnly -> filteredMedia.filter { it.type == TYPE_IMAGES }
else -> filteredMedia.filter {
(filterMedia and TYPE_IMAGES != 0 && it.type == TYPE_IMAGES) ||
(filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) ||
(filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS)
}
}) as ArrayList<Medium>
callback(filteredMedia)
media.filter { !File(it.path).exists() }.forEach {
mediumDao.deleteMediumPath(it.path)
}
}.start()
}
callback(filteredMedia)
media.filter { !File(it.path).exists() }.forEach {
mediumDao.deleteMediumPath(it.path)
}
}.start()
fun Context.removeInvalidDirectories(dirs: ArrayList<Directory>? = null, directoryDao: DirectoryDao = galleryDB.DirectoryDao()) {
val dirsToCheck = dirs ?: directoryDao.getAll()