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 showHidden = config.shouldShowHidden
|
||||
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) {
|
||||
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
|
||||
|
||||
if (getProperDateTaken) {
|
||||
dateTaken = dateTakens.remove(filename) ?: lastModified
|
||||
dateTaken = dateTakens.remove(path) ?: lastModified
|
||||
}
|
||||
|
||||
val type = when {
|
||||
|
@ -390,6 +390,8 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
|
||||
private fun getFolderDateTakens(folder: String): HashMap<String, Long> {
|
||||
val dateTakens = HashMap<String, Long>()
|
||||
if (folder != FAVORITES) {
|
||||
val projection = arrayOf(
|
||||
MediaStore.Images.Media.DISPLAY_NAME,
|
||||
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 selectionArgs = arrayOf("$folder/%", "$folder/%/%")
|
||||
|
||||
val dateTakens = HashMap<String, Long>()
|
||||
val cursor = context.contentResolver.query(uri, projection, selection, selectionArgs, null)
|
||||
cursor?.use {
|
||||
if (cursor.moveToFirst()) {
|
||||
|
@ -408,16 +409,23 @@ class MediaFetcher(val context: Context) {
|
|||
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||
if (dateTaken != 0L) {
|
||||
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME)
|
||||
dateTakens[name] = dateTaken
|
||||
dateTakens["$folder/$name"] = dateTaken
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
context.dateTakensDB.getDateTakensFromPath(folder).forEach {
|
||||
dateTakens[it.filename] = it.taken
|
||||
val dateTakenValues = if (folder == FAVORITES) {
|
||||
context.dateTakensDB.getAllDateTakens()
|
||||
} else {
|
||||
context.dateTakensDB.getDateTakensFromPath(folder)
|
||||
}
|
||||
|
||||
dateTakenValues.forEach {
|
||||
dateTakens[it.fullPath] = it.taken
|
||||
}
|
||||
|
||||
return dateTakens
|
||||
|
@ -460,7 +468,6 @@ class MediaFetcher(val context: Context) {
|
|||
}
|
||||
|
||||
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 currentGrouping = context.config.getFolderGrouping(pathToCheck)
|
||||
if (currentGrouping and GROUP_BY_NONE != 0) {
|
||||
|
@ -473,6 +480,7 @@ class MediaFetcher(val context: Context) {
|
|||
return thumbnailItems
|
||||
}
|
||||
|
||||
val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
|
||||
media.forEach {
|
||||
val key = it.getGroupingKey(currentGrouping)
|
||||
if (!mediumGroups.containsKey(key)) {
|
||||
|
|
Loading…
Reference in a new issue