[Android] Code cleanup

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


vlc-android | branch: master | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Mon Nov 18 08:23:04 2019 +0100| [bcd36d02beb958e7e355abe283eb160785378332] | committer: Geoffrey Métais

Code cleanup

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

 .../org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt  |  8 +++++---
 .../videolan/vlc/repository/MediaPersonRepository.kt | 20 +-------------------
 .../vlc/repository/MoviepediaApiRepository.kt        |  2 +-
 3 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt b/vlc-android/src/org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt
index 7ed00e8e1..ea9b406a5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt
@@ -89,14 +89,16 @@ class MoviepediaTvFragment : SearchSupportFragment(), SearchSupportFragment.Sear
         if (Intent.ACTION_SEARCH == intent.action || "com.google.android.gms.actions.SEARCH_ACTION" == intent.action)
             onQueryTextSubmit(intent.getStringExtra(SearchManager.QUERY))
 
-        media = arguments!!.getParcelable(MoviepediaTvActivity.MEDIA)!!
+        val extras = requireActivity().intent.extras ?: savedInstanceState ?: return
+        media = extras.getParcelable(MoviepediaTvActivity.MEDIA) ?: return
 
         viewModel = ViewModelProviders.of(this).get(media.uri.path
                 ?: "", MoviepediaModel::class.java)
+        val cp = CardPresenter(requireActivity(), true)
+        val videoAdapter = ArrayObjectAdapter(cp)
         viewModel.apiResult.observe(this, Observer {
-            val cp = CardPresenter(requireActivity(), true)
-            val videoAdapter = ArrayObjectAdapter(cp)
             val medias = it.getAllResults()
+            videoAdapter.clear()
             videoAdapter.addAll(0, medias)
             rowsAdapter.add(ListRow(HeaderItem(0, resources.getString(R.string.moviepedia_result)), videoAdapter))
             updateEmptyView(medias.isEmpty())
diff --git a/vlc-android/src/org/videolan/vlc/repository/MediaPersonRepository.kt b/vlc-android/src/org/videolan/vlc/repository/MediaPersonRepository.kt
index b78c297eb..f001ffa95 100644
--- a/vlc-android/src/org/videolan/vlc/repository/MediaPersonRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/MediaPersonRepository.kt
@@ -50,7 +50,6 @@ import org.videolan.tools.IOScopedObject
 import org.videolan.tools.SingletonHolder
 import org.videolan.vlc.database.MediaDatabase
 import org.videolan.vlc.database.MediaPersonJoinDao
-import org.videolan.vlc.database.models.MediaMetadata
 import org.videolan.vlc.database.models.MediaPersonJoin
 import org.videolan.vlc.database.models.Person
 import org.videolan.vlc.database.models.PersonType
@@ -63,27 +62,10 @@ class MediaPersonRepository(private val mediaPersonActorJoinDao: MediaPersonJoin
     fun getAll() =
             mediaPersonActorJoinDao.getAll()
 
-    fun getPersons(metadata: MediaMetadata): MediaPersons {
-        return MediaPersons(
-                mediaPersonActorJoinDao.getActorsForMedia(metadata.mlId, PersonType.ACTOR),
-                mediaPersonActorJoinDao.getActorsForMedia(metadata.mlId, PersonType.DIRECTOR),
-                mediaPersonActorJoinDao.getActorsForMedia(metadata.mlId, PersonType.MUSICIAN),
-                mediaPersonActorJoinDao.getActorsForMedia(metadata.mlId, PersonType.PRODUCER),
-                mediaPersonActorJoinDao.getActorsForMedia(metadata.mlId, PersonType.WRITER)
-        )
-    }
 
     fun getPersonsByType(mlId: Long, personType: PersonType): LiveData<List<Person>> {
         return mediaPersonActorJoinDao.getActorsForMediaLive(mlId, personType)
     }
 
     companion object : SingletonHolder<MediaPersonRepository, Context>({ MediaPersonRepository(MediaDatabase.getInstance(it).mediaPersonActorJoinDao()) })
-}
-
-data class MediaPersons(
-        val actors: List<Person>,
-        val directors: List<Person>,
-        val musicians: List<Person>,
-        val producers: List<Person>,
-        val writers: List<Person>
-)
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/repository/MoviepediaApiRepository.kt b/vlc-android/src/org/videolan/vlc/repository/MoviepediaApiRepository.kt
index 5f74caca8..1f3ad02b3 100644
--- a/vlc-android/src/org/videolan/vlc/repository/MoviepediaApiRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/MoviepediaApiRepository.kt
@@ -44,7 +44,7 @@ class MoviepediaApiRepository(private val moviepediaApiService: IMoviepediaApiSe
         return moviepediaApiService.searchMedia(scrobbleBody)
     }
 
-    suspend fun searchTitle(title: String) = moviepediaApiService.searchMedia(ScrobbleBody(title = title))
+    suspend fun searchTitle(title: String) = moviepediaApiService.searchMedia(ScrobbleBody(title = title, filename = title))
 
     suspend fun searchMedia(query: ScrobbleBody) = moviepediaApiService.searchMedia(query)
 



More information about the Android mailing list