mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
sort the hidden folders by .nomedia last modified + fix threading
This commit is contained in:
parent
865db7099f
commit
cd03b455dc
2 changed files with 36 additions and 31 deletions
|
@ -21,16 +21,19 @@ class HiddenFoldersActivity : SimpleActivity(), RefreshRecyclerViewListener {
|
|||
}
|
||||
|
||||
private fun updateFolders() {
|
||||
val folders = getNoMediaFolders()
|
||||
manage_folders_placeholder.apply {
|
||||
text = getString(R.string.hidden_folders_placeholder)
|
||||
beVisibleIf(folders.isEmpty())
|
||||
setTextColor(config.textColor)
|
||||
}
|
||||
getNoMediaFolders {
|
||||
runOnUiThread {
|
||||
manage_folders_placeholder.apply {
|
||||
text = getString(R.string.hidden_folders_placeholder)
|
||||
beVisibleIf(it.isEmpty())
|
||||
setTextColor(config.textColor)
|
||||
}
|
||||
|
||||
val adapter = ManageHiddenFoldersAdapter(this, folders, this, manage_folders_list) {}
|
||||
adapter.setupDragListener(true)
|
||||
manage_folders_list.adapter = adapter
|
||||
val adapter = ManageHiddenFoldersAdapter(this, it, this, manage_folders_list) {}
|
||||
adapter.setupDragListener(true)
|
||||
manage_folders_list.adapter = adapter
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
|
|
|
@ -79,31 +79,33 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
|
|||
return movePinnedDirectoriesToFront(dirs)
|
||||
}
|
||||
|
||||
fun Context.getNoMediaFolders(): ArrayList<String> {
|
||||
val folders = 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 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.DATE_MODIFIED} DESC"
|
||||
|
||||
var cursor: Cursor? = null
|
||||
var cursor: Cursor? = null
|
||||
|
||||
try {
|
||||
cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA) ?: continue
|
||||
val noMediaFile = File(path)
|
||||
if (noMediaFile.exists()) {
|
||||
folders.add("${noMediaFile.parent}/")
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
try {
|
||||
cursor = contentResolver.query(uri, projection, selection, selectionArgs, sortOrder)
|
||||
if (cursor?.moveToFirst() == true) {
|
||||
do {
|
||||
val path = cursor.getStringValue(MediaStore.Files.FileColumns.DATA) ?: continue
|
||||
val noMediaFile = File(path)
|
||||
if (noMediaFile.exists()) {
|
||||
folders.add("${noMediaFile.parent}/")
|
||||
}
|
||||
} while (cursor.moveToNext())
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
} finally {
|
||||
cursor?.close()
|
||||
}
|
||||
|
||||
return folders
|
||||
callback(folders)
|
||||
}.start()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue