allow setting a different grouping for Show All Folders Content

This commit is contained in:
tibbi 2018-06-27 23:37:15 +02:00
parent 0f3daf9052
commit 61e66a3d5d
5 changed files with 15 additions and 13 deletions

View file

@ -477,7 +477,7 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
} }
private fun showGroupByDialog() { private fun showGroupByDialog() {
ChangeGroupingDialog(this, mShowAll, mPath) { ChangeGroupingDialog(this, mPath) {
mLoadedInitialPhotos = false mLoadedInitialPhotos = false
media_grid.adapter = null media_grid.adapter = null
getMedia() getMedia()
@ -644,7 +644,8 @@ class MediaActivity : SimpleActivity(), MediaAdapter.MediaOperationsListener {
private fun calculateContentHeight(media: ArrayList<ThumbnailItem>) { private fun calculateContentHeight(media: ArrayList<ThumbnailItem>) {
val layoutManager = media_grid.layoutManager as MyGridLayoutManager val layoutManager = media_grid.layoutManager as MyGridLayoutManager
val hasSections = config.getFolderGrouping(mPath) and GROUP_BY_NONE == 0 && !config.scrollHorizontally val pathToCheck = if (mPath.isEmpty()) SHOW_ALL else mPath
val hasSections = config.getFolderGrouping(pathToCheck) and GROUP_BY_NONE == 0 && !config.scrollHorizontally
val sectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0 val sectionTitleHeight = if (hasSections) layoutManager.getChildAt(0)?.height ?: 0 else 0
val thumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height val thumbnailHeight = if (hasSections) layoutManager.getChildAt(1)?.height ?: 0 else layoutManager.getChildAt(0)?.height
?: 0 ?: 0

View file

@ -6,6 +6,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_DATE_TAKEN
import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.extensions.getFavoritePaths import com.simplemobiletools.gallery.extensions.getFavoritePaths
import com.simplemobiletools.gallery.helpers.MediaFetcher import com.simplemobiletools.gallery.helpers.MediaFetcher
import com.simplemobiletools.gallery.helpers.SHOW_ALL
import com.simplemobiletools.gallery.models.Medium import com.simplemobiletools.gallery.models.Medium
import com.simplemobiletools.gallery.models.ThumbnailItem import com.simplemobiletools.gallery.models.ThumbnailItem
import java.util.* import java.util.*
@ -31,7 +32,7 @@ class GetMediaAsynctask(val context: Context, val mPath: String, val isPickImage
} else { } else {
mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths) mediaFetcher.getFilesFrom(mPath, isPickImage, isPickVideo, getProperDateTaken, favoritePaths)
} }
return mediaFetcher.groupMedia(media, mPath) return mediaFetcher.groupMedia(media, if (showAll) SHOW_ALL else mPath)
} }
override fun onPostExecute(media: ArrayList<ThumbnailItem>) { override fun onPostExecute(media: ArrayList<ThumbnailItem>) {

View file

@ -11,18 +11,17 @@ import com.simplemobiletools.gallery.extensions.config
import com.simplemobiletools.gallery.helpers.* import com.simplemobiletools.gallery.helpers.*
import kotlinx.android.synthetic.main.dialog_change_grouping.view.* import kotlinx.android.synthetic.main.dialog_change_grouping.view.*
class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: Boolean, val path: String = "", val callback: () -> Unit) : class ChangeGroupingDialog(val activity: BaseSimpleActivity, val path: String = "", val callback: () -> Unit) :
DialogInterface.OnClickListener { DialogInterface.OnClickListener {
private var currGrouping = 0 private var currGrouping = 0
private var config = activity.config private var config = activity.config
private val pathToUse = if (path.isEmpty()) SHOW_ALL else path
private var view: View private var view: View
init { init {
view = activity.layoutInflater.inflate(R.layout.dialog_change_grouping, null).apply { view = activity.layoutInflater.inflate(R.layout.dialog_change_grouping, null).apply {
use_for_this_folder_divider.beVisibleIf(!isShowingAll) grouping_dialog_use_for_this_folder.isChecked = config.hasCustomGrouping(pathToUse)
grouping_dialog_use_for_this_folder.beVisibleIf(!isShowingAll) grouping_dialog_radio_folder.beVisibleIf(path.isEmpty())
grouping_dialog_use_for_this_folder.isChecked = config.hasCustomGrouping(path)
grouping_dialog_radio_folder.beVisibleIf(isShowingAll)
} }
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
@ -32,7 +31,7 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: B
activity.setupDialogStuff(view, this, R.string.group_by) activity.setupDialogStuff(view, this, R.string.group_by)
} }
currGrouping = config.getFolderGrouping(path) currGrouping = config.getFolderGrouping(pathToUse)
setupGroupRadio() setupGroupRadio()
setupOrderRadio() setupOrderRadio()
} }
@ -77,9 +76,9 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val isShowingAll: B
} }
if (view.grouping_dialog_use_for_this_folder.isChecked) { if (view.grouping_dialog_use_for_this_folder.isChecked) {
config.saveFolderGrouping(path, grouping) config.saveFolderGrouping(pathToUse, grouping)
} else { } else {
config.removeFolderGrouping(path) config.removeFolderGrouping(pathToUse)
config.groupBy = grouping config.groupBy = grouping
} }
callback() callback()

View file

@ -46,7 +46,7 @@ class Config(context: Context) : BaseConfig(context) {
fun getFolderGrouping(path: String): Int { fun getFolderGrouping(path: String): Int {
var groupBy = prefs.getInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), groupBy) var groupBy = prefs.getInt(GROUP_FOLDER_PREFIX + path.toLowerCase(), groupBy)
if (path.isNotEmpty() && groupBy and GROUP_BY_FOLDER != 0) { if (path != SHOW_ALL && groupBy and GROUP_BY_FOLDER != 0) {
groupBy -= GROUP_BY_FOLDER + 1 groupBy -= GROUP_BY_FOLDER + 1
} }
return groupBy return groupBy

View file

@ -346,7 +346,8 @@ class MediaFetcher(val context: Context) {
fun groupMedia(media: ArrayList<Medium>, path: String): ArrayList<ThumbnailItem> { fun groupMedia(media: ArrayList<Medium>, path: String): ArrayList<ThumbnailItem> {
val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>() val mediumGroups = LinkedHashMap<String, ArrayList<Medium>>()
val currentGrouping = context.config.getFolderGrouping(path) val pathToCheck = if (path.isEmpty()) SHOW_ALL else path
val currentGrouping = context.config.getFolderGrouping(pathToCheck)
if (currentGrouping and GROUP_BY_NONE != 0) { if (currentGrouping and GROUP_BY_NONE != 0) {
return media as ArrayList<ThumbnailItem> return media as ArrayList<ThumbnailItem>
} }