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
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
|
||||||
|
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_IMAGES != 0 && it.types and TYPE_IMAGES != 0) ||
|
||||||
(filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) ||
|
(filterMedia and TYPE_VIDEOS != 0 && it.types and TYPE_VIDEOS != 0) ||
|
||||||
(filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0)
|
(filterMedia and TYPE_GIFS != 0 && it.types and TYPE_GIFS != 0)
|
||||||
} as ArrayList<Directory>
|
}
|
||||||
|
}) as ArrayList<Directory>
|
||||||
|
|
||||||
callback(filteredDirectories)
|
callback(filteredDirectories)
|
||||||
|
|
||||||
|
@ -266,7 +271,7 @@ 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>
|
||||||
|
@ -277,19 +282,21 @@ fun Context.getCachedMedia(path: String, callback: (ArrayList<Medium>) -> Unit)
|
||||||
}
|
}
|
||||||
|
|
||||||
val filterMedia = config.filterMedia
|
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_IMAGES != 0 && it.type == TYPE_IMAGES) ||
|
||||||
(filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) ||
|
(filterMedia and TYPE_VIDEOS != 0 && it.type == TYPE_VIDEOS) ||
|
||||||
(filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS)
|
(filterMedia and TYPE_GIFS != 0 && it.type == TYPE_GIFS)
|
||||||
} as ArrayList<Medium>
|
}
|
||||||
|
}) 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()
|
||||||
|
|
Loading…
Reference in a new issue