Add seasons to the MediaInfoFragment

This commit is contained in:
Jarne Demeulemeester 2021-06-24 11:53:13 +02:00
parent 71ae0a886a
commit 2ce0755cf3
No known key found for this signature in database
GPG key ID: 60884A0C1EBA43E5
5 changed files with 48 additions and 0 deletions

View file

@ -31,6 +31,7 @@ class JellyfinApi(context: Context, baseUrl: String) {
val viewsApi = UserViewsApi(api)
val itemsApi = ItemsApi(api)
val userLibraryApi = UserLibraryApi(api)
val showsApi = TvShowsApi(api)
companion object {
@Volatile

View file

@ -8,6 +8,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.navigation.fragment.navArgs
import dev.jdtech.jellyfin.adapters.PersonListAdapter
import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
import dev.jdtech.jellyfin.viewmodels.MediaInfoViewModel
import dev.jdtech.jellyfin.databinding.FragmentMediaInfoBinding
import dev.jdtech.jellyfin.viewmodels.MediaInfoViewModelFactory
@ -45,6 +46,7 @@ class MediaInfoFragment : Fragment() {
}
})
binding.seasonsRecyclerView.adapter = ViewItemListAdapter(ViewItemListAdapter.OnClickListener {}, fixedWidth = true)
binding.peopleRecyclerView.adapter = PersonListAdapter()
}

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 _seasons = MutableLiveData<List<BaseItemDto>>()
val seasons: LiveData<List<BaseItemDto>> = _seasons
init {
viewModelScope.launch {
_item.value = getItemDetails(itemId)
@ -53,6 +56,9 @@ class MediaInfoViewModel(application: Application, itemId: UUID) : AndroidViewMo
_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") {
_seasons.value = getSeasons(itemId)
}
}
}
@ -64,6 +70,14 @@ class MediaInfoViewModel(application: Application, itemId: UUID) : AndroidViewMo
return item
}
private suspend fun getSeasons(itemId: UUID): List<BaseItemDto>? {
val seasons: List<BaseItemDto>?
withContext(Dispatchers.IO) {
seasons = jellyfinApi.showsApi.getSeasons(itemId, jellyfinApi.userId!!).content.items
}
return seasons
}
private suspend fun getActors(item: BaseItemDto): List<BaseItemPerson>? {
val actors: List<BaseItemPerson>?
withContext(Dispatchers.Default) {

View file

@ -181,6 +181,36 @@
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:layout_marginBottom="24dp"
android:visibility="@{viewModel.seasons != null ? View.VISIBLE : View.GONE}"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
android:layout_marginBottom="12dp"
android:text="@string/seasons"
android:textAppearance="@style/TextAppearance.MaterialComponents.Subtitle1"
android:textSize="18sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/seasons_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:orientation="horizontal"
android:paddingHorizontal="12dp"
app:items="@{viewModel.seasons}"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:itemCount="3"
tools:listitem="@layout/base_item" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"

View file

@ -25,4 +25,5 @@
<string name="director">Director</string>
<string name="writers">Writers</string>
<string name="cast_amp_crew"><![CDATA[Cast & Crew]]></string>
<string name="seasons">Seasons</string>
</resources>