From 1f14416b3d38a9515a48472d4e3c3acdedd3af71 Mon Sep 17 00:00:00 2001 From: Felix Date: Thu, 11 Jun 2020 16:09:15 +0200 Subject: [PATCH] fix differences between free and non free cast services --- .../{CastService.kt => CastServiceImpl.kt} | 15 ++++++++------- .../common/viewmodel/ViewModelFactory.kt | 3 ++- .../chaosflix/touch/browse/cast/CastService.kt | 18 ++++++++++++++++++ .../{CastService.kt => CastServiceImpl.kt} | 16 ++++++++-------- leanback/src/main/AndroidManifest.xml | 1 + 5 files changed, 37 insertions(+), 16 deletions(-) rename common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/{CastService.kt => CastServiceImpl.kt} (57%) create mode 100644 common/src/main/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt rename common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/{CastService.kt => CastServiceImpl.kt} (92%) diff --git a/common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt b/common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/CastServiceImpl.kt similarity index 57% rename from common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt rename to common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/CastServiceImpl.kt index cf39fd53..b263746f 100644 --- a/common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt +++ b/common/src/free/java/de/nicidienase/chaosflix/touch/browse/cast/CastServiceImpl.kt @@ -6,30 +6,31 @@ import androidx.appcompat.app.AppCompatActivity import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording import de.nicidienase.chaosflix.common.mediadata.entities.streaming.StreamUrl +import de.nicidienase.chaosflix.common.userdata.entities.progress.PlaybackProgress import de.nicidienase.chaosflix.touch.browse.streaming.StreamingItem @SuppressWarnings("unused") -class CastService { +class CastServiceImpl : CastService { - val connected: Boolean = false + override val connected: Boolean = false - fun castStream(streamingItem: StreamingItem, streamUrl: StreamUrl, contentKey: String) { + override fun castStream(streamingItem: StreamingItem, streamUrl: StreamUrl, contentKey: String) { Log.e(TAG, "No Cast Support") } - fun loadMediaAndPlay(recording: Recording, event: Event) { + override fun loadMediaAndPlay(recording: Recording, event: Event, progress: PlaybackProgress?) { Log.e(TAG, "No Cast Support") } - fun addMediaRouteMenuItem(menu: Menu) { + override fun addMediaRouteMenuItem(menu: Menu) { Log.i(TAG, "No Cast Support, adding no Menu item") } - fun attachToActivity(activity: AppCompatActivity) { + override fun attachToActivity(activity: AppCompatActivity) { Log.i(TAG, "No Cast Support, doing nothing") } companion object { - val TAG = CastService::class.java.simpleName + private val TAG = CastServiceImpl::class.java.simpleName + "Free" } } diff --git a/common/src/main/java/de/nicidienase/chaosflix/common/viewmodel/ViewModelFactory.kt b/common/src/main/java/de/nicidienase/chaosflix/common/viewmodel/ViewModelFactory.kt index 7c020cab..03ab2fc8 100644 --- a/common/src/main/java/de/nicidienase/chaosflix/common/viewmodel/ViewModelFactory.kt +++ b/common/src/main/java/de/nicidienase/chaosflix/common/viewmodel/ViewModelFactory.kt @@ -16,6 +16,7 @@ import de.nicidienase.chaosflix.common.mediadata.StreamingRepository import de.nicidienase.chaosflix.common.mediadata.ThumbnailParser import de.nicidienase.chaosflix.common.mediadata.network.ApiFactory import de.nicidienase.chaosflix.touch.browse.cast.CastService +import de.nicidienase.chaosflix.touch.browse.cast.CastServiceImpl import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -40,7 +41,7 @@ class ViewModelFactory private constructor(context: Context) : ViewModelProvider private val externalFilesDir = Environment.getExternalStorageDirectory() private val resourcesFacade by lazy { ResourcesFacade(context) } private val thumbnailParser by lazy { ThumbnailParser(apiFactory.client) } - private val castService: CastService by lazy { CastService(database.playbackProgressDao(), coroutineScope) } + private val castService: CastService by lazy { CastServiceImpl(database.playbackProgressDao(), coroutineScope) } val mediaRepository by lazy { MediaRepository(apiFactory.recordingApi, database) } @Suppress("UNCHECKED_CAST") diff --git a/common/src/main/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt b/common/src/main/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt new file mode 100644 index 00000000..10238247 --- /dev/null +++ b/common/src/main/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt @@ -0,0 +1,18 @@ +package de.nicidienase.chaosflix.touch.browse.cast + +import android.view.Menu +import androidx.appcompat.app.AppCompatActivity +import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Event +import de.nicidienase.chaosflix.common.mediadata.entities.recording.persistence.Recording +import de.nicidienase.chaosflix.common.mediadata.entities.streaming.StreamUrl +import de.nicidienase.chaosflix.common.userdata.entities.progress.PlaybackProgress +import de.nicidienase.chaosflix.touch.browse.streaming.StreamingItem + +interface CastService { + val connected: Boolean + + fun attachToActivity(activity: AppCompatActivity) + fun castStream(streamingItem: StreamingItem, streamUrl: StreamUrl, contentKey: String) + fun loadMediaAndPlay(recording: Recording, event: Event, progress: PlaybackProgress?) + fun addMediaRouteMenuItem(menu: Menu) +} diff --git a/common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt b/common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/CastServiceImpl.kt similarity index 92% rename from common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt rename to common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/CastServiceImpl.kt index 6b52f3f1..9a414120 100644 --- a/common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/CastService.kt +++ b/common/src/noFree/java/de/nicidienase/chaosflix/touch/browse/cast/CastServiceImpl.kt @@ -24,18 +24,18 @@ import kotlinx.coroutines.launch import pl.droidsonroids.casty.Casty import pl.droidsonroids.casty.MediaData -class CastService( +class CastServiceImpl( private val playbackProgressDao: PlaybackProgressDao, private val scope: CoroutineScope -) : LifecycleObserver { +) : LifecycleObserver, CastService { private var currentEvent: Event? = null private var casty: Casty? = null - val connected: Boolean + override val connected: Boolean get() = casty?.isConnected ?: false - fun attachToActivity(activity: AppCompatActivity) { + override fun attachToActivity(activity: AppCompatActivity) { casty = Casty.create(activity) activity.lifecycle.addObserver(this) currentEvent?.let { @@ -48,7 +48,7 @@ class CastService( casty = null } - fun castStream(streamingItem: StreamingItem, streamUrl: StreamUrl, contentKey: String) { + override fun castStream(streamingItem: StreamingItem, streamUrl: StreamUrl, contentKey: String) { casty?.let { val contentType = getContentTypeForKey(contentKey) val mediaData = MediaData.Builder(streamUrl.url) @@ -62,7 +62,7 @@ class CastService( } } - fun loadMediaAndPlay(recording: Recording, event: Event, progress: PlaybackProgress?) { + override fun loadMediaAndPlay(recording: Recording, event: Event, progress: PlaybackProgress?) { Log.d(TAG, "Casting: ${event.title}") currentEvent = event casty?.let { @@ -80,7 +80,7 @@ class CastService( sessionManager?.currentCastSession?.let { sessionListener.attachProgressListener(it) } } - fun addMediaRouteMenuItem(menu: Menu) { + override fun addMediaRouteMenuItem(menu: Menu) { casty?.addMediaRouteMenuItem(menu) } @@ -180,6 +180,6 @@ class CastService( } companion object { - private val TAG = CastService::class.java.simpleName + private val TAG = CastServiceImpl::class.java.simpleName + "NoFree" } } diff --git a/leanback/src/main/AndroidManifest.xml b/leanback/src/main/AndroidManifest.xml index d6809795..26b051fc 100644 --- a/leanback/src/main/AndroidManifest.xml +++ b/leanback/src/main/AndroidManifest.xml @@ -11,6 +11,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" + tools:replace="android:label" tools:ignore="GoogleAppIndexingWarning">