From e3fde0a6eb4247a38c5c62979bfb1f024b0f74d9 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 21 Jun 2018 23:26:05 +0200 Subject: [PATCH] obtain the start of the day TS at grouping by date taken and last modified --- .../simplemobiletools/gallery/models/Medium.kt | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) 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 e4441f6d5..1097f935f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/models/Medium.kt @@ -13,6 +13,7 @@ import com.simplemobiletools.commons.helpers.SORT_BY_PATH import com.simplemobiletools.commons.helpers.SORT_BY_SIZE import com.simplemobiletools.gallery.helpers.* import java.io.Serializable +import java.util.* @Entity(tableName = "media", indices = [(Index(value = "full_path", unique = true))]) data class Medium( @@ -48,12 +49,24 @@ data class Medium( fun getGroupingKey(groupBy: Int): String { return when { - groupBy and GROUP_BY_LAST_MODIFIED != 0 -> modified.toString() - groupBy and GROUP_BY_DATE_TAKEN != 0 -> taken.toString() + groupBy and GROUP_BY_LAST_MODIFIED != 0 -> getDayStartTS(modified) + groupBy and GROUP_BY_DATE_TAKEN != 0 -> getDayStartTS(taken) groupBy and GROUP_BY_FILE_TYPE != 0 -> type.toString() groupBy and GROUP_BY_EXTENSION != 0 -> name.getFilenameExtension().toLowerCase() groupBy and GROUP_BY_FOLDER != 0 -> parentPath else -> "" } } + + private fun getDayStartTS(ts: Long): String { + val calendar = Calendar.getInstance(Locale.ENGLISH).apply { + timeInMillis = ts + set(Calendar.HOUR_OF_DAY, 0) + set(Calendar.MINUTE, 0) + set(Calendar.SECOND, 0) + set(Calendar.MILLISECOND, 0) + } + + return calendar.timeInMillis.toString() + } }