implement custom sorting per folder
This commit is contained in:
parent
8c236aaf5b
commit
940ed8a43b
5 changed files with 29 additions and 5 deletions
|
@ -145,7 +145,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
|
|||
}
|
||||
|
||||
private fun showSortingDialog() {
|
||||
ChangeSortingDialog(this, false, true) {
|
||||
ChangeSortingDialog(this, false, true, mPath) {
|
||||
getMedia()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickVideo
|
|||
override fun onPreExecute() {
|
||||
super.onPreExecute()
|
||||
showMedia = config.showMedia
|
||||
fileSorting = config.fileSorting
|
||||
fileSorting = config.getFileSorting(mPath)
|
||||
}
|
||||
|
||||
override fun doInBackground(vararg params: Void): ArrayList<Medium> {
|
||||
|
|
|
@ -12,7 +12,8 @@ import com.simplemobiletools.gallery.extensions.config
|
|||
import com.simplemobiletools.gallery.helpers.*
|
||||
import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
|
||||
|
||||
class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting: Boolean, val showFolderCheckbox: Boolean, val callback: () -> Unit) :
|
||||
class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean,
|
||||
val path: String = "", val callback: () -> Unit) :
|
||||
DialogInterface.OnClickListener {
|
||||
companion object {
|
||||
private var currSorting = 0
|
||||
|
@ -26,6 +27,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
|||
view = LayoutInflater.from(activity).inflate(R.layout.dialog_change_sorting, null)
|
||||
view.use_for_this_folder_divider.beVisibleIf(showFolderCheckbox)
|
||||
view.sorting_dialog_use_for_this_folder.beVisibleIf(showFolderCheckbox)
|
||||
view.sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path)
|
||||
|
||||
AlertDialog.Builder(activity)
|
||||
.setPositiveButton(R.string.ok, this)
|
||||
|
@ -34,7 +36,7 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
|||
activity.setupDialogStuff(view, this, R.string.sort_by)
|
||||
}
|
||||
|
||||
currSorting = if (isDirectorySorting) config.directorySorting else config.fileSorting
|
||||
currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(path)
|
||||
setupSortRadio()
|
||||
setupOrderRadio()
|
||||
}
|
||||
|
@ -78,7 +80,12 @@ class ChangeSortingDialog(val activity: SimpleActivity, val isDirectorySorting:
|
|||
if (isDirectorySorting) {
|
||||
config.directorySorting = sorting
|
||||
} else {
|
||||
config.fileSorting = sorting
|
||||
if (view.sorting_dialog_use_for_this_folder.isChecked) {
|
||||
config.saveFileSorting(path, sorting)
|
||||
} else {
|
||||
config.removeFileSorting(path)
|
||||
config.fileSorting = sorting
|
||||
}
|
||||
}
|
||||
callback.invoke()
|
||||
}
|
||||
|
|
|
@ -18,6 +18,22 @@ class Config(context: Context) : BaseConfig(context) {
|
|||
get() = prefs.getInt(DIRECTORY_SORT_ORDER, SORT_BY_DATE_MODIFIED or SORT_DESCENDING)
|
||||
set(order) = prefs.edit().putInt(DIRECTORY_SORT_ORDER, order).apply()
|
||||
|
||||
fun saveFileSorting(path: String, value: Int) {
|
||||
if (path.isEmpty()) {
|
||||
fileSorting = value
|
||||
} else {
|
||||
prefs.edit().putInt(SORT_FOLDER_PREFIX + path, value).apply()
|
||||
}
|
||||
}
|
||||
|
||||
fun getFileSorting(path: String) = prefs.getInt(SORT_FOLDER_PREFIX + path, fileSorting)
|
||||
|
||||
fun removeFileSorting(path: String) {
|
||||
prefs.edit().remove(SORT_FOLDER_PREFIX + path).apply()
|
||||
}
|
||||
|
||||
fun hasCustomSorting(path: String) = prefs.contains(SORT_FOLDER_PREFIX + path)
|
||||
|
||||
var wasHideFolderTooltipShown: Boolean
|
||||
get() = prefs.getBoolean(HIDE_FOLDER_TOOLTIP_SHOWN, false)
|
||||
set(wasShown) = prefs.edit().putBoolean(HIDE_FOLDER_TOOLTIP_SHOWN, wasShown).apply()
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.simplemobiletools.gallery.helpers
|
|||
// shared preferences
|
||||
val SORT_ORDER = "sort_order"
|
||||
val DIRECTORY_SORT_ORDER = "directory_sort_order"
|
||||
val SORT_FOLDER_PREFIX = "sort_folder_"
|
||||
val SHOW_HIDDEN_FOLDERS = "show_hidden_folders"
|
||||
val AUTOPLAY_VIDEOS = "autoplay_videos"
|
||||
val LOOP_VIDEOS = "loop_videos"
|
||||
|
|
Loading…
Reference in a new issue