diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt index 991d93e40..da162cfef 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt @@ -10,6 +10,7 @@ import com.simplemobiletools.commons.helpers.* import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.extensions.config import com.simplemobiletools.gallery.helpers.SHOW_ALL +import com.simplemobiletools.gallery.helpers.SORT_BY_RANDOM import kotlinx.android.synthetic.main.dialog_change_sorting.view.* class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorting: Boolean, showFolderCheckbox: Boolean, @@ -47,6 +48,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti currSorting and SORT_BY_SIZE != 0 -> sortingRadio.sorting_dialog_radio_size currSorting and SORT_BY_DATE_MODIFIED != 0 -> sortingRadio.sorting_dialog_radio_last_modified currSorting and SORT_BY_DATE_TAKEN != 0 -> sortingRadio.sorting_dialog_radio_date_taken + currSorting and SORT_BY_RANDOM != 0 -> sortingRadio.sorting_dialog_radio_random else -> sortingRadio.sorting_dialog_radio_name } sortBtn.isChecked = true @@ -69,6 +71,7 @@ class ChangeSortingDialog(val activity: BaseSimpleActivity, val isDirectorySorti R.id.sorting_dialog_radio_path -> SORT_BY_PATH R.id.sorting_dialog_radio_size -> SORT_BY_SIZE R.id.sorting_dialog_radio_last_modified -> SORT_BY_DATE_MODIFIED + R.id.sorting_dialog_radio_random -> SORT_BY_RANDOM else -> SORT_BY_DATE_TAKEN } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt index a00548a84..b28041829 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/extensions/Context.kt @@ -139,6 +139,11 @@ fun Context.getSortedDirectories(source: ArrayList): ArrayList + if (sorting and SORT_BY_RANDOM != 0) { + dirs.shuffle() + return movePinnedDirectoriesToFront(dirs) + } + dirs.sortWith(Comparator { o1, o2 -> o1 as Directory o2 as Directory diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 8c0c7b15d..edff3b94d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -153,3 +153,6 @@ const val BOTTOM_ACTION_RENAME = 1024 const val BOTTOM_ACTION_SET_AS = 2048 const val DEFAULT_BOTTOM_ACTIONS = BOTTOM_ACTION_TOGGLE_FAVORITE or BOTTOM_ACTION_EDIT or BOTTOM_ACTION_SHARE or BOTTOM_ACTION_DELETE + +// sorting +const val SORT_BY_RANDOM = 16384 \ No newline at end of file diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt index 7b7a08997..6312293bd 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/MediaFetcher.kt @@ -343,7 +343,12 @@ class MediaFetcher(val context: Context) { return dateTakens } - fun sortMedia(media: ArrayList, sorting: Int) { + fun sortMedia (media: ArrayList, sorting: Int) { + if (sorting and SORT_BY_RANDOM != 0) { + media.shuffle() + return + } + media.sortWith(Comparator { o1, o2 -> o1 as Medium o2 as Medium diff --git a/app/src/main/res/layout/dialog_change_sorting.xml b/app/src/main/res/layout/dialog_change_sorting.xml index e0e642acc..1b2be9ebc 100644 --- a/app/src/main/res/layout/dialog_change_sorting.xml +++ b/app/src/main/res/layout/dialog_change_sorting.xml @@ -60,6 +60,14 @@ android:paddingTop="@dimen/medium_margin" android:text="@string/date_taken"/> + + + Náhodne