Add sort by count.

This commit is contained in:
terofeev 2025-03-06 23:09:31 +04:00
parent a948355d2e
commit 140f876d13
6 changed files with 25 additions and 5 deletions

View file

@ -0,0 +1,3 @@
package org.fossify.gallery
const val SORT_BY_COUNT = 524288 // TODO: Replace with Constants from Commons, then delete this file.

View file

@ -1094,7 +1094,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
taken = newDir.taken
this@apply.size = newDir.size
types = newDir.types
sortValue = getDirectorySortingValue(curMedia, path, name, size)
sortValue = getDirectorySortingValue(curMedia, path, name, size, mediaCnt)
}
setupAdapter(dirs)

View file

@ -5,6 +5,7 @@ import org.fossify.commons.activities.BaseSimpleActivity
import org.fossify.commons.extensions.*
import org.fossify.commons.helpers.*
import org.fossify.gallery.R
import org.fossify.gallery.SORT_BY_COUNT
import org.fossify.gallery.databinding.DialogChangeSortingBinding
import org.fossify.gallery.extensions.config
import org.fossify.gallery.helpers.SHOW_ALL
@ -22,6 +23,7 @@ class ChangeSortingDialog(
init {
currSorting = if (isDirectorySorting) config.directorySorting else config.getFolderSorting(pathToUse)
binding = DialogChangeSortingBinding.inflate(activity.layoutInflater).apply {
sortingDialogRadioNumberOfItems.beVisibleIf(isDirectorySorting)
sortingDialogOrderDivider.beVisibleIf(showFolderCheckbox || (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0))
sortingDialogNumericSorting.beVisibleIf(showFolderCheckbox && (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0))
@ -59,6 +61,7 @@ class ChangeSortingDialog(
val sortBtn = when {
currSorting and SORT_BY_PATH != 0 -> binding.sortingDialogRadioPath
currSorting and SORT_BY_SIZE != 0 -> binding.sortingDialogRadioSize
currSorting and SORT_BY_COUNT != 0 -> binding.sortingDialogRadioNumberOfItems
currSorting and SORT_BY_DATE_MODIFIED != 0 -> binding.sortingDialogRadioLastModified
currSorting and SORT_BY_DATE_TAKEN != 0 -> binding.sortingDialogRadioDateTaken
currSorting and SORT_BY_RANDOM != 0 -> binding.sortingDialogRadioRandom
@ -83,6 +86,7 @@ class ChangeSortingDialog(
R.id.sorting_dialog_radio_name -> SORT_BY_NAME
R.id.sorting_dialog_radio_path -> SORT_BY_PATH
R.id.sorting_dialog_radio_size -> SORT_BY_SIZE
R.id.sorting_dialog_radio_number_of_items -> SORT_BY_COUNT
R.id.sorting_dialog_radio_last_modified -> SORT_BY_DATE_MODIFIED
R.id.sorting_dialog_radio_random -> SORT_BY_RANDOM
R.id.sorting_dialog_radio_custom -> SORT_BY_CUSTOM

View file

@ -37,6 +37,7 @@ import org.fossify.commons.extensions.*
import org.fossify.commons.helpers.*
import org.fossify.commons.views.MySquareImageView
import org.fossify.gallery.R
import org.fossify.gallery.SORT_BY_COUNT
import org.fossify.gallery.asynctasks.GetMediaAsynctask
import org.fossify.gallery.databases.GalleryDatabase
import org.fossify.gallery.helpers.*
@ -124,7 +125,7 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
return newDirsOrdered
}
dirs.sortWith(Comparator { o1, o2 ->
dirs.sortWith { o1, o2 ->
o1 as Directory
o2 as Directory
@ -170,6 +171,7 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
)
sorting and SORT_BY_SIZE != 0 -> (o1.sortValue.toLongOrNull() ?: 0).compareTo(o2.sortValue.toLongOrNull() ?: 0)
sorting and SORT_BY_COUNT != 0 -> (o1.sortValue.toLongOrNull() ?: 0).compareTo(o2.sortValue.toLongOrNull() ?: 0)
sorting and SORT_BY_DATE_MODIFIED != 0 -> (o1.sortValue.toLongOrNull() ?: 0).compareTo(o2.sortValue.toLongOrNull() ?: 0)
else -> (o1.sortValue.toLongOrNull() ?: 0).compareTo(o2.sortValue.toLongOrNull() ?: 0)
}
@ -178,7 +180,7 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
result *= -1
}
result
})
}
return movePinnedDirectoriesToFront(dirs)
}
@ -1061,16 +1063,18 @@ fun Context.createDirectoryFromMedia(
val dateTaken = if (isSortingAscending) Math.min(firstItem.taken, lastItem.taken) else Math.max(firstItem.taken, lastItem.taken)
val size = if (getProperFileSize) curMedia.sumByLong { it.size } else 0L
val mediaTypes = curMedia.getDirMediaTypes()
val sortValue = getDirectorySortingValue(curMedia, path, dirName, size)
val count = curMedia.size
val sortValue = getDirectorySortingValue(curMedia, path, dirName, size, count)
return Directory(null, path, thumbnail!!, dirName, curMedia.size, lastModified, dateTaken, size, getPathLocation(path), mediaTypes, sortValue)
}
fun Context.getDirectorySortingValue(media: ArrayList<Medium>, path: String, name: String, size: Long): String {
fun Context.getDirectorySortingValue(media: ArrayList<Medium>, path: String, name: String, size: Long, count: Int): String {
val sorting = config.directorySorting
val sorted = when {
sorting and SORT_BY_NAME != 0 -> return name
sorting and SORT_BY_PATH != 0 -> return path
sorting and SORT_BY_SIZE != 0 -> return size.toString()
sorting and SORT_BY_COUNT != 0 -> return count.toString()
sorting and SORT_BY_DATE_MODIFIED != 0 -> media.sortedBy { it.modified }
sorting and SORT_BY_DATE_TAKEN != 0 -> media.sortedBy { it.taken }
else -> media

View file

@ -37,6 +37,12 @@
android:layout_height="wrap_content"
android:text="@string/size" />
<org.fossify.commons.views.MyCompatRadioButton
android:id="@+id/sorting_dialog_radio_number_of_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/number_of_items" />
<org.fossify.commons.views.MyCompatRadioButton
android:id="@+id/sorting_dialog_radio_last_modified"
android:layout_width="match_parent"

View file

@ -289,4 +289,7 @@
Haven't found some strings? There's more at
https://github.com/FossifyOrg/Commons/tree/master/commons/src/main/res
-->
<!-- Replace with strings.xml from Commons, then delete these lines. -->
<string name="number_of_items">Number of items</string>
</resources>