Skip to content

Commit

Permalink
Merge pull request #420 from terofeev/sort-by-count
Browse files Browse the repository at this point in the history
Add sort folders by count
  • Loading branch information
naveensingh authored Mar 11, 2025
2 parents 6b0e90f + 23e374c commit f3b3eda
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/kotlin/org/fossify/gallery/extensions/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
}
Expand All @@ -178,7 +179,7 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
result *= -1
}
result
})
}

return movePinnedDirectoriesToFront(dirs)
}
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/layout/dialog_change_sorting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3b3eda

Please sign in to comment.