[Android] AudioBrowser add shorter time periods for headers

Duncan McNamara git at videolan.org
Mon May 15 12:09:54 UTC 2023


vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu May 11 14:25:58 2023 +0200| [a5e4d41e734407a2676f792a71deca95eb09e0ce] | committer: Nicolas Pomepuy

AudioBrowser add shorter time periods for headers

Headers have time periods for sorts based on dates. But it goes from new
media to current month, adding a bit of granularity will benefit users.

> https://code.videolan.org/videolan/vlc-android/commit/a5e4d41e734407a2676f792a71deca95eb09e0ce
---

 .../java/org/videolan/resources/util/Helpers.kt    | 29 ++++++++++++++--------
 .../resources/src/main/res/values/strings.xml      |  4 +++
 2 files changed, 22 insertions(+), 11 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt b/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt
index edd73024ae..d5ef17bdd1 100644
--- a/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt
+++ b/application/resources/src/main/java/org/videolan/resources/util/Helpers.kt
@@ -17,27 +17,34 @@ import org.videolan.resources.AppContextProvider
 import org.videolan.resources.R
 import java.util.*
 
-const val LENGTH_WEEK = 7 * 24 * 60 * 60
-const val LENGTH_MONTH = 30 * LENGTH_WEEK
+const val LENGTH_DAY = 24 * 60 * 60
+const val LENGTH_WEEK = 7 * LENGTH_DAY
+const val LENGTH_MONTH = 30 * LENGTH_DAY
 const val LENGTH_YEAR = 52 * LENGTH_WEEK
 const val LENGTH_2_YEAR = 2 * LENGTH_YEAR
 
 fun getTimeCategory(timestamp: Long): Int {
     val delta = (System.currentTimeMillis() / 1000L) - timestamp
     return when {
-        delta < LENGTH_WEEK -> 0
-        delta < LENGTH_MONTH -> 1
-        delta < LENGTH_YEAR -> 2
-        delta < LENGTH_2_YEAR -> 3
-        else -> 4
+        delta < LENGTH_DAY -> 0
+        delta < 2 * LENGTH_DAY -> 1
+        delta < LENGTH_WEEK -> 2
+        delta < 2 * LENGTH_WEEK -> 3
+        delta < LENGTH_MONTH -> 4
+        delta < LENGTH_YEAR -> 5
+        delta < LENGTH_2_YEAR -> 6
+        else -> 7
     }
 }
 
 fun getTimeCategoryString(context: Context, cat: Int) = when (cat) {
-    0 -> context.getString(R.string.time_category_new)
-    1 -> context.getString(R.string.time_category_current_month)
-    2 -> context.getString(R.string.time_category_current_year)
-    3 -> context.getString(R.string.time_category_last_year)
+    0 -> context.getString(R.string.time_category_today)
+    1 -> context.getString(R.string.time_category_yesterday)
+    2 -> context.getString(R.string.time_category_current_week)
+    3 -> context.getString(R.string.time_category_last_week)
+    4 -> context.getString(R.string.time_category_current_month)
+    5 -> context.getString(R.string.time_category_current_year)
+    6 -> context.getString(R.string.time_category_last_year)
     else -> context.getString(R.string.time_category_older)
 }
 
diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index c8e6010972..51daa19b3d 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -726,6 +726,10 @@
     <string name="ab_repeat_stop">Stop A-B repeat</string>
     <string name="stop_after_this">Stop after this track</string>
     <string name="time_category_new">New media</string>
+    <string name="time_category_today">Today</string>
+    <string name="time_category_yesterday">Yesterday</string>
+    <string name="time_category_current_week">This week</string>
+    <string name="time_category_last_week">Last week</string>
     <string name="time_category_current_month">This month</string>
     <string name="time_category_current_year">This year</string>
     <string name="time_category_last_year">Last year</string>



More information about the Android mailing list