implement the sorting by date taken

This commit is contained in:
tibbi 2016-12-05 22:51:13 +01:00
parent 438d987e3f
commit 609cfbd580
4 changed files with 41 additions and 14 deletions

View file

@ -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) {

View file

@ -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

View file

@ -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

View file

@ -28,7 +28,15 @@
android:text="@string/name"/>
<RadioButton
android:id="@+id/sorting_dialog_radio_date"
android:id="@+id/sorting_dialog_radio_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium_padding"
android:paddingTop="@dimen/medium_padding"
android:text="@string/size"/>
<RadioButton
android:id="@+id/sorting_dialog_radio_last_modified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium_padding"
@ -36,12 +44,13 @@
android:text="@string/last_modified"/>
<RadioButton
android:id="@+id/sorting_dialog_radio_size"
android:id="@+id/sorting_dialog_radio_date_taken"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/medium_padding"
android:paddingTop="@dimen/medium_padding"
android:text="@string/size"/>
android:text="@string/date_taken"/>
</RadioGroup>
<ImageView