properly show third party image, even if its not in mediastore

This commit is contained in:
tibbi 2017-09-01 11:14:00 +02:00
parent c04f887229
commit bc281dd102
5 changed files with 53 additions and 44 deletions

View file

@ -116,6 +116,7 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
config.isThirdPartyIntent = false
if (mStoredAnimateGifs != config.animateGifs) { if (mStoredAnimateGifs != config.animateGifs) {
directories_grid.adapter?.notifyDataSetChanged() directories_grid.adapter?.notifyDataSetChanged()
} }

View file

@ -105,11 +105,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
} }
} }
config.excludedFolders.map { "$it/" }.forEach { config.isThirdPartyIntent = true
if (mPath.startsWith(it)) {
config.temporarilyShowExcluded = true
}
}
} }
showSystemUI() showSystemUI()
@ -153,7 +149,11 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
if (intent.extras?.containsKey(IS_VIEW_INTENT) == true) { if (intent.extras?.containsKey(IS_VIEW_INTENT) == true) {
config.temporarilyShowHidden = false config.temporarilyShowHidden = false
} }
config.temporarilyShowExcluded = false
if (config.isThirdPartyIntent) {
mMedia.clear()
config.isThirdPartyIntent = false
}
} }
private fun setupOrientationEventListener() { private fun setupOrientationEventListener() {

View file

@ -16,7 +16,6 @@ import com.simplemobiletools.gallery.activities.SettingsActivity
import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.helpers.*
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import java.io.File import java.io.File
import java.util.*
val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT val Context.portrait get() = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT
val Context.audioManager get() = getSystemService(Context.AUDIO_SERVICE) as AudioManager 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 config = context.config
val filterMedia = config.filterMedia val filterMedia = config.filterMedia
val showHidden = config.shouldShowHidden val showHidden = config.shouldShowHidden
val showExcluded = config.temporarilyShowExcluded
val includedFolders = config.includedFolders.map { "$it/" } val includedFolders = config.includedFolders.map { "$it/" }
val excludedFolders = config.excludedFolders.map { "$it/" } val excludedFolders = config.excludedFolders.map { "$it/" }
val noMediaFolders = context.getNoMediaFolders() val noMediaFolders = context.getNoMediaFolders()
val isThirdPartyIntent = config.isThirdPartyIntent
cur.use { cur.use {
if (cur.moveToFirst()) { if (cur.moveToFirst()) {
@ -138,7 +137,7 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
isExcluded = true isExcluded = true
} }
if (!isExcluded || showExcluded) { if (!isExcluded || isThirdPartyIntent) {
val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN) val dateTaken = cur.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
val dateModified = cur.getIntValue(MediaStore.Images.Media.DATE_MODIFIED) * 1000L 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 { config.includedFolders.filter { it.isNotEmpty() && (curPath.isEmpty() || it == curPath) }.forEach {
for (file in it) { getMediaInFolder(it, curMedia, isPickImage, isPickVideo, filterMedia)
val size = file.length() }
if (size <= 0L) {
continue
}
val filename = file.name if (isThirdPartyIntent && curPath.isNotEmpty() && curMedia.isEmpty()) {
val isImage = filename.isImageFast() getMediaInFolder(curPath, curMedia, isPickImage, isPickVideo, filterMedia)
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)
}
} }
Medium.sorting = config.getFileSorting(curPath) Medium.sorting = config.getFileSorting(curPath)
@ -192,6 +165,41 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
return curMedia 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 { fun Context.getSortingForFolder(path: String): String {
val sorting = config.getFileSorting(path) val sorting = config.getFileSorting(path)
val sortValue = when { val sortValue = when {

View file

@ -54,9 +54,9 @@ class Config(context: Context) : BaseConfig(context) {
get() = prefs.getBoolean(TEMPORARILY_SHOW_HIDDEN, false) get() = prefs.getBoolean(TEMPORARILY_SHOW_HIDDEN, false)
set(temporarilyShowHidden) = prefs.edit().putBoolean(TEMPORARILY_SHOW_HIDDEN, temporarilyShowHidden).apply() set(temporarilyShowHidden) = prefs.edit().putBoolean(TEMPORARILY_SHOW_HIDDEN, temporarilyShowHidden).apply()
var temporarilyShowExcluded: Boolean var isThirdPartyIntent: Boolean
get() = prefs.getBoolean(TEMPORARILY_SHOW_EXCLUDED, false) get() = prefs.getBoolean(IS_THIRD_PARTY_INTENT, false)
set(temporarilyShowExcluded) = prefs.edit().putBoolean(TEMPORARILY_SHOW_EXCLUDED, temporarilyShowExcluded).apply() set(isThirdPartyIntent) = prefs.edit().putBoolean(IS_THIRD_PARTY_INTENT, isThirdPartyIntent).apply()
var pinnedFolders: Set<String> var pinnedFolders: Set<String>
get() = prefs.getStringSet(PINNED_FOLDERS, HashSet<String>()) get() = prefs.getStringSet(PINNED_FOLDERS, HashSet<String>())

View file

@ -6,7 +6,7 @@ val DIRECTORY_SORT_ORDER = "directory_sort_order"
val SORT_FOLDER_PREFIX = "sort_folder_" val SORT_FOLDER_PREFIX = "sort_folder_"
val SHOW_HIDDEN_MEDIA = "show_hidden_media" val SHOW_HIDDEN_MEDIA = "show_hidden_media"
val TEMPORARILY_SHOW_HIDDEN = "temporarily_show_hidden" 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 AUTOPLAY_VIDEOS = "autoplay_videos"
val LOOP_VIDEOS = "loop_videos" val LOOP_VIDEOS = "loop_videos"
val ANIMATE_GIFS = "animate_gifs" val ANIMATE_GIFS = "animate_gifs"