mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
unify the directories funnel through which they are sorted, filtered etc
This commit is contained in:
parent
d654eca1f2
commit
a0798bcd29
1 changed files with 19 additions and 35 deletions
|
@ -313,7 +313,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
override fun onQueryTextChange(newText: String): Boolean {
|
||||||
if (mIsSearchOpen) {
|
if (mIsSearchOpen) {
|
||||||
searchQueryChanged(newText)
|
setupAdapter(mDirs, newText)
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -332,25 +332,13 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
if (mIsSearchOpen) {
|
if (mIsSearchOpen) {
|
||||||
mIsSearchOpen = false
|
mIsSearchOpen = false
|
||||||
directories_refresh_layout.isEnabled = config.enablePullToRefresh
|
directories_refresh_layout.isEnabled = config.enablePullToRefresh
|
||||||
searchQueryChanged("")
|
setupAdapter(mDirs, "")
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchQueryChanged(text: String) {
|
|
||||||
Thread {
|
|
||||||
val filtered = getUniqueSortedDirs(mDirs).filter { it.name.contains(text, true) } as ArrayList
|
|
||||||
filtered.sortBy { !it.name.startsWith(text, true) }
|
|
||||||
|
|
||||||
runOnUiThread {
|
|
||||||
getRecyclerAdapter()?.updateDirs(filtered)
|
|
||||||
measureRecyclerViewContent(filtered)
|
|
||||||
}
|
|
||||||
}.start()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun removeTempFolder() {
|
private fun removeTempFolder() {
|
||||||
if (config.tempFolderPath.isNotEmpty()) {
|
if (config.tempFolderPath.isNotEmpty()) {
|
||||||
val newFolder = File(config.tempFolderPath)
|
val newFolder = File(config.tempFolderPath)
|
||||||
|
@ -828,7 +816,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
types = newDir.types
|
types = newDir.types
|
||||||
}
|
}
|
||||||
|
|
||||||
showSortedDirs(dirs)
|
setupAdapter(dirs)
|
||||||
|
|
||||||
// update directories and media files in the local db, delete invalid items
|
// update directories and media files in the local db, delete invalid items
|
||||||
updateDBDirectory(directory, mDirectoryDao)
|
updateDBDirectory(directory, mDirectoryDao)
|
||||||
|
@ -855,7 +843,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
mDirectoryDao.deleteDirPath(it.path)
|
mDirectoryDao.deleteDirPath(it.path)
|
||||||
}
|
}
|
||||||
dirs.removeAll(dirsToRemove)
|
dirs.removeAll(dirsToRemove)
|
||||||
showSortedDirs(dirs)
|
setupAdapter(dirs)
|
||||||
}
|
}
|
||||||
|
|
||||||
val foldersToScan = mediaFetcher.getFoldersToScan()
|
val foldersToScan = mediaFetcher.getFoldersToScan()
|
||||||
|
@ -892,7 +880,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
|
|
||||||
val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
|
val newDir = createDirectoryFromMedia(folder, newMedia, albumCovers, hiddenString, includedFolders, isSortingAscending)
|
||||||
dirs.add(newDir)
|
dirs.add(newDir)
|
||||||
showSortedDirs(dirs)
|
setupAdapter(dirs)
|
||||||
mDirectoryDao.insert(newDir)
|
mDirectoryDao.insert(newDir)
|
||||||
if (folder != RECYCLE_BIN) {
|
if (folder != RECYCLE_BIN) {
|
||||||
mMediumDao.insertAll(newMedia)
|
mMediumDao.insertAll(newMedia)
|
||||||
|
@ -964,14 +952,6 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
directories_grid.beVisibleIf(directories_empty_text_label.isGone())
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSortedDirs(dirs: ArrayList<Directory>, checkSubfolders: Boolean = true) {
|
|
||||||
val updatedDirs = getUniqueSortedDirs(dirs).toMutableList() as ArrayList
|
|
||||||
val dirsToShow = if (checkSubfolders) getDirsToShow(updatedDirs) else updatedDirs
|
|
||||||
runOnUiThread {
|
|
||||||
(directories_grid.adapter as? DirectoryAdapter)?.updateDirs(dirsToShow)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getDirsToShow(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
private fun getDirsToShow(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
||||||
return if (config.groupDirectSubfolders) {
|
return if (config.groupDirectSubfolders) {
|
||||||
val dirFolders = dirs.map { it.path }.sorted().toMutableSet() as HashSet<String>
|
val dirFolders = dirs.map { it.path }.sorted().toMutableSet() as HashSet<String>
|
||||||
|
@ -1015,29 +995,33 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes)
|
return Directory(null, path, thumbnail, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupAdapter(dirs: ArrayList<Directory>) {
|
private fun setupAdapter(dirs: ArrayList<Directory>, textToSearch: String = "") {
|
||||||
val currAdapter = directories_grid.adapter
|
val currAdapter = directories_grid.adapter
|
||||||
val dirsToShow = getDirsToShow(dirs)
|
val updatedDirs = getUniqueSortedDirs(dirs).toMutableList() as ArrayList
|
||||||
|
var dirsToShow = getDirsToShow(updatedDirs).clone() as ArrayList<Directory>
|
||||||
if (currAdapter == null) {
|
if (currAdapter == null) {
|
||||||
initZoomListener()
|
initZoomListener()
|
||||||
val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller
|
val fastscroller = if (config.scrollHorizontally) directories_horizontal_fastscroller else directories_vertical_fastscroller
|
||||||
DirectoryAdapter(this, dirsToShow.clone() as ArrayList<Directory>, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) {
|
DirectoryAdapter(this, dirsToShow, this, directories_grid, isPickIntent(intent) || isGetAnyContentIntent(intent), fastscroller) {
|
||||||
val path = (it as Directory).path
|
val path = (it as Directory).path
|
||||||
if (path != config.tempFolderPath) {
|
if (path != config.tempFolderPath) {
|
||||||
itemClicked(path)
|
itemClicked(path)
|
||||||
}
|
}
|
||||||
|
measureRecyclerViewContent(dirsToShow)
|
||||||
}.apply {
|
}.apply {
|
||||||
setupZoomListener(mZoomListener)
|
setupZoomListener(mZoomListener)
|
||||||
directories_grid.adapter = this
|
directories_grid.adapter = this
|
||||||
}
|
}
|
||||||
|
setupScrollDirection()
|
||||||
} else {
|
} else {
|
||||||
showSortedDirs(dirsToShow, false)
|
if (textToSearch.isNotEmpty()) {
|
||||||
|
dirsToShow = dirsToShow.filter { it.name.contains(textToSearch, true) }.sortedBy { !it.name.startsWith(textToSearch, true) }.toMutableList() as ArrayList
|
||||||
|
}
|
||||||
|
runOnUiThread {
|
||||||
|
(directories_grid.adapter as? DirectoryAdapter)?.updateDirs(dirsToShow)
|
||||||
|
measureRecyclerViewContent(dirsToShow)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getRecyclerAdapter()?.dirs?.apply {
|
|
||||||
measureRecyclerViewContent(this)
|
|
||||||
}
|
|
||||||
setupScrollDirection()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupScrollDirection() {
|
private fun setupScrollDirection() {
|
||||||
|
@ -1091,7 +1075,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
|
|
||||||
if (invalidDirs.isNotEmpty()) {
|
if (invalidDirs.isNotEmpty()) {
|
||||||
dirs.removeAll(invalidDirs)
|
dirs.removeAll(invalidDirs)
|
||||||
showSortedDirs(dirs)
|
setupAdapter(dirs)
|
||||||
invalidDirs.forEach {
|
invalidDirs.forEach {
|
||||||
mDirectoryDao.deleteDirPath(it.path)
|
mDirectoryDao.deleteDirPath(it.path)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue