[Android] Retrieve more tv show info

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Nov 18 07:49:29 2019 +0100| [881e572ba7691f0782b78a89fdf4a5c7eae14989] | committer: Geoffrey Métais

Retrieve more tv show info

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

 .../src/org/videolan/vlc/database/MediaTvshowDao.kt       |  5 ++++-
 .../src/org/videolan/vlc/database/models/MediaMetadata.kt |  2 +-
 .../videolan/vlc/repository/MediaMetadataRepository.kt    |  2 ++
 .../src/org/videolan/vlc/viewmodels/MoviepediaModel.kt    | 15 ++++++++-------
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/database/MediaTvshowDao.kt b/vlc-android/src/org/videolan/vlc/database/MediaTvshowDao.kt
index e2a519495..81e82defb 100644
--- a/vlc-android/src/org/videolan/vlc/database/MediaTvshowDao.kt
+++ b/vlc-android/src/org/videolan/vlc/database/MediaTvshowDao.kt
@@ -35,7 +35,10 @@ interface MediaTvshowDao {
     @Insert(onConflict = OnConflictStrategy.REPLACE)
     fun insert(show: MediaTvshow)
 
-    @Query("select count(moviepedia_show_id) from media_tv_show")
+    @Query("SELECT * FROM media_tv_show WHERE moviepedia_show_id=:showId")
+    fun find(showId: String): MediaTvshow?
+
+    @Query("SELECT count(moviepedia_show_id) FROM media_tv_show")
     fun getTvshowsCount(): Int
 
     @RawQuery(observedEntities = [MediaTvshow::class])
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 6c0b717e2..db1ed1a2f 100644
--- a/vlc-android/src/org/videolan/vlc/database/models/MediaMetadata.kt
+++ b/vlc-android/src/org/videolan/vlc/database/models/MediaMetadata.kt
@@ -164,7 +164,7 @@ data class MediaTvshow(
         @ColumnInfo(name = "image")
         val image: String,
         @ColumnInfo(name = "release_date")
-        val releaseDate: Date
+        val releaseDate: Date?
 
 ) : DisplayableMediaMetadata {
     override fun getDescription(): String = summary
diff --git a/vlc-android/src/org/videolan/vlc/repository/MediaMetadataRepository.kt b/vlc-android/src/org/videolan/vlc/repository/MediaMetadataRepository.kt
index 6ce4e6991..c7461c5ba 100644
--- a/vlc-android/src/org/videolan/vlc/repository/MediaMetadataRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/MediaMetadataRepository.kt
@@ -93,5 +93,7 @@ class MediaMetadataRepository(private val mediaMetadataFullDao: MediaMetadataDat
         return mediaTvshowDao.getAllPaged(query)
     }
 
+    fun getTvshow(showId: String) = mediaTvshowDao.find(showId)
+
     companion object : SingletonHolder<MediaMetadataRepository, Context>({ MediaMetadataRepository(MediaDatabase.getInstance(it).mediaMedataDataFullDao(), MediaDatabase.getInstance(it).mediaMetadataDao(), MediaDatabase.getInstance(it).mediaImageDao(), MediaDatabase.getInstance(it).mediaTvshowDao()) })
 }
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt b/vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt
index 2fb5fe97a..c542abbdc 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt
+++ b/vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt
@@ -37,21 +37,17 @@ import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
 import org.videolan.vlc.BuildConfig
 import org.videolan.vlc.database.models.*
 import org.videolan.vlc.moviepedia.models.identify.*
-import org.videolan.vlc.moviepedia.models.media.cast.CastResult
 import org.videolan.vlc.moviepedia.models.media.cast.image
 import org.videolan.vlc.repository.MediaMetadataRepository
 import org.videolan.vlc.repository.MediaPersonRepository
 import org.videolan.vlc.repository.MoviepediaApiRepository
 import org.videolan.vlc.repository.PersonRepository
 import org.videolan.vlc.util.getLocaleLanguages
-import java.util.*
-import kotlin.collections.ArrayList
 
 class MoviepediaModel : ViewModel() {
 
     val apiResult: MutableLiveData<IdentifyResult> = MutableLiveData()
-    val mediaResult: MutableLiveData<Media> = MutableLiveData()
-    val mediaCastResult: MutableLiveData<CastResult> = MutableLiveData()
+    private val mediaResult: MutableLiveData<Media> = MutableLiveData()
     private val repo = MoviepediaApiRepository.getInstance()
     private var searchJob: Job? = null
         set(value) {
@@ -94,8 +90,13 @@ class MoviepediaModel : ViewModel() {
 
             val show = when (item.mediaType) {
                 MediaType.TV_EPISODE -> {
-                    //todo moviepedia we have to add an API call to retrieve more TV Show info
-                    val show = MediaTvshow(item.showId, item.showTitle, "", "", Date())
+                    //check if show already exists
+                    mediaMetadataRepository.getTvshow(item.showId)?.moviepediaShowId
+                    //show doesn't exist, let's retrieve it
+                    val tvShowResult = repo.getMedia(item.showId)
+                    val show = MediaTvshow(item.showId, item.showTitle, tvShowResult.summary
+                            ?: "", tvShowResult.getImageUri(context.getLocaleLanguages())?.toString()
+                            ?: "", tvShowResult.date)
                     mediaMetadataRepository.insertShow(show)
                     show.moviepediaShowId
                 }



More information about the Android mailing list