Skip to content

Commit

Permalink
Trailers: add trailer button to add show dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Nov 16, 2023
1 parent 1bc17da commit 7993945
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.battlelancer.seriesguide.ui.OverviewActivity
import com.battlelancer.seriesguide.ui.dialogs.L10nDialogFragment
import com.battlelancer.seriesguide.util.ImageTools
import com.battlelancer.seriesguide.util.LanguageTools
import com.battlelancer.seriesguide.util.ServiceUtils
import com.battlelancer.seriesguide.util.TextTools
import com.battlelancer.seriesguide.util.TimeTools
import com.battlelancer.seriesguide.util.ViewTools
Expand Down Expand Up @@ -152,6 +153,17 @@ class AddShowDialogFragment : AppCompatDialogFragment() {
this.binding?.textViewAddDescription?.isGone = false
populateShowViews(show)
}
model.trailer.observe(this) { videoId ->
this.binding?.buttonAddTrailer?.apply {
if (videoId != null) {
setOnClickListener { ServiceUtils.openYoutube(videoId, requireContext()) }
isEnabled = true
} else {
setOnClickListener(null)
isEnabled = false
}
}
}
model.watchProvider.observe(this) { watchInfo ->
this.binding?.buttonAddStreamingSearch?.let {
val providerInfo = StreamingSearch.configureButton(it, watchInfo, false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.battlelancer.seriesguide.SgApp
import com.battlelancer.seriesguide.shows.database.SgShow2
import com.battlelancer.seriesguide.shows.tools.GetShowTools.GetShowError.GetShowDoesNotExist
import com.battlelancer.seriesguide.streaming.StreamingSearch
import com.battlelancer.seriesguide.tmdbapi.TmdbTools2
import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.onSuccess
import kotlinx.coroutines.Dispatchers
Expand All @@ -35,6 +36,7 @@ class AddShowDialogViewModel(

val languageCode = MutableLiveData<String>()
val showDetails: LiveData<ShowDetails>
val trailer: LiveData<String?>

init {
// Set original value for region.
Expand Down Expand Up @@ -66,6 +68,12 @@ class AddShowDialogViewModel(
}
}
}
this.trailer = languageCode.switchMap { languageCode ->
liveData(context = viewModelScope.coroutineContext + Dispatchers.IO) {
TmdbTools2().getShowTrailerYoutubeId(application, showTmdbId, languageCode)
.onSuccess { emit(it) }
}
}
}

private val watchInfoMediator = MediatorLiveData<StreamingSearch.WatchInfo>().apply {
Expand Down
23 changes: 20 additions & 3 deletions app/src/main/res/layout/dialog_addshow.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- Copyright 2023 Uwe Trottmann -->
<!-- SPDX-License-Identifier: Apache-2.0 -->

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
Expand Down Expand Up @@ -76,12 +80,25 @@

</RelativeLayout>

<Button
android:id="@+id/buttonAddTrailer"
style="@style/Widget.SeriesGuide.Button.Outlined"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/containerShowInfo"
android:layout_marginLeft="@dimen/default_padding"
android:layout_marginTop="@dimen/default_padding"
android:layout_marginRight="@dimen/default_padding"
android:text="@string/trailer"
app:icon="@drawable/ic_movie_white_24dp"
app:iconGravity="start" />

<Button
android:id="@+id/buttonAddLanguage"
style="@style/Widget.SeriesGuide.Button.Borderless.Default"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/containerShowInfo"
android:layout_below="@+id/buttonAddTrailer"
android:layout_marginLeft="@dimen/default_padding"
android:layout_marginTop="@dimen/default_padding"
android:layout_marginRight="@dimen/default_padding"
Expand Down Expand Up @@ -178,9 +195,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonAddDisplaySimilar"
android:maxWidth="@dimen/max_width_text_size_body"
android:layout_marginStart="@dimen/default_padding"
android:layout_marginEnd="@dimen/default_padding">
android:layout_marginEnd="@dimen/default_padding"
android:maxWidth="@dimen/max_width_text_size_body">

<!-- MaterialButton ignores line breaks here (wtf?), so use separate TextView. -->
<Button
Expand Down

0 comments on commit 7993945

Please sign in to comment.