Skip to content

Commit

Permalink
Add vector to MediaComposition call. (#220)
Browse files Browse the repository at this point in the history
Co-authored-by: Walid Kayhal <[email protected]>
  • Loading branch information
StaehliJ and waliid authored Aug 23, 2023
1 parent 830630a commit 5e48aa3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package ch.srgssr.pillarbox.core.business.integrationlayer.service

import android.content.Context
import ch.srgssr.pillarbox.core.business.integrationlayer.data.MediaComposition
import ch.srgssr.pillarbox.core.business.integrationlayer.service.Vector.getVector
import okhttp3.Cache
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand All @@ -20,15 +21,22 @@ import java.util.concurrent.TimeUnit
/**
* Implementation of MediaCompositionDataSource using integration layer.
*
* @property mediaCompositionService
* @property mediaCompositionService MediaCompositionService implementation.
* @property vector The distribution vector. see [Vector.getVector].
*/
class MediaCompositionDataSourceImpl(private val mediaCompositionService: MediaCompositionService) : MediaCompositionDataSource {
constructor(host: URL, okHttpClient: OkHttpClient) : this(createMediaCompositionService(host, okHttpClient))
constructor(context: Context, host: URL) : this(host, createOkHttpClient(context))
class MediaCompositionDataSourceImpl(
private val mediaCompositionService: MediaCompositionService,
private val vector: String = DEFAULT_VECTOR
) : MediaCompositionDataSource {
constructor(host: URL, okHttpClient: OkHttpClient, vector: String = DEFAULT_VECTOR) :
this(createMediaCompositionService(host, okHttpClient), vector)

constructor(context: Context, host: URL, vector: String = context.getVector()) :
this(host, createOkHttpClient(context), vector)

override suspend fun getMediaCompositionByUrn(urn: String): RemoteResult<MediaComposition> {
return try {
val result = mediaCompositionService.getMediaCompositionByUrn(urn, true)
val result = mediaCompositionService.getMediaCompositionByUrn(urn = urn, vector = vector, onlyChapters = true)
RemoteResult.Success(result)
} catch (e: HttpException) {
RemoteResult.Error(e, e.code())
Expand All @@ -42,6 +50,7 @@ class MediaCompositionDataSourceImpl(private val mediaCompositionService: MediaC
private var CONNECT_TIMEOUT_SECONDS: Long = 60L
private var DEFAULT_CACHE_DIR = "il_cache"
private var DEFAULT_CACHE_MAX_SIZE = 2 * 1024 * 1024L
private const val DEFAULT_VECTOR = Vector.MOBILE

private fun createMediaCompositionService(ilHost: URL, okHttpClient: OkHttpClient): MediaCompositionService {
return Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ interface MediaCompositionService {
*
* @param urn Urn of the content.
* @param onlyChapters Only chapters, no segments are delivered.
* @param vector Distribution vector.
*/
@GET("integrationlayer/2.1/mediaComposition/byUrn/{urn}")
suspend fun getMediaCompositionByUrn(@Path("urn") urn: String, @Query("onlyChapters") onlyChapters: Boolean = true): MediaComposition
suspend fun getMediaCompositionByUrn(
@Path("urn") urn: String,
@Query("onlyChapters") onlyChapters: Boolean = true,
@Query("vector") vector: String = Vector.MOBILE
): MediaComposition
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2023. SRG SSR. All rights reserved.
* License information is available from the LICENSE file.
*/
package ch.srgssr.pillarbox.core.business.integrationlayer.service

import android.content.Context
import android.content.res.Configuration

/**
* Vector
*/
object Vector {
/**
* TV vector
*/
const val TV = "TVPLAY"

/**
* Mobile vector
*/
const val MOBILE = "APPPLAY"

/**
* Get vector
*
* @return vector for MediaCompositionService.
*/
fun Context.getVector(): String {
val uiMode = resources.configuration.uiMode
return if (uiMode and Configuration.UI_MODE_TYPE_MASK == Configuration.UI_MODE_TYPE_TELEVISION) {
TV
} else {
MOBILE
}
}
}

0 comments on commit 5e48aa3

Please sign in to comment.