just quickly resort directories at sorting change, when possible
This commit is contained in:
parent
0da84f2958
commit
417c1169f8
|
@ -19,6 +19,8 @@ import com.google.gson.Gson
|
|||
import com.simplemobiletools.commons.dialogs.CreateNewFolderDialog
|
||||
import com.simplemobiletools.commons.dialogs.FilePickerDialog
|
||||
import com.simplemobiletools.commons.extensions.*
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_MODIFIED
|
||||
import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
|
||||
import com.simplemobiletools.commons.models.Release
|
||||
import com.simplemobiletools.commons.views.MyScalableRecyclerView
|
||||
import com.simplemobiletools.gallery.BuildConfig
|
||||
|
@ -220,7 +222,11 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
|
||||
private fun showSortingDialog() {
|
||||
ChangeSortingDialog(this, true, false) {
|
||||
getDirectories()
|
||||
if (config.directorySorting and SORT_BY_DATE_MODIFIED > 0 || config.directorySorting and SORT_BY_DATE_TAKEN > 0) {
|
||||
getDirectories()
|
||||
} else {
|
||||
gotDirectories(mDirs, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -420,7 +426,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun gotDirectories(dirs: ArrayList<Directory>, isFromCache: Boolean) {
|
||||
private fun gotDirectories(newDirs: ArrayList<Directory>, isFromCache: Boolean) {
|
||||
val dirs = getSortedDirectories(newDirs)
|
||||
|
||||
mLastMediaModified = getLastMediaModified()
|
||||
directories_refresh_layout.isRefreshing = false
|
||||
mIsGettingDirs = false
|
||||
|
@ -429,8 +437,9 @@ class MainActivity : SimpleActivity(), DirectoryAdapter.DirOperationsListener {
|
|||
directories_empty_text.beVisibleIf(dirs.isEmpty() && !isFromCache)
|
||||
|
||||
checkLastMediaChanged()
|
||||
if (dirs.hashCode() == mDirs.hashCode())
|
||||
if (dirs.hashCode() == mDirs.hashCode()) {
|
||||
return
|
||||
}
|
||||
|
||||
mDirs = dirs
|
||||
|
||||
|
|
|
@ -77,9 +77,7 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
dirs.add(directory)
|
||||
}
|
||||
|
||||
Directory.sorting = config.directorySorting
|
||||
dirs.sort()
|
||||
return movePinnedToFront(dirs)
|
||||
return dirs
|
||||
}
|
||||
|
||||
private fun groupDirectories(media: ArrayList<Medium>): HashMap<String, ArrayList<Medium>> {
|
||||
|
@ -133,16 +131,6 @@ class GetDirectoriesAsynctask(val context: Context, val isPickVideo: Boolean, va
|
|||
private fun isThisOrParentExcluded(path: String, excludedPaths: MutableSet<String>, includedPaths: MutableSet<String>) =
|
||||
includedPaths.none { path.startsWith(it) } && excludedPaths.any { path.startsWith(it) }
|
||||
|
||||
private fun movePinnedToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
||||
val foundFolders = ArrayList<Directory>()
|
||||
val pinnedFolders = config.pinnedFolders
|
||||
|
||||
dirs.forEach { if (pinnedFolders.contains(it.path)) foundFolders.add(it) }
|
||||
dirs.removeAll(foundFolders)
|
||||
dirs.addAll(0, foundFolders)
|
||||
return dirs
|
||||
}
|
||||
|
||||
override fun onPostExecute(dirs: ArrayList<Directory>) {
|
||||
super.onPostExecute(dirs)
|
||||
callback(dirs)
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.simplemobiletools.gallery.adapters.DirectoryAdapter
|
|||
import com.simplemobiletools.gallery.asynctasks.GetDirectoriesAsynctask
|
||||
import com.simplemobiletools.gallery.extensions.config
|
||||
import com.simplemobiletools.gallery.extensions.getCachedDirectories
|
||||
import com.simplemobiletools.gallery.extensions.getSortedDirectories
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import kotlinx.android.synthetic.main.dialog_directory_picker.view.*
|
||||
|
||||
|
@ -47,19 +48,20 @@ class PickDirectoryDialog(val activity: SimpleActivity, val sourcePath: String,
|
|||
}
|
||||
}
|
||||
|
||||
fun showOtherFolder() {
|
||||
private fun showOtherFolder() {
|
||||
val showHidden = activity.config.shouldShowHidden
|
||||
FilePickerDialog(activity, sourcePath, false, showHidden, true) {
|
||||
callback(it)
|
||||
}
|
||||
}
|
||||
|
||||
private fun gotDirectories(directories: ArrayList<Directory>) {
|
||||
if (directories.hashCode() == shownDirectories.hashCode())
|
||||
private fun gotDirectories(newDirs: ArrayList<Directory>) {
|
||||
val dirs = activity.getSortedDirectories(newDirs)
|
||||
if (dirs.hashCode() == shownDirectories.hashCode())
|
||||
return
|
||||
|
||||
shownDirectories = directories
|
||||
val adapter = DirectoryAdapter(activity, directories, null, true) {
|
||||
shownDirectories = dirs
|
||||
val adapter = DirectoryAdapter(activity, dirs, null, true) {
|
||||
if (it.path.trimEnd('/') == sourcePath) {
|
||||
activity.toast(R.string.source_and_destination_same)
|
||||
return@DirectoryAdapter
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_SIZE
|
|||
import com.simplemobiletools.commons.helpers.SORT_DESCENDING
|
||||
import com.simplemobiletools.gallery.activities.SettingsActivity
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.models.Directory
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import java.io.File
|
||||
|
||||
|
@ -289,3 +290,21 @@ fun Context.getLastMediaModified(): Int {
|
|||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
fun Context.movePinnedDirectoriesToFront(dirs: ArrayList<Directory>): ArrayList<Directory> {
|
||||
val foundFolders = ArrayList<Directory>()
|
||||
val pinnedFolders = config.pinnedFolders
|
||||
|
||||
dirs.forEach { if (pinnedFolders.contains(it.path)) foundFolders.add(it) }
|
||||
dirs.removeAll(foundFolders)
|
||||
dirs.addAll(0, foundFolders)
|
||||
return dirs
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Directory> {
|
||||
Directory.sorting = config.directorySorting
|
||||
val dirs = source.clone() as ArrayList<Directory>
|
||||
dirs.sort()
|
||||
return movePinnedDirectoriesToFront(dirs)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue