Add "Next up" section to MediaInfoFragment

This commit is contained in:
Jarne Demeulemeester 2021-06-28 21:24:49 +02:00
parent 4329b76448
commit 5ff4ec7e42
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
4 changed files with 79 additions and 3 deletions

View file

@ -146,4 +146,20 @@ fun bindSeasonPoster(imageView: ImageView, seasonId: UUID) {
.transition(DrawableTransitionOptions.withCrossFade())
.placeholder(R.color.neutral_800)
.into(imageView)
}
@BindingAdapter("itemPrimaryImage")
fun bindItemPrimaryImage(imageView: ImageView, item: BaseItemDto?) {
if (item != null) {
val jellyfinApi = JellyfinApi.getInstance(imageView.context.applicationContext, "")
Glide
.with(imageView.context)
.load(jellyfinApi.api.baseUrl.plus("/items/${item.id}/Images/Primary"))
.transition(DrawableTransitionOptions.withCrossFade())
.placeholder(R.color.neutral_800)
.into(imageView)
imageView.contentDescription = "${item.name} poster"
}
}

View file

@ -42,6 +42,9 @@ class MediaInfoViewModel(application: Application, itemId: UUID) : AndroidViewMo
private val _dateString = MutableLiveData<String>()
val dateString: LiveData<String> = _dateString
private val _nextUp = MutableLiveData<BaseItemDto>()
val nextUp: LiveData<BaseItemDto> = _nextUp
private val _seasons = MutableLiveData<List<BaseItemDto>>()
val seasons: LiveData<List<BaseItemDto>> = _seasons
@ -51,12 +54,14 @@ class MediaInfoViewModel(application: Application, itemId: UUID) : AndroidViewMo
_actors.value = getActors(_item.value!!)
_director.value = getDirector(_item.value!!)
_writers.value = getWriters(_item.value!!)
_writersString.value = _writers.value?.joinToString(separator = ", ") { it.name.toString() }
_writersString.value =
_writers.value?.joinToString(separator = ", ") { it.name.toString() }
_genresString.value = _item.value?.genres?.joinToString(separator = ", ")
_runTime.value = "${_item.value?.runTimeTicks?.div(600000000)} min"
_dateString.value = getDateString(_item.value!!)
_item.value!!.status?.let { Log.i("MediaInfoViewModel", it) }
if (_item.value!!.type == "Series") {
_nextUp.value = getNextUp(itemId)
_seasons.value = getSeasons(itemId)
}
}
@ -102,6 +107,24 @@ class MediaInfoViewModel(application: Application, itemId: UUID) : AndroidViewMo
return writers
}
private suspend fun getNextUp(seriesId: UUID): BaseItemDto? {
val nextUpItems: List<BaseItemDto>?
withContext(Dispatchers.IO) {
nextUpItems = jellyfinApi.showsApi.getNextUp(
jellyfinApi.userId!!,
seriesId = seriesId.toString()
).content.items
}
if (nextUpItems != null) {
return if (nextUpItems.isNotEmpty()) {
nextUpItems[0]
} else {
null
}
}
return null
}
private fun getDateString(item: BaseItemDto): String {
val dateString: String = item.productionYear.toString()
return when (item.status) {

View file

@ -31,8 +31,8 @@
android:id="@+id/item_banner"
android:layout_width="match_parent"
android:layout_height="200dp"
app:itemBackdropImage="@{viewModel.item}"
android:scaleType="centerCrop"
app:itemBackdropImage="@{viewModel.item}"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
@ -56,7 +56,7 @@
android:textAppearance="@style/TextAppearance.MaterialComponents.Headline5"
app:layout_constraintBottom_toTopOf="@id/original_title"
app:layout_constraintStart_toStartOf="parent"
tools:text="Alita: Battle Angel"/>
tools:text="Alita: Battle Angel" />
<TextView
android:id="@+id/original_title"
@ -276,6 +276,41 @@
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
tools:text="An angel falls. A warrior rises. When Alita awakens with no memory of who she is in a future world she does not recognize, she is taken in by Ido, a compassionate doctor who realizes that somewhere in this abandoned cyborg shell is the heart and soul of a young woman with an extraordinary past." />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="24dp"
android:visibility="@{viewModel.nextUp != null ? View.VISIBLE : View.GONE}">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="12dp"
android:text="@string/next_up"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textSize="18sp" />
<com.google.android.material.imageview.ShapeableImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="8dp"
app:itemPrimaryImage="@{viewModel.nextUp}"
app:shapeAppearance="@style/roundedImageView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:text="@{String.format(@string/episode_name_extended, viewModel.nextUp.parentIndexNumber, viewModel.nextUp.indexNumber, viewModel.nextUp.name)}"
android:textAppearance="@style/TextAppearance.MaterialComponents.Body1"
tools:text="The Girl Flautist" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -33,4 +33,6 @@
<string name="favorite_button_description">Favorite</string>
<string name="episode_watched_indicator">Episode watched indicator</string>
<string name="episode_name">%1$d. %2$s</string>
<string name="episode_name_extended">S%1$dE%2$d - %3$s</string>
<string name="next_up">Next up</string>
</resources>