sort the hidden folders by .nomedia last modified + fix threading

This commit is contained in:
tibbi 2017-12-29 18:17:33 +01:00
parent 865db7099f
commit cd03b455dc
2 changed files with 36 additions and 31 deletions

View File

@ -21,16 +21,19 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
private fun updateFolders() { private fun updateFolders() {
val folders = getNoMediaFolders() getNoMediaFolders {
manage_folders_placeholder.apply { runOnUiThread {
text = getString(R.string.hidden_folders_placeholder) manage_folders_placeholder.apply {
beVisibleIf(folders.isEmpty()) text = getString(R.string.hidden_folders_placeholder)
setTextColor(config.textColor) beVisibleIf(it.isEmpty())
} setTextColor(config.textColor)
}
val adapter = ManageHiddenFoldersAdapter(this, folders, this, manage_folders_list) {} val adapter = ManageHiddenFoldersAdapter(this, it, this, manage_folders_list) {}
adapter.setupDragListener(true) adapter.setupDragListener(true)
manage_folders_list.adapter = adapter manage_folders_list.adapter = adapter
}
}
} }
override fun onCreateOptionsMenu(menu: Menu?): Boolean { override fun onCreateOptionsMenu(menu: Menu?): Boolean {

View File

@ -79,31 +79,33 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
return movePinnedDirectoriesToFront(dirs) return movePinnedDirectoriesToFront(dirs)
} }
fun Context.getNoMediaFolders(): ArrayList<String> { fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
val folders = ArrayList<String>() Thread {
val folders = ArrayList<String>()
val uri = MediaStore.Files.getContentUri("external") val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(MediaStore.Files.FileColumns.DATA) val projection = arrayOf(MediaStore.Files.FileColumns.DATA)
val selection = "${MediaStore.Files.FileColumns.MEDIA_TYPE} = ? AND ${MediaStore.Files.FileColumns.TITLE} LIKE ?" val selection = "${MediaStore.Files.FileColumns.MEDIA_TYPE} = ? AND ${MediaStore.Files.FileColumns.TITLE} LIKE ?"
val selectionArgs = arrayOf(MediaStore.Files.FileColumns.MEDIA_TYPE_NONE.toString(), "%$NOMEDIA%") val selectionArgs = arrayOf(MediaStore.Files.FileColumns.MEDIA_TYPE_NONE.toString(), "%$NOMEDIA%")
val sortOrder = MediaStore.Files.FileColumns.DATA val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC"
var cursor: Cursor? = null var cursor: Cursor? = null
try { try {
cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder) cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
if (cursor?.moveToFirst() == true) { if (cursor?.moveToFirst() == true) {
do { do {
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA) ?: continue val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA) ?: continue
val noMediaFile = File(path) val noMediaFile = File(path)
if (noMediaFile.exists()) { if (noMediaFile.exists()) {
folders.add("${noMediaFile.parent}/") folders.add("${noMediaFile.parent}/")
} }
} while (cursor.moveToNext()) } while (cursor.moveToNext())
}
} finally {
cursor?.close()
} }
} finally {
cursor?.close()
}
return folders callback(folders)
}.start()
} }