mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-30 00:17:58 +01:00
make sure only the appropriate media files are shown at third party intents
This commit is contained in:
parent
d0f4f0d403
commit
37c31f813b
3 changed files with 41 additions and 31 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
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>
|
||||
}
|
||||
}) as ArrayList<Directory>
|
||||
|
||||
callback(filteredDirectories)
|
||||
|
||||
|
@ -266,7 +271,7 @@ fun Context.getCachedDirectories(callback: (ArrayList<Directory>) -> Unit) {
|
|||
}.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 {
|
||||
val mediumDao = galleryDB.MediumDao()
|
||||
val media = mediumDao.getMediaFromPath(path) as ArrayList<Medium>
|
||||
|
@ -277,19 +282,21 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
|
|||
}
|
||||
|
||||
val filterMedia = config.filterMedia
|
||||
filteredMedia = filteredMedia.filter {
|
||||
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>
|
||||
}
|
||||
}) as ArrayList<Medium>
|
||||
|
||||
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()
|
||||
|
|
Loading…
Reference in a new issue