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,17 +21,20 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener {
}
private fun updateFolders() {
val folders = getNoMediaFolders()
getNoMediaFolders {
runOnUiThread {
manage_folders_placeholder.apply {
text = getString(R.string.hidden_folders_placeholder)
beVisibleIf(folders.isEmpty())
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)
manage_folders_list.adapter = adapter
}
}
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu_add_folder, menu)

View File

@ -79,14 +79,15 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
return movePinnedDirectoriesToFront(dirs)
}
fun Context.getNoMediaFolders(): ArrayList<String> {
fun Context.getNoMediaFolders(callback: (folders: ArrayList<String>) -> Unit) {
Thread {
val folders = ArrayList<String>()
val uri = MediaStore.Files.getContentUri("external")
val projection = arrayOf(MediaStore.Files.FileColumns.DATA)
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 sortOrder = MediaStore.Files.FileColumns.DATA
val sortOrder = "${MediaStore.Files.FileColumns.DATE_MODIFIED} DESC"
var cursor: Cursor? = null
@ -105,5 +106,6 @@ fun Context.getNoMediaFolders(): ArrayList<String> {
cursor?.close()
}
return folders
callback(folders)
}.start()
}