From 609cfbd580fcc808fc11e0eb4ca2326d0bcee6c4 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 5 Dec 2016 22:51:13 +0100 Subject: [PATCH] implement the sorting by date taken --- .../gallery/dialogs/ChangeSortingDialog.kt | 16 +++++++++------- .../gallery/models/Directory.kt | 12 ++++++++++-- .../simplemobiletools/gallery/models/Medium.kt | 12 ++++++++++-- .../main/res/layout/dialog_change_sorting.xml | 15 ++++++++++++--- 4 files changed, 41 insertions(+), 14 deletions(-) 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 778404c20..44933ae44 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ChangeSortingDialog.kt @@ -5,7 +5,7 @@ import android.app.AlertDialog import android.content.DialogInterface import android.view.LayoutInflater import android.view.View -import com.simplemobiletools.gallery.* +import com.simplemobiletools.gallery.R import com.simplemobiletools.gallery.helpers.* import kotlinx.android.synthetic.main.dialog_change_sorting.view.* @@ -40,11 +40,12 @@ class ChangeSortingDialog(val activity: Activity, val isDirectorySorting: Boolea val sortingRadio = view.sorting_dialog_radio_sorting var sortBtn = sortingRadio.sorting_dialog_radio_name - if (currSorting and SORT_BY_DATE_MODIFIED != 0) { - sortBtn = sortingRadio.sorting_dialog_radio_date - } else if (currSorting and SORT_BY_SIZE != 0) { + if (currSorting and SORT_BY_SIZE != 0) { sortBtn = sortingRadio.sorting_dialog_radio_size - } + } else if (currSorting and SORT_BY_DATE_MODIFIED != 0) { + sortBtn = sortingRadio.sorting_dialog_radio_last_modified + } else if (currSorting and SORT_BY_DATE_TAKEN != 0) + sortBtn = sortingRadio.sorting_dialog_radio_date_taken sortBtn.isChecked = true } @@ -62,8 +63,9 @@ class ChangeSortingDialog(val activity: Activity, val isDirectorySorting: Boolea val sortingRadio = view.sorting_dialog_radio_sorting var sorting = when (sortingRadio.checkedRadioButtonId) { R.id.sorting_dialog_radio_name -> SORT_BY_NAME - R.id.sorting_dialog_radio_date -> SORT_BY_DATE_MODIFIED - else -> SORT_BY_SIZE + R.id.sorting_dialog_radio_size -> SORT_BY_SIZE + R.id.sorting_dialog_radio_last_modified -> SORT_BY_DATE_MODIFIED + else -> SORT_BY_DATE_TAKEN } if (view.sorting_dialog_radio_order.checkedRadioButtonId == R.id.sorting_dialog_radio_descending) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt index 2b9c9d3d8..c9be8d77a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Directory.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.models import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.gallery.helpers.SORT_BY_NAME +import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.SORT_DESCENDING class Directory(val path: String, val thumbnail: String, val name: String, var mediaCnt: Int, val date_modified: Long, val date_taken: Long, @@ -18,6 +19,13 @@ class Directory(val path: String, val thumbnail: String, val name: String, var m var res: Int if (sorting and SORT_BY_NAME != 0) { res = name.toLowerCase().compareTo(other.name.toLowerCase()) + } else if (sorting and SORT_BY_SIZE != 0) { + res = if (size == other.size) + 0 + else if (size > other.size) + 1 + else + -1 } else if (sorting and SORT_BY_DATE_MODIFIED != 0) { res = if (date_modified == other.date_modified) 0 @@ -26,9 +34,9 @@ class Directory(val path: String, val thumbnail: String, val name: String, var m else -1 } else { - res = if (size == other.size) + res = if (date_taken == other.date_taken) 0 - else if (size > other.size) + else if (date_taken > other.date_taken) 1 else -1 diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt index 68e6111ab..eaf55074a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -2,6 +2,7 @@ package com.simplemobiletools.gallery.models import com.simplemobiletools.gallery.helpers.SORT_BY_DATE_MODIFIED import com.simplemobiletools.gallery.helpers.SORT_BY_NAME +import com.simplemobiletools.gallery.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.SORT_DESCENDING import java.io.Serializable @@ -23,6 +24,13 @@ class Medium(val name: String, var path: String, val isVideo: Boolean, val date_ var res: Int if (sorting and SORT_BY_NAME != 0) { res = name.toLowerCase().compareTo(other.name.toLowerCase()) + } else if (sorting and SORT_BY_SIZE != 0) { + res = if (size == other.size) + 0 + else if (size > other.size) + 1 + else + -1 } else if (sorting and SORT_BY_DATE_MODIFIED != 0) { res = if (date_modified == other.date_modified) 0 @@ -31,9 +39,9 @@ class Medium(val name: String, var path: String, val isVideo: Boolean, val date_ else -1 } else { - res = if (size == other.size) + res = if (date_taken == other.date_taken) 0 - else if (size > other.size) + else if (date_taken > other.date_taken) 1 else -1 diff --git a/app/src/main/res/layout/dialog_change_sorting.xml b/app/src/main/res/layout/dialog_change_sorting.xml index 045d625b7..a820f3dfa 100644 --- a/app/src/main/res/layout/dialog_change_sorting.xml +++ b/app/src/main/res/layout/dialog_change_sorting.xml @@ -28,7 +28,15 @@ android:text="@string/name"/> + + + android:text="@string/date_taken"/> +