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

View file

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

View file

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