make sure the proper image is the directory thumbnail
This commit is contained in:
parent
7bf936339a
commit
6ad748d16a
|
@ -11,6 +11,7 @@ import com.simplemobiletools.gallery.extensions.getLongValue
|
|||
import com.simplemobiletools.gallery.extensions.getStringValue
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
|
||||
|
@ -24,6 +25,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
}
|
||||
|
||||
override fun doInBackground(vararg params: Void): ArrayList<Directory> {
|
||||
val media = ArrayList<Medium>()
|
||||
val directories = LinkedHashMap<String, Directory>()
|
||||
val invalidFiles = ArrayList<File>()
|
||||
val showMedia = mConfig.showMedia
|
||||
|
@ -38,7 +40,8 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
|
||||
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
||||
}
|
||||
val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_MODIFIED, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE)
|
||||
val columns = arrayOf(MediaStore.Images.Media.DATA, MediaStore.Images.Media.DISPLAY_NAME, MediaStore.Images.Media.DATE_MODIFIED,
|
||||
MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE)
|
||||
val order = getSortOrder()
|
||||
var cursor: Cursor? = null
|
||||
|
||||
|
@ -56,7 +59,22 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
continue
|
||||
}
|
||||
|
||||
val parentDir = file.parent
|
||||
val name = cursor.getStringValue(MediaStore.Images.Media.DISPLAY_NAME) ?: ""
|
||||
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
||||
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||
media.add(Medium(name, fullPath, i == 1, dateModified, dateTaken, size))
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
}
|
||||
|
||||
Medium.sorting = mConfig.fileSorting
|
||||
media.sort()
|
||||
|
||||
for ((name, path, isVideo, dateModified, dateTaken, size) in media) {
|
||||
val parentDir = File(path).parent
|
||||
if (directories.containsKey(parentDir)) {
|
||||
val directory: Directory = directories[parentDir]!!
|
||||
val newImageCnt = directory.mediaCnt + 1
|
||||
|
@ -68,14 +86,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
dirName += " ${context.resources.getString(R.string.hidden)}"
|
||||
}
|
||||
|
||||
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
||||
val dateTaken = cursor.getLongValue(MediaStore.Images.Media.DATE_TAKEN)
|
||||
directories.put(parentDir, Directory(parentDir, fullPath, dirName, 1, dateModified, dateTaken, size))
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
directories.put(parentDir, Directory(parentDir, path, dirName, 1, dateModified, dateTaken, size))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
|||
}
|
||||
|
||||
context.scanFiles(invalidFiles) {}
|
||||
Medium.sorting = mConfig.sorting
|
||||
Medium.sorting = mConfig.fileSorting
|
||||
media.sort()
|
||||
return media
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
|||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||
}
|
||||
|
||||
currSorting = if (isDirectorySorting) config.directorySorting else config.sorting
|
||||
currSorting = if (isDirectorySorting) config.directorySorting else config.fileSorting
|
||||
setupSortRadio()
|
||||
setupOrderRadio()
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
|||
if (isDirectorySorting) {
|
||||
config.directorySorting = sorting
|
||||
} else {
|
||||
config.sorting = sorting
|
||||
config.fileSorting = sorting
|
||||
}
|
||||
callback.invoke()
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = mPrefs.getBoolean(IS_SAME_SORTING, true)
|
||||
set(isSameSorting) = mPrefs.edit().putBoolean(IS_SAME_SORTING, isSameSorting).apply()
|
||||
|
||||
var sorting: Int
|
||||
var fileSorting: Int
|
||||
get() = if (isSameSorting) directorySorting else mPrefs.getInt(SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
|
||||
set(order) = if (isSameSorting) directorySorting = order else mPrefs.edit().putInt(SORT_ORDER, order).apply()
|
||||
|
||||
|
|
Loading…
Reference in New Issue