mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2025-03-12 06:30:06 +01:00
Add sort by count.
This commit is contained in:
parent
a948355d2e
commit
140f876d13
6 changed files with 25 additions and 5 deletions
3
app/src/main/kotlin/org/fossify/gallery/Constants.kt
Normal file
3
app/src/main/kotlin/org/fossify/gallery/Constants.kt
Normal 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.
|
|
@ -1094,7 +1094,7 @@ class MainActivity : SimpleActivity(), DirectoryOperationsListener {
|
||||||
taken = newDir.taken
|
taken = newDir.taken
|
||||||
this@apply.size = newDir.size
|
this@apply.size = newDir.size
|
||||||
types = newDir.types
|
types = newDir.types
|
||||||
sortValue = getDirectorySortingValue(curMedia, path, name, size)
|
sortValue = getDirectorySortingValue(curMedia, path, name, size, mediaCnt)
|
||||||
}
|
}
|
||||||
|
|
||||||
setupAdapter(dirs)
|
setupAdapter(dirs)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.fossify.commons.activities.BaseSimpleActivity
|
||||||
import org.fossify.commons.extensions.*
|
import org.fossify.commons.extensions.*
|
||||||
import org.fossify.commons.helpers.*
|
import org.fossify.commons.helpers.*
|
||||||
import org.fossify.gallery.R
|
import org.fossify.gallery.R
|
||||||
|
import org.fossify.gallery.SORT_BY_COUNT
|
||||||
import org.fossify.gallery.databinding.DialogChangeSortingBinding
|
import org.fossify.gallery.databinding.DialogChangeSortingBinding
|
||||||
import org.fossify.gallery.extensions.config
|
import org.fossify.gallery.extensions.config
|
||||||
import org.fossify.gallery.helpers.SHOW_ALL
|
import org.fossify.gallery.helpers.SHOW_ALL
|
||||||
|
@ -22,6 +23,7 @@ class ChangeSortingDialog(
|
||||||
init {
|
init {
|
||||||
currSorting = if (isDirectorySorting) config.directorySorting else config.getFolderSorting(pathToUse)
|
currSorting = if (isDirectorySorting) config.directorySorting else config.getFolderSorting(pathToUse)
|
||||||
binding = DialogChangeSortingBinding.inflate(activity.layoutInflater).apply {
|
binding = DialogChangeSortingBinding.inflate(activity.layoutInflater).apply {
|
||||||
|
sortingDialogRadioNumberOfItems.beVisibleIf(isDirectorySorting)
|
||||||
sortingDialogOrderDivider.beVisibleIf(showFolderCheckbox || (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0))
|
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))
|
sortingDialogNumericSorting.beVisibleIf(showFolderCheckbox && (currSorting and SORT_BY_NAME != 0 || currSorting and SORT_BY_PATH != 0))
|
||||||
|
@ -59,6 +61,7 @@ class ChangeSortingDialog(
|
||||||
val sortBtn = when {
|
val sortBtn = when {
|
||||||
currSorting and SORT_BY_PATH != 0 -> binding.sortingDialogRadioPath
|
currSorting and SORT_BY_PATH != 0 -> binding.sortingDialogRadioPath
|
||||||
currSorting and SORT_BY_SIZE != 0 -> binding.sortingDialogRadioSize
|
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_MODIFIED != 0 -> binding.sortingDialogRadioLastModified
|
||||||
currSorting and SORT_BY_DATE_TAKEN != 0 -> binding.sortingDialogRadioDateTaken
|
currSorting and SORT_BY_DATE_TAKEN != 0 -> binding.sortingDialogRadioDateTaken
|
||||||
currSorting and SORT_BY_RANDOM != 0 -> binding.sortingDialogRadioRandom
|
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_name -> SORT_BY_NAME
|
||||||
R.id.sorting_dialog_radio_path -> SORT_BY_PATH
|
R.id.sorting_dialog_radio_path -> SORT_BY_PATH
|
||||||
R.id.sorting_dialog_radio_size -> SORT_BY_SIZE
|
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_last_modified -> SORT_BY_DATE_MODIFIED
|
||||||
R.id.sorting_dialog_radio_random -> SORT_BY_RANDOM
|
R.id.sorting_dialog_radio_random -> SORT_BY_RANDOM
|
||||||
R.id.sorting_dialog_radio_custom -> SORT_BY_CUSTOM
|
R.id.sorting_dialog_radio_custom -> SORT_BY_CUSTOM
|
||||||
|
|
|
@ -37,6 +37,7 @@ import org.fossify.commons.extensions.*
|
||||||
import org.fossify.commons.helpers.*
|
import org.fossify.commons.helpers.*
|
||||||
import org.fossify.commons.views.MySquareImageView
|
import org.fossify.commons.views.MySquareImageView
|
||||||
import org.fossify.gallery.R
|
import org.fossify.gallery.R
|
||||||
|
import org.fossify.gallery.SORT_BY_COUNT
|
||||||
import org.fossify.gallery.asynctasks.GetMediaAsynctask
|
import org.fossify.gallery.asynctasks.GetMediaAsynctask
|
||||||
import org.fossify.gallery.databases.GalleryDatabase
|
import org.fossify.gallery.databases.GalleryDatabase
|
||||||
import org.fossify.gallery.helpers.*
|
import org.fossify.gallery.helpers.*
|
||||||
|
@ -124,7 +125,7 @@ fun Context.getSortedDirectories(source: ArrayList<Directory>): ArrayList<Direct
|
||||||
return newDirsOrdered
|
return newDirsOrdered
|
||||||
}
|
}
|
||||||
|
|
||||||
dirs.sortWith(Comparator { o1, o2 ->
|
dirs.sortWith { o1, o2 ->
|
||||||
o1 as Directory
|
o1 as Directory
|
||||||
o2 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_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)
|
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)
|
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 *= -1
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
})
|
}
|
||||||
|
|
||||||
return movePinnedDirectoriesToFront(dirs)
|
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 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 size = if (getProperFileSize) curMedia.sumByLong { it.size } else 0L
|
||||||
val mediaTypes = curMedia.getDirMediaTypes()
|
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)
|
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 sorting = config.directorySorting
|
||||||
val sorted = when {
|
val sorted = when {
|
||||||
sorting and SORT_BY_NAME != 0 -> return name
|
sorting and SORT_BY_NAME != 0 -> return name
|
||||||
sorting and SORT_BY_PATH != 0 -> return path
|
sorting and SORT_BY_PATH != 0 -> return path
|
||||||
sorting and SORT_BY_SIZE != 0 -> return size.toString()
|
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_MODIFIED != 0 -> media.sortedBy { it.modified }
|
||||||
sorting and SORT_BY_DATE_TAKEN != 0 -> media.sortedBy { it.taken }
|
sorting and SORT_BY_DATE_TAKEN != 0 -> media.sortedBy { it.taken }
|
||||||
else -> media
|
else -> media
|
||||||
|
|
|
@ -37,6 +37,12 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/size" />
|
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
|
<org.fossify.commons.views.MyCompatRadioButton
|
||||||
android:id="@+id/sorting_dialog_radio_last_modified"
|
android:id="@+id/sorting_dialog_radio_last_modified"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -289,4 +289,7 @@
|
||||||
Haven't found some strings? There's more at
|
Haven't found some strings? There's more at
|
||||||
https://github.com/FossifyOrg/Commons/tree/master/commons/src/main/res
|
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>
|
</resources>
|
||||||
|
|
Loading…
Add table
Reference in a new issue