[Android] Add countries to next metadata

Nicolas Pomepuy git at videolan.org
Thu Nov 28 11:40:46 CET 2019


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Wed Oct 30 13:35:11 2019 +0100| [ca5a63fe4d83f8cd97f6a2cbbbcb17adbe5077ab] | committer: Geoffrey Métais

Add countries to next metadata

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

 .../src/org/videolan/vlc/database/models/MediaMetadata.kt | 15 ++++++++++-----
 .../src/org/videolan/vlc/next/models/identify/Media.kt    |  2 +-
 vlc-android/src/org/videolan/vlc/viewmodels/NextModel.kt  | 12 ++----------
 3 files changed, 13 insertions(+), 16 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/database/models/MediaMetadata.kt b/vlc-android/src/org/videolan/vlc/database/models/MediaMetadata.kt
index 04f4f50c8..ddfa12474 100644
--- a/vlc-android/src/org/videolan/vlc/database/models/MediaMetadata.kt
+++ b/vlc-android/src/org/videolan/vlc/database/models/MediaMetadata.kt
@@ -49,6 +49,7 @@ import androidx.room.Entity
 import androidx.room.PrimaryKey
 import java.text.SimpleDateFormat
 import java.util.*
+import kotlin.collections.ArrayList
 
 @Entity(tableName = "media_metadata")
 data class MediaMetadata(
@@ -66,16 +67,20 @@ data class MediaMetadata(
         @ColumnInfo(name = "genres")
         val genres: String,
         @ColumnInfo(name = "release_date")
-        val releaseDate: Date?
+        val releaseDate: Date?,
+        @ColumnInfo(name = "countries")
+        val countries: String
 )
 
 fun MediaMetadata.titleWithYear(): String = title + if (releaseDate != null) " - ${SimpleDateFormat("yyyy", Locale.getDefault()).format(releaseDate)}" else ""
 fun MediaMetadata.subtitle(): String {
-    val subtitle = StringBuilder()
+
+    val subtitle = ArrayList<String>()
     if (releaseDate != null) {
-        subtitle.append("${SimpleDateFormat("yyyy", Locale.getDefault()).format(releaseDate)} ")
+        subtitle.add("${SimpleDateFormat("yyyy", Locale.getDefault()).format(releaseDate)} ")
     }
-    subtitle.append(genres)
+    subtitle.add("$genres")
+    subtitle.add("$countries")
 
-    return subtitle.toString()
+    return subtitle.joinToString(separator = " · ") { it }
 }
diff --git a/vlc-android/src/org/videolan/vlc/next/models/identify/Media.kt b/vlc-android/src/org/videolan/vlc/next/models/identify/Media.kt
index 820756389..cc55d0207 100644
--- a/vlc-android/src/org/videolan/vlc/next/models/identify/Media.kt
+++ b/vlc-android/src/org/videolan/vlc/next/models/identify/Media.kt
@@ -37,7 +37,7 @@ data class Media(
         @field:Json(name = "childrenId")
         val childrenId: List<Any>,
         @field:Json(name = "country")
-        val country: List<String>,
+        val country: List<String>?,
         @field:Json(name = "date")
         val date: Date?,
         @field:Json(name = "externalids")
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/NextModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/NextModel.kt
index c1335d338..d285fb94f 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/NextModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/NextModel.kt
@@ -91,15 +91,6 @@ class NextModel : ViewModel() {
         }
     }
 
-    fun getMediaCast(mediaId: String) {
-        mediaJob?.cancel()
-
-        mediaJob = viewModelScope.launch {
-            withContext(Dispatchers.IO) {
-                getMediaCastResultLiveData.postValue(NextApiRepository.getInstance().getMediaCast(mediaId))
-            }
-        }
-    }
 
     fun saveMediaMetadata(context: Context, media: AbstractMediaWrapper, item: Media) {
         val type = when (item.type) {
@@ -116,7 +107,8 @@ class NextModel : ViewModel() {
                         item.title,
                         item.summary ?: "",
                         item.genre?.joinToString { genre -> genre } ?: "",
-                        item.date)
+                        item.date,
+                        item.country?.joinToString { genre -> genre } ?: "")
 
                 val mediaMetadataRepository = MediaMetadataRepository.getInstance(context)
 



More information about the Android mailing list