[Android] Upgrade Room and Retrofit
Geoffrey Métais
git at videolan.org
Fri Jun 14 12:14:52 CEST 2019
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Jun 14 11:07:31 2019 +0200| [20d651adf0942d0387d6b98d8a26485fd632b27c] | committer: Geoffrey Métais
Upgrade Room and Retrofit
> https://code.videolan.org/videolan/vlc-android/commit/20d651adf0942d0387d6b98d8a26485fd632b27c
---
build.gradle | 6 +--
.../org/videolan/vlc/api/IOpenSubtitleService.kt | 5 +-
.../vlc/repository/OpenSubtitleRepository.kt | 57 ++++++----------------
3 files changed, 21 insertions(+), 47 deletions(-)
diff --git a/build.gradle b/build.gradle
index ddc5e5a05..9bb476c64 100644
--- a/build.gradle
+++ b/build.gradle
@@ -34,19 +34,19 @@ ext {
minSdkVersion = 17
targetSdkVersion = 28
compileSdkVersion = 28
- androidxCoreVersion = '1.0.1'
+ androidxCoreVersion = '1.0.2'
androidxPreferencesVersion = '1.0.0'
androidxVersion = '1.0.0'
androidxAnnotationVersion = '1.0.1'
androidxAppcompatVersion = '1.0.2'
constraintLayoutVersion = '1.1.3'
archVersion = '2.0.0'
- roomVersion = '2.0.0'
+ roomVersion = '2.1.0'
pagingVersion = '2.1.0'
junitVersion = '4.12'
mockito = '2.8.9'
powerMock = '1.7.4'
- retrofit = '2.4.0'
+ retrofit = '2.6.0'
espressoVersion = '3.1.1'
supportTest = '1.1.0'
// versionCode scheme is T M NN RR AA
diff --git a/vlc-android/src/org/videolan/vlc/api/IOpenSubtitleService.kt b/vlc-android/src/org/videolan/vlc/api/IOpenSubtitleService.kt
index 46dc1a161..cb92f191e 100644
--- a/vlc-android/src/org/videolan/vlc/api/IOpenSubtitleService.kt
+++ b/vlc-android/src/org/videolan/vlc/api/IOpenSubtitleService.kt
@@ -1,20 +1,19 @@
package org.videolan.vlc.api
-import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path
//Passing 0 for numbers and "" for strings ignores that parameters
interface IOpenSubtitleService {
@GET("episode-{episode}/imdbid-{imdbId}/moviebytesize-{movieByteSize}/moviehash-{movieHash}/query-{name}/season-{season}/sublanguageid-{subLanguageId}/tag_{tag}")
- fun query( @Path("movieByteSize") movieByteSize: String = "",
+ suspend fun query( @Path("movieByteSize") movieByteSize: String = "",
@Path("movieHash") movieHash: String = "",
@Path("name") name: String = "",
@Path("imdbId") imdbId: String = "" ,
@Path("tag") tag: String = "",
@Path("episode") episode: Int = 0,
@Path("season") season: Int = 0,
- @Path("subLanguageId") languageId: String = ""): Call<List<OpenSubtitle>>
+ @Path("subLanguageId") languageId: String = ""): List<OpenSubtitle>
}
diff --git a/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt b/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt
index 3fcd82195..9c9b84bf6 100644
--- a/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt
+++ b/vlc-android/src/org/videolan/vlc/repository/OpenSubtitleRepository.kt
@@ -3,12 +3,6 @@ package org.videolan.vlc.repository
import org.videolan.vlc.api.IOpenSubtitleService
import org.videolan.vlc.api.OpenSubtitle
import org.videolan.vlc.api.OpenSubtitleClient
-import retrofit2.Call
-import retrofit2.Callback
-import retrofit2.Response
-import kotlin.coroutines.resume
-import kotlin.coroutines.resumeWithException
-import kotlin.coroutines.suspendCoroutine
class OpenSubtitleRepository(private val openSubtitleService: IOpenSubtitleService) {
@@ -24,31 +18,31 @@ class OpenSubtitleRepository(private val openSubtitleService: IOpenSubtitleServi
val actualSeason = season ?: 0
val actualLanguageId = languageId ?: ""
val actualTag = tag ?: ""
- return retrofitResponseCall { openSubtitleService.query(
+ return openSubtitleService.query(
imdbId = String.format("%07d", imdbId),
tag = actualTag,
episode = actualEpisode,
season = actualSeason,
- languageId = actualLanguageId) }
+ languageId = actualLanguageId)
}
suspend fun queryWithHash(movieByteSize: Long, movieHash: String, languageId: String?): List<OpenSubtitle> {
val actualLanguageId = languageId ?: ""
- return retrofitResponseCall { openSubtitleService.query(
+ return openSubtitleService.query(
movieByteSize = movieByteSize.toString(),
movieHash = movieHash,
- languageId = actualLanguageId) }
+ languageId = actualLanguageId)
}
suspend fun queryWithName(name: String, episode: Int?, season: Int?, languageId: String?): List<OpenSubtitle> {
val actualEpisode = episode ?: 0
val actualSeason = season ?: 0
val actualLanguageId = languageId ?: ""
- return retrofitResponseCall { openSubtitleService.query(
+ return openSubtitleService.query(
name = name,
episode = actualEpisode,
season = actualSeason,
- languageId = actualLanguageId) }
+ languageId = actualLanguageId)
}
suspend fun queryWithImdbid(imdbId: Int, tag: String?, episode: Int? , season: Int?, languageIds: List<String>? ): List<OpenSubtitle> {
@@ -57,24 +51,21 @@ class OpenSubtitleRepository(private val openSubtitleService: IOpenSubtitleServi
val actualLanguageIds = languageIds?.toSet()?.run { if (contains("") || isEmpty()) setOf("") else this } ?: setOf("")
val actualTag = tag ?: ""
return actualLanguageIds.flatMap {
- retrofitResponseCall { openSubtitleService.query(
+ openSubtitleService.query(
imdbId = String.format("%07d", imdbId),
tag = actualTag,
episode = actualEpisode,
season = actualSeason,
languageId = it) }
- }
}
suspend fun queryWithHash(movieByteSize: Long, movieHash: String?, languageIds: List<String>?): List<OpenSubtitle> {
val actualLanguageIds = languageIds?.toSet()?.run { if (contains("") || isEmpty()) setOf("") else this } ?: setOf("")
return actualLanguageIds.flatMap {
- retrofitResponseCall {
- openSubtitleService.query(
- movieByteSize = movieByteSize.toString(),
- movieHash = movieHash ?: "",
- languageId = it)
- }
+ openSubtitleService.query(
+ movieByteSize = movieByteSize.toString(),
+ movieHash = movieHash ?: "",
+ languageId = it)
}
}
@@ -83,29 +74,13 @@ class OpenSubtitleRepository(private val openSubtitleService: IOpenSubtitleServi
val actualSeason = season ?: 0
val actualLanguageIds = languageIds?.toSet()?.run { if (contains("") || isEmpty()) setOf("") else this } ?: setOf("")
return actualLanguageIds.flatMap {
- retrofitResponseCall {
- openSubtitleService.query(
- name = name,
- episode = actualEpisode,
- season = actualSeason,
- languageId = it)
- }
+ openSubtitleService.query(
+ name = name,
+ episode = actualEpisode,
+ season = actualSeason,
+ languageId = it)
}
}
companion object { fun getInstance() = OpenSubtitleRepository(OpenSubtitleClient.instance)}
-
- private suspend inline fun <reified T> retrofitResponseCall(crossinline call: () -> Call<T>) : T {
- with(retrofitSuspendCall(call)) {
- if (isSuccessful) return body()!!
- else throw Exception(message())
- }
- }
-
- private suspend inline fun <reified T> retrofitSuspendCall(crossinline call: () -> Call<T>) : Response<T> = suspendCoroutine { continuation ->
- call.invoke().enqueue(object : Callback<T> {
- override fun onResponse(call: Call<T>?, response: Response<T>) = continuation.resume(response)
- override fun onFailure(call: Call<T>, t: Throwable) = continuation.resumeWithException(t)
- })
- }
}
More information about the Android
mailing list