Merge pull request #420 from terofeev/sort-by-count

Add sort folders by count
This commit is contained in:
Naveen Singh 2025-03-11 19:35:56 +05:30 committed by GitHub
commit f3b3edab29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 20 additions and 6 deletions

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

@ -59,6 +59,8 @@ open class SimpleActivity : BaseSimpleActivity() {
override fun getAppLauncherName() = getString(R.string.app_launcher_name)
override fun getRepositoryName() = "Gallery"
protected fun checkNotchSupport() {
if (isPiePlus()) {
val cutoutMode = when {

View file

@ -22,6 +22,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 +60,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 +85,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

@ -124,7 +124,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 +170,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 +179,7 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
result *= -1
}
result
})
}
return movePinnedDirectoriesToFront(dirs)
}
@ -1061,16 +1062,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

@ -13,7 +13,7 @@ exif = "1.0.1"
#Room
room = "2.6.1"
#Fossify
commons = "39c99b73c7"
commons = "3dd1f7f33e"
#Gradle4
gradlePlugins-agp = "8.6.1"
#Other