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() {
super.onResume()
config.isThirdPartyIntent = false
if (mStoredAnimateGifs != config.animateGifs) {
directories_grid.adapter?.notifyDataSetChanged()
}

View file

@ -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() {

View file

@ -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,8 +151,23 @@ 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) {
config.includedFolders.filter { it.isNotEmpty() && (curPath.isEmpty() || it == curPath) }.forEach {
getMediaInFolder(it, curMedia, isPickImage, isPickVideo, filterMedia)
}
if (isThirdPartyIntent && curPath.isNotEmpty() && curMedia.isEmpty()) {
getMediaInFolder(curPath, curMedia, isPickImage, isPickVideo, filterMedia)
}
Medium.sorting = config.getFileSorting(curPath)
curMedia.sort()
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
@ -184,12 +198,6 @@ private fun parseCursor(context: Context, cur: Cursor, isPickImage: Boolean, isP
if (!isAlreadyAdded)
curMedia.add(medium)
}
}
Medium.sorting = config.getFileSorting(curPath)
curMedia.sort()
return curMedia
}
fun Context.getSortingForFolder(path: String): String {

View file

@ -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>())

View file

@ -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"