allow sorting Show All separately

This commit is contained in:
tibbi 2018-06-27 23:52:42 +02:00
parent 8bb6c50075
commit 5db37d6c54
5 changed files with 17 additions and 12 deletions

View file

@ -362,7 +362,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
media_horizontal_fastscroller.isHorizontal = true media_horizontal_fastscroller.isHorizontal = true
media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll) media_horizontal_fastscroller.beVisibleIf(allowHorizontalScroll)
val sorting = config.getFileSorting(mPath) val sorting = config.getFileSorting(if (mShowAll) SHOW_ALL else mPath)
if (allowHorizontalScroll) { if (allowHorizontalScroll) {
media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble media_horizontal_fastscroller.allowBubbleDisplay = config.showInfoBubble
media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) { media_horizontal_fastscroller.setViews(media_grid, media_refresh_layout) {
@ -409,7 +409,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun showSortingDialog() { private fun showSortingDialog() {
ChangeSortingDialog(this, false, !config.showAll, mPath) { ChangeSortingDialog(this, false, true, mPath) {
mLoadedInitialPhotos = false mLoadedInitialPhotos = false
media_grid.adapter = null media_grid.adapter = null
getMedia() getMedia()

View file

@ -17,7 +17,8 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
private val mediaFetcher = MediaFetcher(context) private val mediaFetcher = MediaFetcher(context)
override fun doInBackground(vararg params: Void): ArrayList<ThumbnailItem> { override fun doInBackground(vararg params: Void): ArrayList<ThumbnailItem> {
val getProperDateTaken = context.config.getFileSorting(mPath) and SORT_BY_DATE_TAKEN != 0 val pathToUse = if (showAll) SHOW_ALL else mPath
val getProperDateTaken = context.config.getFileSorting(pathToUse) and SORT_BY_DATE_TAKEN != 0
val favoritePaths = context.getFavoritePaths() val favoritePaths = context.getFavoritePaths()
val media = if (showAll) { val media = if (showAll) {
val foldersToScan = mediaFetcher.getFoldersToScan() val foldersToScan = mediaFetcher.getFoldersToScan()
@ -27,12 +28,12 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
media.addAll(newMedia) media.addAll(newMedia)
} }
mediaFetcher.sortMedia(media, context.config.getFileSorting("")) mediaFetcher.sortMedia(media, context.config.getFileSorting(SHOW_ALL))
media media
} else { } else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths)
} }
return mediaFetcher.groupMedia(media, if (showAll) SHOW_ALL else mPath) return mediaFetcher.groupMedia(media, pathToUse)
} }
override fun onPostExecute(media: ArrayList<ThumbnailItem>) { override fun onPostExecute(media: ArrayList<ThumbnailItem>) {

View file

@ -9,6 +9,7 @@ import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.commons.helpers.*
import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.R
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.helpers.SHOW_ALL
import kotlinx.android.synthetic.main.dialog_change_sorting.view.* import kotlinx.android.synthetic.main.dialog_change_sorting.view.*
class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean, class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean,
@ -16,13 +17,14 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti
DialogInterface.OnClickListener { DialogInterface.OnClickListener {
private var currSorting = 0 private var currSorting = 0
private var config = activity.config private var config = activity.config
private var pathToUse = if (!isDirectorySorting && path.isEmpty()) SHOW_ALL else path
private var view: View private var view: View
init { init {
view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply { view = activity.layoutInflater.inflate(R.layout.dialog_change_sorting, null).apply {
use_for_this_folder_divider.beVisibleIf(showFolderCheckbox) use_for_this_folder_divider.beVisibleIf(showFolderCheckbox)
sorting_dialog_use_for_this_folder.beVisibleIf(showFolderCheckbox) sorting_dialog_use_for_this_folder.beVisibleIf(showFolderCheckbox)
sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(path) sorting_dialog_use_for_this_folder.isChecked = config.hasCustomSorting(pathToUse)
} }
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
@ -32,7 +34,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti
activity.setupDialogStuff(view, this, R.string.sort_by) activity.setupDialogStuff(view, this, R.string.sort_by)
} }
currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(path) currSorting = if (isDirectorySorting) config.directorySorting else config.getFileSorting(pathToUse)
setupSortRadio() setupSortRadio()
setupOrderRadio() setupOrderRadio()
} }
@ -78,9 +80,9 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti
config.directorySorting = sorting config.directorySorting = sorting
} else { } else {
if (view.sorting_dialog_use_for_this_folder.isChecked) { if (view.sorting_dialog_use_for_this_folder.isChecked) {
config.saveFileSorting(path, sorting) config.saveFileSorting(pathToUse, sorting)
} else { } else {
config.removeFileSorting(path) config.removeFileSorting(pathToUse)
config.sorting = sorting config.sorting = sorting
} }
} }

View file

@ -12,6 +12,7 @@ import com.simplemobiletools.gallery.adapters.MediaAdapter
import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask import com.simplemobiletools.gallery.asynctasks.GetMediaAsynctask
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getCachedMedia import com.simplemobiletools.gallery.extensions.getCachedMedia
import com.simplemobiletools.gallery.helpers.SHOW_ALL
import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID import com.simplemobiletools.gallery.helpers.VIEW_TYPE_GRID
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.models.ThumbnailItem
@ -71,7 +72,7 @@ class PickMediumDialog(val activity: BaseSimpleActivity, val path: String, val c
} }
val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType val scrollHorizontally = activity.config.scrollHorizontally && isGridViewType
val sorting = activity.config.getFileSorting(path) val sorting = activity.config.getFileSorting(if (path.isEmpty()) SHOW_ALL else path)
view.apply { view.apply {
media_grid.adapter = adapter media_grid.adapter = adapter

View file

@ -360,8 +360,9 @@ fun Context.getCachedMedia(path: String, getVideosOnly: Boolean = false, getImag
} }
}) as ArrayList<Medium> }) as ArrayList<Medium>
mediaFetcher.sortMedia(media, config.getFileSorting(path)) val pathToUse = if (path.isEmpty()) SHOW_ALL else path
val grouped = mediaFetcher.groupMedia(media, path) mediaFetcher.sortMedia(media, config.getFileSorting(pathToUse))
val grouped = mediaFetcher.groupMedia(media, pathToUse)
callback(grouped.clone() as ArrayList<ThumbnailItem>) callback(grouped.clone() as ArrayList<ThumbnailItem>)
val recycleBinPath = filesDir.toString() val recycleBinPath = filesDir.toString()