[Android] AudioBrowser: fix track sort by date display
Duncan McNamara
git at videolan.org
Wed May 10 12:41:25 UTC 2023
vlc-android | branch: master | Duncan McNamara <dcn.mcnamara at gmail.com> | Thu May 4 15:08:13 2023 +0200| [f3732b3ed24a2093e4a5b9d739c13c56c005762f] | committer: Nicolas Pomepuy
AudioBrowser: fix track sort by date display
Albums and MediaWrappers use MedialibraryItem's releaseDate as releaseYear
Though when indexed an album's releaseDate saves only the year,
whereas MediaWrappers' releaseDate save the whole date
This adds conversion from date to year for mediawrappers in the helper
getYear
Fixes #2829
> https://code.videolan.org/videolan/vlc-android/commit/f3732b3ed24a2093e4a5b9d739c13c56c005762f
---
.../main/java/org/videolan/resources/util/Helpers.kt | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 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 a7cc24c72f..edd73024ae 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
@@ -11,11 +11,11 @@ import androidx.core.content.ContextCompat
import org.videolan.libvlc.util.AndroidUtil
import org.videolan.medialibrary.interfaces.media.Album
import org.videolan.medialibrary.interfaces.media.MediaWrapper
-import org.videolan.medialibrary.interfaces.media.Playlist
import org.videolan.medialibrary.interfaces.media.VideoGroup
import org.videolan.medialibrary.media.MediaLibraryItem
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
@@ -52,9 +52,22 @@ fun MediaLibraryItem.getLength() = when {
else -> 0L
}
+// Albums and MediaWrappers use MedialibraryItem's releaseDate as releaseYear
+// Though when indexed an album's releaseDate saves only the year,
+// whereas MediaWrappers' releaseDate save the whole date
fun MediaLibraryItem.getYear() = when (itemType) {
- MediaLibraryItem.TYPE_ALBUM -> if ((this as Album).releaseYear <= 0) "-" else releaseYear.toString()
- MediaLibraryItem.TYPE_MEDIA -> if ((this as MediaWrapper).releaseYear <= 0) "-" else releaseYear.toString()
+ MediaLibraryItem.TYPE_ALBUM -> {
+ if ((this as Album).releaseYear <= 0) "-" else releaseYear.toString()
+ }
+ MediaLibraryItem.TYPE_MEDIA ->{
+ if ((this as MediaWrapper).releaseYear <= 0)
+ "-"
+ else {
+ val calendar = Calendar.getInstance()
+ calendar.time = Date(releaseYear.toLong() * 1000)
+ calendar.get(Calendar.YEAR).toString()
+ }
+ }
else -> "-"
}
More information about the Android
mailing list