use "Fix Date Taken values" on Android 11+ file fetching

This commit is contained in:
tibbi 2022-05-03 10:14:18 +02:00
parent 5b03714ab7
commit b2130669ab
3 changed files with 17 additions and 10 deletions

View file

@ -77,7 +77,7 @@ android {
} }
dependencies { dependencies {
implementation 'com.github.SimpleMobileTools:Simple-Commons:e8ad6a9128' implementation 'com.github.SimpleMobileTools:Simple-Commons:b9178c4702'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0' implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.0'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'

View file

@ -929,7 +929,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
} }
} }
val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false) val android11Files = mLastMediaFetcher?.getAndroid11FolderMedia(getImagesOnly, getVideosOnly, favoritePaths, false, true, dateTakens)
try { try {
for (directory in dirs) { for (directory in dirs) {
if (mShouldStopFetching || isDestroyed || isFinishing) { if (mShouldStopFetching || isDestroyed || isFinishing) {

View file

@ -46,7 +46,7 @@ class MediaFetcher(val context: Context) {
if (android11Files?.containsKey(curPath.toLowerCase()) == true) { if (android11Files?.containsKey(curPath.toLowerCase()) == true) {
curMedia.addAll(android11Files[curPath.toLowerCase()]!!) curMedia.addAll(android11Files[curPath.toLowerCase()]!!)
} else if (android11Files == null) { } else if (android11Files == null) {
val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, false) val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, false, getProperDateTaken, dateTakens)
if (files.containsKey(curPath.toLowerCase())) { if (files.containsKey(curPath.toLowerCase())) {
curMedia.addAll(files[curPath.toLowerCase()]!!) curMedia.addAll(files[curPath.toLowerCase()]!!)
} }
@ -60,7 +60,8 @@ class MediaFetcher(val context: Context) {
) )
if (curPath == FAVORITES && isRPlus()) { if (curPath == FAVORITES && isRPlus()) {
val files = getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true) val files =
getAndroid11FolderMedia(isPickImage, isPickVideo, favoritePaths, true, getProperDateTaken, dateTakens.clone() as HashMap<String, Long>)
newMedia.forEach { newMedium -> newMedia.forEach { newMedium ->
for ((folder, media) in files) { for ((folder, media) in files) {
media.forEach { medium -> media.forEach { medium ->
@ -423,7 +424,9 @@ class MediaFetcher(val context: Context) {
isPickImage: Boolean, isPickImage: Boolean,
isPickVideo: Boolean, isPickVideo: Boolean,
favoritePaths: ArrayList<String>, favoritePaths: ArrayList<String>,
getFavoritePathsOnly: Boolean getFavoritePathsOnly: Boolean,
getProperDateTaken: Boolean,
dateTakens: HashMap<String, Long>
): HashMap<String, ArrayList<Medium>> { ): HashMap<String, ArrayList<Medium>> {
val media = HashMap<String, ArrayList<Medium>>() val media = HashMap<String, ArrayList<Medium>>()
if (!isRPlus()) { if (!isRPlus()) {
@ -458,11 +461,6 @@ class MediaFetcher(val context: Context) {
return@queryCursor return@queryCursor
} }
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
var dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
val size = cursor.getLongValue(Images.Media.SIZE)
val videoDuration = Math.round(cursor.getIntValue(MediaStore.MediaColumns.DURATION) / 1000.toDouble()).toInt()
val isPortrait = false val isPortrait = false
val isImage = path.isImageFast() val isImage = path.isImageFast()
val isVideo = if (isImage) false else path.isVideoFast() val isVideo = if (isImage) false else path.isVideoFast()
@ -492,6 +490,7 @@ class MediaFetcher(val context: Context) {
if (!showHidden && filename.startsWith('.')) if (!showHidden && filename.startsWith('.'))
return@queryCursor return@queryCursor
val size = cursor.getLongValue(Images.Media.SIZE)
if (size <= 0L) { if (size <= 0L) {
return@queryCursor return@queryCursor
} }
@ -505,10 +504,18 @@ class MediaFetcher(val context: Context) {
else -> TYPE_IMAGES else -> TYPE_IMAGES
} }
val lastModified = cursor.getLongValue(Images.Media.DATE_MODIFIED) * 1000
var dateTaken = cursor.getLongValue(Images.Media.DATE_TAKEN)
if (getProperDateTaken) {
dateTaken = dateTakens.remove(path) ?: lastModified
}
if (dateTaken == 0L) { if (dateTaken == 0L) {
dateTaken = lastModified dateTaken = lastModified
} }
val videoDuration = Math.round(cursor.getIntValue(MediaStore.MediaColumns.DURATION) / 1000.toDouble()).toInt()
val isFavorite = favoritePaths.contains(path) val isFavorite = favoritePaths.contains(path)
val medium = val medium =
Medium(null, filename, path, path.getParentPath(), lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L, mediaStoreId) Medium(null, filename, path, path.getParentPath(), lastModified, dateTaken, size, type, videoDuration, isFavorite, 0L, mediaStoreId)