fix #1545, properly sort Favorites by date taken
This commit is contained in:
parent
650a985a9c
commit
f4c02d1168
1 changed files with 34 additions and 26 deletions
|
@ -226,7 +226,7 @@ class MediaFetcher(val context: Context) {
|
||||||
val checkFileExistence = config.fileLoadingPriority == PRIORITY_VALIDITY
|
val checkFileExistence = config.fileLoadingPriority == PRIORITY_VALIDITY
|
||||||
val showHidden = config.shouldShowHidden
|
val showHidden = config.shouldShowHidden
|
||||||
val showPortraits = filterMedia and TYPE_PORTRAITS != 0
|
val showPortraits = filterMedia and TYPE_PORTRAITS != 0
|
||||||
val dateTakens = if (getProperDateTaken && folder != FAVORITES && !isRecycleBin) getFolderDateTakens(folder) else HashMap()
|
val dateTakens = if (getProperDateTaken && !isRecycleBin) getFolderDateTakens(folder) else HashMap()
|
||||||
|
|
||||||
val files = when (folder) {
|
val files = when (folder) {
|
||||||
FAVORITES -> favoritePaths.filter { showHidden || !it.contains("/.") }.map { File(it) }.toMutableList() as ArrayList<File>
|
FAVORITES -> favoritePaths.filter { showHidden || !it.contains("/.") }.map { File(it) }.toMutableList() as ArrayList<File>
|
||||||
|
@ -302,7 +302,7 @@ class MediaFetcher(val context: Context) {
|
||||||
val videoDuration = if (getVideoDurations && isVideo) path.getVideoDuration() else 0
|
val videoDuration = if (getVideoDurations && isVideo) path.getVideoDuration() else 0
|
||||||
|
|
||||||
if (getProperDateTaken) {
|
if (getProperDateTaken) {
|
||||||
dateTaken = dateTakens.remove(filename) ?: lastModified
|
dateTaken = dateTakens.remove(path) ?: lastModified
|
||||||
}
|
}
|
||||||
|
|
||||||
val type = when {
|
val type = when {
|
||||||
|
@ -390,6 +390,8 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFolderDateTakens(folder: String): HashMap<String, Long> {
|
private fun getFolderDateTakens(folder: String): HashMap<String, Long> {
|
||||||
|
val dateTakens = HashMap<String, Long>()
|
||||||
|
if (folder != FAVORITES) {
|
||||||
val projection = arrayOf(
|
val projection = arrayOf(
|
||||||
MediaStore.Images.Media.DISPLAY_NAME,
|
MediaStore.Images.Media.DISPLAY_NAME,
|
||||||
MediaStore.Images.Media.DATE_TAKEN
|
MediaStore.Images.Media.DATE_TAKEN
|
||||||
|
@ -399,7 +401,6 @@ class MediaFetcher(val context: Context) {
|
||||||
val selection = "${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?"
|
val selection = "${MediaStore.Images.Media.DATA} LIKE ? AND ${MediaStore.Images.Media.DATA} NOT LIKE ?"
|
||||||
val selectionArgs = arrayOf("$folder/%", "$folder/%/%")
|
val selectionArgs = arrayOf("$folder/%", "$folder/%/%")
|
||||||
|
|
||||||
val dateTakens = HashMap<String, Long>()
|
|
||||||
val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||||
cursor?.use {
|
cursor?.use {
|
||||||
if (cursor.moveToFirst()) {
|
if (cursor.moveToFirst()) {
|
||||||
|
@ -408,16 +409,23 @@ class MediaFetcher(val context: Context) {
|
||||||
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||||
if (dateTaken != 0L) {
|
if (dateTaken != 0L) {
|
||||||
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)
|
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)
|
||||||
dateTakens[name] = dateTaken
|
dateTakens["$folder/$name"] = dateTaken
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext())
|
} while (cursor.moveToNext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context.dateTakensDB.getDateTakensFromPath(folder).forEach {
|
val dateTakenValues = if (folder == FAVORITES) {
|
||||||
dateTakens[it.filename] = it.taken
|
context.dateTakensDB.getAllDateTakens()
|
||||||
|
} else {
|
||||||
|
context.dateTakensDB.getDateTakensFromPath(folder)
|
||||||
|
}
|
||||||
|
|
||||||
|
dateTakenValues.forEach {
|
||||||
|
dateTakens[it.fullPath] = it.taken
|
||||||
}
|
}
|
||||||
|
|
||||||
return dateTakens
|
return dateTakens
|
||||||
|
@ -460,7 +468,6 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun groupMedia(media: ArrayList<Medium>, path: String): ArrayList<ThumbnailItem> {
|
fun groupMedia(media: ArrayList<Medium>, path: String): ArrayList<ThumbnailItem> {
|
||||||
val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
|
|
||||||
val pathToCheck = if (path.isEmpty()) SHOW_ALL else path
|
val pathToCheck = if (path.isEmpty()) SHOW_ALL else path
|
||||||
val currentGrouping = context.config.getFolderGrouping(pathToCheck)
|
val currentGrouping = context.config.getFolderGrouping(pathToCheck)
|
||||||
if (currentGrouping and GROUP_BY_NONE != 0) {
|
if (currentGrouping and GROUP_BY_NONE != 0) {
|
||||||
|
@ -473,6 +480,7 @@ class MediaFetcher(val context: Context) {
|
||||||
return thumbnailItems
|
return thumbnailItems
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
|
||||||
media.forEach {
|
media.forEach {
|
||||||
val key = it.getGroupingKey(currentGrouping)
|
val key = it.getGroupingKey(currentGrouping)
|
||||||
if (!mediumGroups.containsKey(key)) {
|
if (!mediumGroups.containsKey(key)) {
|
||||||
|
|
Loading…
Reference in a new issue