replace date at thumbnail grouping with Today or Yesterday, if appropriate
This commit is contained in:
parent
c50960316a
commit
e5a22cd196
2 changed files with 16 additions and 5 deletions
|
@ -47,7 +47,7 @@ ext {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'com.simplemobiletools:commons:4.3.7'
|
implementation 'com.simplemobiletools:commons:4.3.8'
|
||||||
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
|
implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0'
|
||||||
implementation 'com.android.support:multidex:1.0.3'
|
implementation 'com.android.support:multidex:1.0.3'
|
||||||
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
implementation 'it.sephiroth.android.exif:library:1.0.1'
|
||||||
|
|
|
@ -373,17 +373,20 @@ class MediaFetcher(val context: Context) {
|
||||||
mediumGroups[key] = value
|
mediumGroups[key] = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val today = formatDate(System.currentTimeMillis().toString())
|
||||||
|
val yesterday = formatDate((System.currentTimeMillis() - DAY_SECONDS * 1000).toString())
|
||||||
for ((key, value) in mediumGroups) {
|
for ((key, value) in mediumGroups) {
|
||||||
thumbnailItems.add(ThumbnailSection(getFormattedKey(key, currentGrouping)))
|
val sectionKey = getFormattedKey(key, currentGrouping, today, yesterday)
|
||||||
|
thumbnailItems.add(ThumbnailSection(sectionKey))
|
||||||
thumbnailItems.addAll(value)
|
thumbnailItems.addAll(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
return thumbnailItems
|
return thumbnailItems
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFormattedKey(key: String, grouping: Int): String {
|
private fun getFormattedKey(key: String, grouping: Int, today: String, yesterday: String): String {
|
||||||
return when {
|
return when {
|
||||||
grouping and GROUP_BY_LAST_MODIFIED != 0 || grouping and GROUP_BY_DATE_TAKEN != 0 -> formatDate(key)
|
grouping and GROUP_BY_LAST_MODIFIED != 0 || grouping and GROUP_BY_DATE_TAKEN != 0 -> getFinalDate(formatDate(key), today, yesterday)
|
||||||
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)
|
||||||
|
@ -391,11 +394,19 @@ class MediaFetcher(val context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getFinalDate(date: String, today: String, yesterday: String): String {
|
||||||
|
return when (date) {
|
||||||
|
today -> context.getString(R.string.today)
|
||||||
|
yesterday -> context.getString(R.string.yesterday)
|
||||||
|
else -> date
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun formatDate(timestamp: String): String {
|
private fun formatDate(timestamp: String): 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()
|
return DateFormat.format("dd MMM yyyy", cal).toString()
|
||||||
} else {
|
} else {
|
||||||
""
|
""
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue