always sort FilePicker by name, folders first

This commit is contained in:
tibbi 2020-09-15 19:39:04 +02:00
parent b1c648fce0
commit fd9198b5b0
4 changed files with 13 additions and 14 deletions

View file

@ -6,8 +6,8 @@ buildscript {
propMinSdkVersion = 21
propTargetSdkVersion = propCompileSdkVersion
propVersionCode = 1
propVersionName = '5.30.2'
kotlin_version = '1.4.0'
propVersionName = '5.30.4'
kotlin_version = '1.4.10'
}
repositories {

View file

@ -128,7 +128,7 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
private fun tryUpdateItems() {
ensureBackgroundThread {
getItems(currPath, activity.baseConfig.getFolderSorting(currPath) and SORT_BY_SIZE != 0) {
getItems(currPath) {
activity.runOnUiThread {
updateItems(it as ArrayList<FileDirItem>)
}
@ -142,10 +142,9 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
return
}
FileDirItem.sorting = activity.baseConfig.getFolderSorting(currPath)
items.sort()
val sortedItems = items.sortedWith(compareBy({ !it.isDirectory }, { it.name.toLowerCase() }))
val adapter = FilepickerItemsAdapter(activity, items, mDialogView.filepicker_list) {
val adapter = FilepickerItemsAdapter(activity, sortedItems, mDialogView.filepicker_list) {
if ((it as FileDirItem).isDirectory) {
activity.handleLockedFolderOpening(it.path) { success ->
if (success) {
@ -166,7 +165,7 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
filepicker_list.adapter = adapter
filepicker_breadcrumbs.setBreadcrumb(currPath)
filepicker_fastscroller.setViews(filepicker_list) {
filepicker_fastscroller.updateBubbleText(items.getOrNull(it)?.getBubbleText(context, mDateFormat, mTimeFormat) ?: "")
filepicker_fastscroller.updateBubbleText(sortedItems.getOrNull(it)?.getBubbleText(context, mDateFormat, mTimeFormat) ?: "")
}
layoutManager.onRestoreInstanceState(mScrollStates[currPath.trimEnd('/')])
@ -203,15 +202,15 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
mDialog.dismiss()
}
private fun getItems(path: String, getProperFileSize: Boolean, callback: (List<FileDirItem>) -> Unit) {
private fun getItems(path: String, callback: (List<FileDirItem>) -> Unit) {
if (activity.isPathOnOTG(path)) {
activity.getOTGItems(path, showHidden, getProperFileSize, callback)
activity.getOTGItems(path, showHidden, callback)
} else {
getRegularItems(path, getProperFileSize, callback)
getRegularItems(path, callback)
}
}
private fun getRegularItems(path: String, getProperFileSize: Boolean, callback: (List<FileDirItem>) -> Unit) {
private fun getRegularItems(path: String, callback: (List<FileDirItem>) -> Unit) {
val items = ArrayList<FileDirItem>()
val base = File(path)
val files = base.listFiles()
@ -227,7 +226,7 @@ class FilePickerDialog(val activity: BaseSimpleActivity,
val curPath = file.absolutePath
val curName = curPath.getFilenameFromPath()
val size = if (getProperFileSize) file.getProperSize(showHidden) else file.length()
val size = file.length()
items.add(FileDirItem(curPath, curName, file.isDirectory, file.getDirectChildrenCount(showHidden), size, file.lastModified()))
}
callback(items)

View file

@ -348,7 +348,7 @@ fun Context.updateLastModified(path: String, lastModified: Long) {
}
}
fun Context.getOTGItems(path: String, shouldShowHidden: Boolean, getProperFileSize: Boolean, callback: (ArrayList<FileDirItem>) -> Unit) {
fun Context.getOTGItems(path: String, shouldShowHidden: Boolean, callback: (ArrayList<FileDirItem>) -> Unit) {
val items = ArrayList<FileDirItem>()
val OTGTreeUri = baseConfig.OTGTreeUri
var rootUri = try {
@ -395,7 +395,6 @@ fun Context.getOTGItems(path: String, shouldShowHidden: Boolean, getProperFileSi
val filePath = file.uri.toString().substring(basePath.length)
val decodedPath = otgPath + "/" + URLDecoder.decode(filePath, "UTF-8")
val fileSize = when {
getProperFileSize -> file.getItemSize(shouldShowHidden)
isDirectory -> 0L
else -> file.length()
}

View file

@ -337,6 +337,7 @@ fun isOreoPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
fun isOreoMr1Plus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1
fun isPiePlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P
fun isQPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q
fun isRPlus() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R
fun getDateFormats() = arrayListOf(
"--MM-dd",