mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
properly show third party image, even if its not in mediastore
This commit is contained in:
parent
c04f887229
commit
bc281dd102
5 changed files with 53 additions and 44 deletions
|
@ -116,6 +116,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
config.isThirdPartyIntent = false
|
||||
if (mStoredAnimateGifs != config.animateGifs) {
|
||||
directories_grid.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
@ -105,11 +105,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
}
|
||||
}
|
||||
|
||||
config.excludedFolders.map { "$it/" }.forEach {
|
||||
if (mPath.startsWith(it)) {
|
||||
config.temporarilyShowExcluded = true
|
||||
}
|
||||
}
|
||||
config.isThirdPartyIntent = true
|
||||
}
|
||||
|
||||
showSystemUI()
|
||||
|
@ -153,7 +149,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
|
|||
if (intent.extras?.containsKey(IS_VIEW_INTENT) == true) {
|
||||
config.temporarilyShowHidden = false
|
||||
}
|
||||
config.temporarilyShowExcluded = false
|
||||
|
||||
if (config.isThirdPartyIntent) {
|
||||
mMedia.clear()
|
||||
config.isThirdPartyIntent = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupOrientationEventListener() {
|
||||
|
|
|
@ -16,7 +16,6 @@ import com.simplemobiletools.gallery.activities.SettingsActivity
|
|||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||
val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
|
@ -72,10 +71,10 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
|
|||
val config = context.config
|
||||
val filterMedia = config.filterMedia
|
||||
val showHidden = config.shouldShowHidden
|
||||
val showExcluded = config.temporarilyShowExcluded
|
||||
val includedFolders = config.includedFolders.map { "$it/" }
|
||||
val excludedFolders = config.excludedFolders.map { "$it/" }
|
||||
val noMediaFolders = context.getNoMediaFolders()
|
||||
val isThirdPartyIntent = config.isThirdPartyIntent
|
||||
|
||||
cur.use {
|
||||
if (cur.moveToFirst()) {
|
||||
|
@ -138,7 +137,7 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
|
|||
isExcluded = true
|
||||
}
|
||||
|
||||
if (!isExcluded || showExcluded) {
|
||||
if (!isExcluded || isThirdPartyIntent) {
|
||||
val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||
val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L
|
||||
|
||||
|
@ -152,38 +151,12 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
|
|||
}
|
||||
}
|
||||
|
||||
config.includedFolders.filter { it.isNotEmpty() && (curPath.isEmpty() || it == curPath) }.mapNotNull { File(it).listFiles() }.forEach {
|
||||
for (file in it) {
|
||||
val size = file.length()
|
||||
if (size <= 0L) {
|
||||
continue
|
||||
}
|
||||
config.includedFolders.filter { it.isNotEmpty() && (curPath.isEmpty() || it == curPath) }.forEach {
|
||||
getMediaInFolder(it, curMedia, isPickImage, isPickVideo, filterMedia)
|
||||
}
|
||||
|
||||
val filename = file.name
|
||||
val isImage = filename.isImageFast()
|
||||
val isVideo = if (isImage) false else filename.isVideoFast()
|
||||
val isGif = if (isImage || isVideo) false else filename.isGif()
|
||||
|
||||
if (!isImage && !isVideo)
|
||||
continue
|
||||
|
||||
if (isVideo && (isPickImage || filterMedia and VIDEOS == 0))
|
||||
continue
|
||||
|
||||
if (isImage && (isPickVideo || filterMedia and IMAGES == 0))
|
||||
continue
|
||||
|
||||
if (isGif && filterMedia and GIFS == 0)
|
||||
continue
|
||||
|
||||
val dateTaken = file.lastModified()
|
||||
val dateModified = file.lastModified()
|
||||
|
||||
val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateTaken, size)
|
||||
val isAlreadyAdded = curMedia.any { it.path == file.absolutePath }
|
||||
if (!isAlreadyAdded)
|
||||
curMedia.add(medium)
|
||||
}
|
||||
if (isThirdPartyIntent && curPath.isNotEmpty() && curMedia.isEmpty()) {
|
||||
getMediaInFolder(curPath, curMedia, isPickImage, isPickVideo, filterMedia)
|
||||
}
|
||||
|
||||
Medium.sorting = config.getFileSorting(curPath)
|
||||
|
@ -192,6 +165,41 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
|
|||
return curMedia
|
||||
}
|
||||
|
||||
private fun getMediaInFolder(folder: String, curMedia: ArrayList<Medium>, isPickImage: Boolean, isPickVideo: Boolean, filterMedia: Int) {
|
||||
val files = File(folder).listFiles() ?: return
|
||||
for (file in files) {
|
||||
val size = file.length()
|
||||
if (size <= 0L) {
|
||||
continue
|
||||
}
|
||||
|
||||
val filename = file.name
|
||||
val isImage = filename.isImageFast()
|
||||
val isVideo = if (isImage) false else filename.isVideoFast()
|
||||
val isGif = if (isImage || isVideo) false else filename.isGif()
|
||||
|
||||
if (!isImage && !isVideo)
|
||||
continue
|
||||
|
||||
if (isVideo && (isPickImage || filterMedia and VIDEOS == 0))
|
||||
continue
|
||||
|
||||
if (isImage && (isPickVideo || filterMedia and IMAGES == 0))
|
||||
continue
|
||||
|
||||
if (isGif && filterMedia and GIFS == 0)
|
||||
continue
|
||||
|
||||
val dateTaken = file.lastModified()
|
||||
val dateModified = file.lastModified()
|
||||
|
||||
val medium = Medium(filename, file.absolutePath, isVideo, dateModified, dateTaken, size)
|
||||
val isAlreadyAdded = curMedia.any { it.path == file.absolutePath }
|
||||
if (!isAlreadyAdded)
|
||||
curMedia.add(medium)
|
||||
}
|
||||
}
|
||||
|
||||
fun Context.getSortingForFolder(path: String): String {
|
||||
val sorting = config.getFileSorting(path)
|
||||
val sortValue = when {
|
||||
|
|
|
@ -54,9 +54,9 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getBoolean(TEMPORARILY_SHOW_HIDDEN, false)
|
||||
set(temporarilyShowHidden) = prefs.edit().putBoolean(TEMPORARILY_SHOW_HIDDEN, temporarilyShowHidden).apply()
|
||||
|
||||
var temporarilyShowExcluded: Boolean
|
||||
get() = prefs.getBoolean(TEMPORARILY_SHOW_EXCLUDED, false)
|
||||
set(temporarilyShowExcluded) = prefs.edit().putBoolean(TEMPORARILY_SHOW_EXCLUDED, temporarilyShowExcluded).apply()
|
||||
var isThirdPartyIntent: Boolean
|
||||
get() = prefs.getBoolean(IS_THIRD_PARTY_INTENT, false)
|
||||
set(isThirdPartyIntent) = prefs.edit().putBoolean(IS_THIRD_PARTY_INTENT, isThirdPartyIntent).apply()
|
||||
|
||||
var pinnedFolders: Set<String>
|
||||
get() = prefs.getStringSet(PINNED_FOLDERS, HashSet<String>())
|
||||
|
|
|
@ -6,7 +6,7 @@ val DIRECTORY_SORT_ORDER = "directory_sort_order"
|
|||
val SORT_FOLDER_PREFIX = "sort_folder_"
|
||||
val SHOW_HIDDEN_MEDIA = "show_hidden_media"
|
||||
val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden"
|
||||
val TEMPORARILY_SHOW_EXCLUDED = "temporarily_show_excluded"
|
||||
val IS_THIRD_PARTY_INTENT = "is_third_party_intent"
|
||||
val AUTOPLAY_VIDEOS = "autoplay_videos"
|
||||
val LOOP_VIDEOS = "loop_videos"
|
||||
val ANIMATE_GIFS = "animate_gifs"
|
||||
|
|
Loading…
Reference in a new issue