[Android] Move MoviepediaViewModel to related module
Geoffrey Métais
git at videolan.org
Fri Dec 27 12:17:02 CET 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Dec 26 15:47:25 2019 +0100| [253e9a43e33665a56a6ea962e3238f43d84b6c5e] | committer: Geoffrey Métais
Move MoviepediaViewModel to related module
> https://code.videolan.org/videolan/vlc-android/commit/253e9a43e33665a56a6ea962e3238f43d84b6c5e
---
moviepedia/build.gradle | 1 +
.../videolan/moviepedia/MoviepediaApiService.kt | 2 +-
.../org/videolan/moviepedia/MoviepediaIndexer.kt | 54 +++++++++++-----------
.../moviepedia/viewmodel}/MoviepediaModel.kt | 2 +-
tools/build.gradle | 1 +
.../src/org/videolan/vlc/gui/MoviepediaActivity.kt | 2 +-
.../videolan/vlc/gui/tv/MoviepediaTvFragment.kt | 2 +-
7 files changed, 32 insertions(+), 32 deletions(-)
diff --git a/moviepedia/build.gradle b/moviepedia/build.gradle
index e0b48247d..1fd257c87 100644
--- a/moviepedia/build.gradle
+++ b/moviepedia/build.gradle
@@ -34,6 +34,7 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.ext.kotlinx_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.ext.kotlinx_version"
implementation "androidx.paging:paging-runtime-ktx:$rootProject.ext.pagingVersion"
+ implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.ext.lifecycleVersion"
//Room
implementation "androidx.room:room-runtime:$rootProject.ext.roomVersion"
diff --git a/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaApiService.kt b/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaApiService.kt
index d4e42b35c..4437ff72a 100644
--- a/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaApiService.kt
+++ b/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaApiService.kt
@@ -38,7 +38,7 @@ import java.util.concurrent.TimeUnit
private const val USER_AGENT = "VLC-Android"
-private fun buildClient() =
+private fun buildClient(): IMoviepediaApiService =
Retrofit.Builder()
.baseUrl(BuildConfig.MOVIEPEDIA_API_URL)
.client(OkHttpClient.Builder()
diff --git a/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaIndexer.kt b/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaIndexer.kt
index d785f56f4..b52956684 100644
--- a/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaIndexer.kt
+++ b/moviepedia/src/main/java/org/videolan/moviepedia/MoviepediaIndexer.kt
@@ -43,36 +43,34 @@ import org.videolan.tools.getLocaleLanguages
object MoviepediaIndexer : CoroutineScope by MainScope() {
- fun indexMedialib(context: Context) {
- launch(Dispatchers.IO) {
- val medias = Medialibrary.getInstance().getPagedVideos(Medialibrary.SORT_DEFAULT, false, 1000, 0)
-
- val filesToIndex = HashMap<Long, Uri>()
- medias.forEach {
- if (it.getMetaLong(MediaWrapper.META_METADATA_RETRIEVED) != 1L)
- filesToIndex[it.id] = it.uri
- }
- val repo = MoviepediaApiRepository.getInstance()
- val results = try {
- repo.searchMediaBatch(filesToIndex)
- } catch (e: Exception) {
- return at launch
- }
- medias.forEach { media ->
- media?.setLongMeta(MediaWrapper.META_METADATA_RETRIEVED, 1L)
- }
- results.forEach { result ->
- result.lucky?.let {
- val media = medias.find { it.id == result.id.toLong() }
- try {
- saveMediaMetadata(context, media, it, retrieveCast = false, removePersonOrphans = false)
- } catch (e: Exception) {
- media?.setLongMeta(251, 0L)
- }
+ fun indexMedialib(context: Context) = launch(Dispatchers.IO) {
+ val medias = Medialibrary.getInstance().getPagedVideos(Medialibrary.SORT_DEFAULT, false, 1000, 0)
+
+ val filesToIndex = HashMap<Long, Uri>()
+ medias.forEach {
+ if (it.getMetaLong(MediaWrapper.META_METADATA_RETRIEVED) != 1L)
+ filesToIndex[it.id] = it.uri
+ }
+ val repo = MoviepediaApiRepository.getInstance()
+ val results = try {
+ repo.searchMediaBatch(filesToIndex)
+ } catch (e: Exception) {
+ return at launch
+ }
+ medias.forEach { media ->
+ media?.setLongMeta(MediaWrapper.META_METADATA_RETRIEVED, 1L)
+ }
+ results.forEach { result ->
+ result.lucky?.let {
+ val media = medias.find { it.id == result.id.toLong() }
+ try {
+ saveMediaMetadata(context, media, it, retrieveCast = false, removePersonOrphans = false)
+ } catch (e: Exception) {
+ media?.setLongMeta(251, 0L)
}
}
- removePersonOrphans(context)
}
+ removePersonOrphans(context)
}
private fun removePersonOrphans(context: Context) {
@@ -185,4 +183,4 @@ object MoviepediaIndexer : CoroutineScope by MainScope() {
mediaMetadata.hasCast = true
MediaMetadataRepository.getInstance(context).addMetadataImmediate(mediaMetadata)
}
-}
\ No newline at end of file
+}
diff --git a/vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt b/moviepedia/src/main/java/org/videolan/moviepedia/viewmodel/MoviepediaModel.kt
similarity index 98%
rename from vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt
rename to moviepedia/src/main/java/org/videolan/moviepedia/viewmodel/MoviepediaModel.kt
index 7b9f366f1..adb15a59d 100644
--- a/vlc-android/src/org/videolan/vlc/viewmodels/MoviepediaModel.kt
+++ b/moviepedia/src/main/java/org/videolan/moviepedia/viewmodel/MoviepediaModel.kt
@@ -22,7 +22,7 @@
*
*/
-package org.videolan.vlc.viewmodels
+package org.videolan.moviepedia.viewmodel
import android.net.Uri
import androidx.lifecycle.MutableLiveData
diff --git a/tools/build.gradle b/tools/build.gradle
index b5fa04951..e609c8096 100644
--- a/tools/build.gradle
+++ b/tools/build.gradle
@@ -25,6 +25,7 @@ android {
dependencies {
api "androidx.appcompat:appcompat:$rootProject.ext.androidxAppcompatVersion"
+ implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.ext.archVersion"
api "androidx.tvprovider:tvprovider:$rootProject.ext.androidxLeanbackVersion"
implementation("com.squareup.okhttp3:logging-interceptor:4.2.1")
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
diff --git a/vlc-android/src/org/videolan/vlc/gui/MoviepediaActivity.kt b/vlc-android/src/org/videolan/vlc/gui/MoviepediaActivity.kt
index 608ac1cf9..33c0059df 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MoviepediaActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/MoviepediaActivity.kt
@@ -42,7 +42,7 @@ import org.videolan.vlc.gui.helpers.UiTools
import org.videolan.vlc.gui.helpers.applyTheme
import org.videolan.moviepedia.models.identify.Media
import org.videolan.moviepedia.models.identify.getAllResults
-import org.videolan.vlc.viewmodels.MoviepediaModel
+import org.videolan.moviepedia.viewmodel.MoviepediaModel
open class MoviepediaActivity : BaseActivity(), TextWatcher, TextView.OnEditorActionListener {
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 0e6370b6a..95e122947 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/MoviepediaTvFragment.kt
@@ -63,7 +63,7 @@ import org.videolan.moviepedia.MoviepediaIndexer
import org.videolan.moviepedia.models.identify.Media
import org.videolan.moviepedia.models.identify.getAllResults
import org.videolan.vlc.util.manageHttpException
-import org.videolan.vlc.viewmodels.MoviepediaModel
+import org.videolan.moviepedia.viewmodel.MoviepediaModel
private const val TAG = "SearchFragment"
private const val REQUEST_SPEECH = 1
More information about the Android
mailing list