mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-26 22:47:59 +01:00
properly handle grouping by last_modified and date_taken monthly
This commit is contained in:
parent
3e2c66e294
commit
48f097f789
4 changed files with 53 additions and 18 deletions
|
@ -41,8 +41,10 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val path: String =
|
||||||
|
|
||||||
val groupBtn = when {
|
val groupBtn = when {
|
||||||
currGrouping and GROUP_BY_NONE != 0 -> groupingRadio.grouping_dialog_radio_none
|
currGrouping and GROUP_BY_NONE != 0 -> groupingRadio.grouping_dialog_radio_none
|
||||||
currGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 -> groupingRadio.grouping_dialog_radio_last_modified
|
currGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 -> groupingRadio.grouping_dialog_radio_last_modified_daily
|
||||||
currGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 -> groupingRadio.grouping_dialog_radio_date_taken
|
currGrouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0 -> groupingRadio.grouping_dialog_radio_last_modified_monthly
|
||||||
|
currGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 -> groupingRadio.grouping_dialog_radio_date_taken_daily
|
||||||
|
currGrouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0 -> groupingRadio.grouping_dialog_radio_date_taken_monthly
|
||||||
currGrouping and GROUP_BY_FILE_TYPE != 0 -> groupingRadio.grouping_dialog_radio_file_type
|
currGrouping and GROUP_BY_FILE_TYPE != 0 -> groupingRadio.grouping_dialog_radio_file_type
|
||||||
currGrouping and GROUP_BY_EXTENSION != 0 -> groupingRadio.grouping_dialog_radio_extension
|
currGrouping and GROUP_BY_EXTENSION != 0 -> groupingRadio.grouping_dialog_radio_extension
|
||||||
else -> groupingRadio.grouping_dialog_radio_folder
|
else -> groupingRadio.grouping_dialog_radio_folder
|
||||||
|
@ -64,8 +66,10 @@ class ChangeGroupingDialog(val activity: BaseSimpleActivity, val path: String =
|
||||||
val groupingRadio = view.grouping_dialog_radio_grouping
|
val groupingRadio = view.grouping_dialog_radio_grouping
|
||||||
var grouping = when (groupingRadio.checkedRadioButtonId) {
|
var grouping = when (groupingRadio.checkedRadioButtonId) {
|
||||||
R.id.grouping_dialog_radio_none -> GROUP_BY_NONE
|
R.id.grouping_dialog_radio_none -> GROUP_BY_NONE
|
||||||
R.id.grouping_dialog_radio_last_modified -> GROUP_BY_LAST_MODIFIED_DAILY
|
R.id.grouping_dialog_radio_last_modified_daily -> GROUP_BY_LAST_MODIFIED_DAILY
|
||||||
R.id.grouping_dialog_radio_date_taken -> GROUP_BY_DATE_TAKEN_DAILY
|
R.id.grouping_dialog_radio_last_modified_monthly -> GROUP_BY_LAST_MODIFIED_MONTHLY
|
||||||
|
R.id.grouping_dialog_radio_date_taken_daily -> GROUP_BY_DATE_TAKEN_DAILY
|
||||||
|
R.id.grouping_dialog_radio_date_taken_monthly -> GROUP_BY_DATE_TAKEN_MONTHLY
|
||||||
R.id.grouping_dialog_radio_file_type -> GROUP_BY_FILE_TYPE
|
R.id.grouping_dialog_radio_file_type -> GROUP_BY_FILE_TYPE
|
||||||
R.id.grouping_dialog_radio_extension -> GROUP_BY_EXTENSION
|
R.id.grouping_dialog_radio_extension -> GROUP_BY_EXTENSION
|
||||||
else -> GROUP_BY_FOLDER
|
else -> GROUP_BY_FOLDER
|
||||||
|
|
|
@ -336,7 +336,8 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
val sortDescending = currentGrouping and GROUP_DESCENDING != 0
|
val sortDescending = currentGrouping and GROUP_DESCENDING != 0
|
||||||
val sorted = if (currentGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 || currentGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0) {
|
val sorted = if (currentGrouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 || currentGrouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0 ||
|
||||||
|
currentGrouping and GROUP_BY_DATE_TAKEN_DAILY != 0 || currentGrouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0) {
|
||||||
mediumGroups.toSortedMap(if (sortDescending) compareByDescending {
|
mediumGroups.toSortedMap(if (sortDescending) compareByDescending {
|
||||||
it.toLongOrNull() ?: 0L
|
it.toLongOrNull() ?: 0L
|
||||||
} else {
|
} else {
|
||||||
|
@ -351,8 +352,8 @@ class MediaFetcher(val context: Context) {
|
||||||
mediumGroups[key] = value
|
mediumGroups[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
val today = formatDate(System.currentTimeMillis().toString())
|
val today = formatDate(System.currentTimeMillis().toString(), true)
|
||||||
val yesterday = formatDate((System.currentTimeMillis() - DAY_SECONDS * 1000).toString())
|
val yesterday = formatDate((System.currentTimeMillis() - DAY_SECONDS * 1000).toString(), true)
|
||||||
for ((key, value) in mediumGroups) {
|
for ((key, value) in mediumGroups) {
|
||||||
val sectionKey = getFormattedKey(key, currentGrouping, today, yesterday)
|
val sectionKey = getFormattedKey(key, currentGrouping, today, yesterday)
|
||||||
thumbnailItems.add(ThumbnailSection(sectionKey))
|
thumbnailItems.add(ThumbnailSection(sectionKey))
|
||||||
|
@ -363,13 +364,20 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFormattedKey(key: String, grouping: Int, today: String, yesterday: String): String {
|
private fun getFormattedKey(key: String, grouping: Int, today: String, yesterday: String): String {
|
||||||
return when {
|
var result = when {
|
||||||
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 || grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 -> getFinalDate(formatDate(key), today, yesterday)
|
grouping and GROUP_BY_LAST_MODIFIED_DAILY != 0 || grouping and GROUP_BY_DATE_TAKEN_DAILY != 0 -> getFinalDate(formatDate(key, true), today, yesterday)
|
||||||
|
grouping and GROUP_BY_LAST_MODIFIED_MONTHLY != 0 || grouping and GROUP_BY_DATE_TAKEN_MONTHLY != 0 -> formatDate(key, false)
|
||||||
grouping and GROUP_BY_FILE_TYPE != 0 -> getFileTypeString(key)
|
grouping and GROUP_BY_FILE_TYPE != 0 -> getFileTypeString(key)
|
||||||
grouping and GROUP_BY_EXTENSION != 0 -> key.toUpperCase()
|
grouping and GROUP_BY_EXTENSION != 0 -> key.toUpperCase()
|
||||||
grouping and GROUP_BY_FOLDER != 0 -> context.humanizePath(key)
|
grouping and GROUP_BY_FOLDER != 0 -> context.humanizePath(key)
|
||||||
else -> key
|
else -> key
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
result = context.getString(R.string.unknown)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFinalDate(date: String, today: String, yesterday: String): String {
|
private fun getFinalDate(date: String, today: String, yesterday: String): String {
|
||||||
|
@ -380,11 +388,12 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatDate(timestamp: String): String {
|
private fun formatDate(timestamp: String, showDay: Boolean): String {
|
||||||
return if (timestamp.areDigitsOnly()) {
|
return if (timestamp.areDigitsOnly()) {
|
||||||
val cal = Calendar.getInstance(Locale.ENGLISH)
|
val cal = Calendar.getInstance(Locale.ENGLISH)
|
||||||
cal.timeInMillis = timestamp.toLong()
|
cal.timeInMillis = timestamp.toLong()
|
||||||
DateFormat.format("dd MMM yyyy", cal).toString()
|
val format = if (showDay) "dd MMM yyyy" else "MMM yyyy"
|
||||||
|
DateFormat.format(format, cal).toString()
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,8 +56,10 @@ data class Medium(
|
||||||
|
|
||||||
fun getGroupingKey(groupBy: Int): String {
|
fun getGroupingKey(groupBy: Int): String {
|
||||||
return when {
|
return when {
|
||||||
groupBy and GROUP_BY_LAST_MODIFIED_DAILY != 0 -> getDayStartTS(modified)
|
groupBy and GROUP_BY_LAST_MODIFIED_DAILY != 0 -> getDayStartTS(modified, false)
|
||||||
groupBy and GROUP_BY_DATE_TAKEN_DAILY != 0 -> getDayStartTS(taken)
|
groupBy and GROUP_BY_LAST_MODIFIED_MONTHLY != 0 -> getDayStartTS(modified, true)
|
||||||
|
groupBy and GROUP_BY_DATE_TAKEN_DAILY != 0 -> getDayStartTS(taken, false)
|
||||||
|
groupBy and GROUP_BY_DATE_TAKEN_MONTHLY != 0 -> getDayStartTS(taken, true)
|
||||||
groupBy and GROUP_BY_FILE_TYPE != 0 -> type.toString()
|
groupBy and GROUP_BY_FILE_TYPE != 0 -> type.toString()
|
||||||
groupBy and GROUP_BY_EXTENSION != 0 -> name.getFilenameExtension().toLowerCase()
|
groupBy and GROUP_BY_EXTENSION != 0 -> name.getFilenameExtension().toLowerCase()
|
||||||
groupBy and GROUP_BY_FOLDER != 0 -> parentPath
|
groupBy and GROUP_BY_FOLDER != 0 -> parentPath
|
||||||
|
@ -67,13 +69,17 @@ data class Medium(
|
||||||
|
|
||||||
fun getIsInRecycleBin() = deletedTS != 0L
|
fun getIsInRecycleBin() = deletedTS != 0L
|
||||||
|
|
||||||
private fun getDayStartTS(ts: Long): String {
|
private fun getDayStartTS(ts: Long, resetDays: Boolean): String {
|
||||||
val calendar = Calendar.getInstance(Locale.ENGLISH).apply {
|
val calendar = Calendar.getInstance(Locale.ENGLISH).apply {
|
||||||
timeInMillis = ts
|
timeInMillis = ts
|
||||||
set(Calendar.HOUR_OF_DAY, 0)
|
set(Calendar.HOUR_OF_DAY, 0)
|
||||||
set(Calendar.MINUTE, 0)
|
set(Calendar.MINUTE, 0)
|
||||||
set(Calendar.SECOND, 0)
|
set(Calendar.SECOND, 0)
|
||||||
set(Calendar.MILLISECOND, 0)
|
set(Calendar.MILLISECOND, 0)
|
||||||
|
|
||||||
|
if (resetDays) {
|
||||||
|
set(Calendar.DAY_OF_MONTH, 1)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return calendar.timeInMillis.toString()
|
return calendar.timeInMillis.toString()
|
||||||
|
|
|
@ -29,20 +29,36 @@
|
||||||
android:text="@string/do_not_group_files"/>
|
android:text="@string/do_not_group_files"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
android:id="@+id/grouping_dialog_radio_last_modified"
|
android:id="@+id/grouping_dialog_radio_last_modified_daily"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="@dimen/medium_margin"
|
android:paddingTop="@dimen/medium_margin"
|
||||||
android:paddingBottom="@dimen/medium_margin"
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
android:text="@string/by_last_modified"/>
|
android:text="@string/by_last_modified_daily"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
android:id="@+id/grouping_dialog_radio_date_taken"
|
android:id="@+id/grouping_dialog_radio_last_modified_monthly"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:paddingTop="@dimen/medium_margin"
|
android:paddingTop="@dimen/medium_margin"
|
||||||
android:paddingBottom="@dimen/medium_margin"
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
android:text="@string/by_date_taken"/>
|
android:text="@string/by_last_modified_monthly"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/grouping_dialog_radio_date_taken_daily"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/by_date_taken_daily"/>
|
||||||
|
|
||||||
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
|
android:id="@+id/grouping_dialog_radio_date_taken_monthly"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingTop="@dimen/medium_margin"
|
||||||
|
android:paddingBottom="@dimen/medium_margin"
|
||||||
|
android:text="@string/by_date_taken_monthly"/>
|
||||||
|
|
||||||
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
<com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
android:id="@+id/grouping_dialog_radio_file_type"
|
android:id="@+id/grouping_dialog_radio_file_type"
|
||||||
|
|
Loading…
Reference in a new issue