make sure the proper image is the directory thumbnail
This commit is contained in:
parent
7bf936339a
commit
6ad748d16a
4 changed files with 32 additions and 21 deletions
|
@ -11,6 +11,7 @@ import com.simplemobiletools.gallery.extensions.getLongValue
|
||||||
import com.simplemobiletools.gallery.extensions.getStringValue
|
import com.simplemobiletools.gallery.extensions.getStringValue
|
||||||
import com.simplemobiletools.gallery.helpers.*
|
import com.simplemobiletools.gallery.helpers.*
|
||||||
import com.simplemobiletools.gallery.models.Directory
|
import com.simplemobiletools.gallery.models.Directory
|
||||||
|
import com.simplemobiletools.gallery.models.Medium
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun doInBackground(vararg params: Void): ArrayList<Directory> {
|
override fun doInBackground(vararg params: Void): ArrayList<Directory> {
|
||||||
|
val media = ArrayList<Medium>()
|
||||||
val directories = LinkedHashMap<String, Directory>()
|
val directories = LinkedHashMap<String, Directory>()
|
||||||
val invalidFiles = ArrayList<File>()
|
val invalidFiles = ArrayList<File>()
|
||||||
val showMedia = mConfig.showMedia
|
val showMedia = mConfig.showMedia
|
||||||
|
@ -38,7 +40,8 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
|
|
||||||
uri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI
|
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()
|
val order = getSortOrder()
|
||||||
var cursor: Cursor? = null
|
var cursor: Cursor? = null
|
||||||
|
|
||||||
|
@ -56,7 +59,22 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
||||||
continue
|
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)) {
|
if (directories.containsKey(parentDir)) {
|
||||||
val directory: Directory = directories[parentDir]!!
|
val directory: Directory = directories[parentDir]!!
|
||||||
val newImageCnt = directory.mediaCnt + 1
|
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)}"
|
dirName += " ${context.resources.getString(R.string.hidden)}"
|
||||||
}
|
}
|
||||||
|
|
||||||
val dateModified = cursor.getLongValue(MediaStore.Images.Media.DATE_MODIFIED)
|
directories.put(parentDir, Directory(parentDir, path, dirName, 1, dateModified, dateTaken, size))
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
||||||
}
|
}
|
||||||
|
|
||||||
context.scanFiles(invalidFiles) {}
|
context.scanFiles(invalidFiles) {}
|
||||||
Medium.sorting = mConfig.sorting
|
Medium.sorting = mConfig.fileSorting
|
||||||
media.sort()
|
media.sort()
|
||||||
return media
|
return media
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
||||||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
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()
|
setupSortRadio()
|
||||||
setupOrderRadio()
|
setupOrderRadio()
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
||||||
if (isDirectorySorting) {
|
if (isDirectorySorting) {
|
||||||
config.directorySorting = sorting
|
config.directorySorting = sorting
|
||||||
} else {
|
} else {
|
||||||
config.sorting = sorting
|
config.fileSorting = sorting
|
||||||
}
|
}
|
||||||
callback.invoke()
|
callback.invoke()
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Config(context: Context) : BaseConfig(context) {
|
||||||
get() = mPrefs.getBoolean(IS_SAME_SORTING, true)
|
get() = mPrefs.getBoolean(IS_SAME_SORTING, true)
|
||||||
set(isSameSorting) = mPrefs.edit().putBoolean(IS_SAME_SORTING, isSameSorting).apply()
|
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)
|
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()
|
set(order) = if (isSameSorting) directorySorting = order else mPrefs.edit().putInt(SORT_ORDER, order).apply()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue