implement preferred season/languag choosing in MediaFragment
This commit is contained in:
@ -15,6 +15,7 @@ import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.bumptech.glide.Glide
|
||||
import com.bumptech.glide.request.RequestOptions
|
||||
import com.google.android.material.appbar.AppBarLayout
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
import jp.wasabeef.glide.transformations.BlurTransformation
|
||||
import kotlinx.coroutines.launch
|
||||
import org.mosad.teapod.R
|
||||
@ -56,14 +57,14 @@ class MediaFragment(private val mediaIdStr: String, mediaCr: Item = NoneItem) :
|
||||
// fix material components issue #1878, if more tabs are added increase
|
||||
binding.pagerEpisodesSimilar.offscreenPageLimit = 2
|
||||
binding.pagerEpisodesSimilar.adapter = pagerAdapter
|
||||
// TODO implement for cr media items
|
||||
// TabLayoutMediator(binding.tabEpisodesSimilar, binding.pagerEpisodesSimilar) { tab, position ->
|
||||
// tab.text = if (model.media.type == MediaType.TVSHOW && position == 0) {
|
||||
// getString(R.string.episodes)
|
||||
// } else {
|
||||
// getString(R.string.similar_titles)
|
||||
// }
|
||||
// }.attach()
|
||||
// TODO is position 0 always episodes? (and 1 always similar titles)
|
||||
TabLayoutMediator(binding.tabEpisodesSimilar, binding.pagerEpisodesSimilar) { tab, position ->
|
||||
tab.text = when(position) {
|
||||
0 -> getString(R.string.episodes)
|
||||
1 -> getString(R.string.similar_titles)
|
||||
else -> ""
|
||||
}
|
||||
}.attach()
|
||||
|
||||
lifecycleScope.launch {
|
||||
model.loadCrunchy(mediaIdStr)
|
||||
@ -77,9 +78,10 @@ class MediaFragment(private val mediaIdStr: String, mediaCr: Item = NoneItem) :
|
||||
super.onResume()
|
||||
|
||||
// update the next ep text if there is one, since it may have changed
|
||||
if (model.media.getEpisodeById(model.nextEpisodeId).title.isNotEmpty()) {
|
||||
binding.textTitle.text = model.media.getEpisodeById(model.nextEpisodeId).title
|
||||
}
|
||||
// TODO reimplement
|
||||
// if (model.media.getEpisodeById(model.nextEpisodeId).title.isNotEmpty()) {
|
||||
// binding.textTitle.text = model.media.getEpisodeById(model.nextEpisodeId).title
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,9 +90,9 @@ class MediaFragment(private val mediaIdStr: String, mediaCr: Item = NoneItem) :
|
||||
private fun updateGUI() = with(model) {
|
||||
// generic gui
|
||||
val backdropUrl = tmdbResult?.backdropPath?.let { TMDBApiController.imageUrl + it }
|
||||
?: mediaCrunchy.images.poster_wide[0][2].source
|
||||
?: seriesCrunchy.images.poster_wide[0][2].source
|
||||
val posterUrl = tmdbResult?.posterPath?.let { TMDBApiController.imageUrl + it }
|
||||
?: mediaCrunchy.images.poster_tall[0][2].source
|
||||
?: seriesCrunchy.images.poster_tall[0][2].source
|
||||
|
||||
// load poster and backdrop
|
||||
Glide.with(requireContext()).load(posterUrl)
|
||||
@ -100,65 +102,74 @@ class MediaFragment(private val mediaIdStr: String, mediaCr: Item = NoneItem) :
|
||||
.apply(RequestOptions.bitmapTransform(BlurTransformation(20, 3)))
|
||||
.into(binding.imageBackdrop)
|
||||
|
||||
binding.textTitle.text = mediaCrunchy.title
|
||||
//binding.textYear.text = media.year.toString() // TODO
|
||||
//binding.textAge.text = media.age.toString() // TODO
|
||||
binding.textOverview.text = mediaCrunchy.description
|
||||
binding.textTitle.text = seriesCrunchy.title
|
||||
//binding.textYear.text = media.year.toString() // TODO get from tmdb
|
||||
//binding.textAge.text = media.age.toString() // TODO get from tmdb
|
||||
binding.textOverview.text = seriesCrunchy.description
|
||||
|
||||
// TODO set "my list" indicator
|
||||
if (StorageController.myList.contains(media.aodId)) {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
} else {
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
|
||||
}
|
||||
// if (StorageController.myList.contains(media.aodId)) {
|
||||
// Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
// } else {
|
||||
// Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
|
||||
// }
|
||||
|
||||
// clear fragments, since it lives in onCreate scope (don't do this in onPause/onStop -> FragmentManager transaction)
|
||||
val fragmentsSize = if (fragments.lastIndex < 0) 0 else fragments.lastIndex
|
||||
fragments.clear()
|
||||
pagerAdapter.notifyItemRangeRemoved(0, fragmentsSize)
|
||||
|
||||
// specific gui
|
||||
if (mediaCrunchy.type == MediaType.TVSHOW.str) {
|
||||
// TODO get next episode
|
||||
// nextEpisodeId = media.playlist.firstOrNull{ !it.watched }?.mediaId
|
||||
// ?: media.playlist.first().mediaId
|
||||
|
||||
// TODO title is the next episodes title
|
||||
// binding.textTitle.text = media.getEpisodeById(nextEpisodeId).title
|
||||
|
||||
// episodes count
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_episodes_count,
|
||||
episodesCrunchy.total,
|
||||
episodesCrunchy.total
|
||||
)
|
||||
|
||||
// episodes
|
||||
MediaFragmentEpisodes().also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
} else if (media.type == MediaType.MOVIE) {
|
||||
val tmdbMovie = (tmdbResult as TMDBMovie?)
|
||||
|
||||
if (tmdbMovie?.runtime != null) {
|
||||
binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
R.plurals.text_runtime,
|
||||
tmdbMovie.runtime,
|
||||
tmdbMovie.runtime
|
||||
)
|
||||
} else {
|
||||
binding.textEpisodesOrRuntime.visibility = View.GONE
|
||||
}
|
||||
// add the episodes fragment (as tab)
|
||||
MediaFragmentEpisodes().also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
|
||||
// TODO reimplement via tmdb/metaDB
|
||||
// specific gui
|
||||
// if (mediaCrunchy.type == MediaType.TVSHOW.str) {
|
||||
// // TODO get next episode
|
||||
//// nextEpisodeId = media.playlist.firstOrNull{ !it.watched }?.mediaId
|
||||
//// ?: media.playlist.first().mediaId
|
||||
//
|
||||
// // TODO title is the next episodes title
|
||||
//// binding.textTitle.text = media.getEpisodeById(nextEpisodeId).title
|
||||
//
|
||||
// // episodes count
|
||||
// binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
// R.plurals.text_episodes_count,
|
||||
// episodesCrunchy.total,
|
||||
// episodesCrunchy.total
|
||||
// )
|
||||
//
|
||||
// // episodes
|
||||
// MediaFragmentEpisodes().also {
|
||||
// fragments.add(it)
|
||||
// pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
// }
|
||||
// } else if (media.type == MediaType.MOVIE) {
|
||||
// val tmdbMovie = (tmdbResult as TMDBMovie?)
|
||||
//
|
||||
// if (tmdbMovie?.runtime != null) {
|
||||
// binding.textEpisodesOrRuntime.text = resources.getQuantityString(
|
||||
// R.plurals.text_runtime,
|
||||
// tmdbMovie.runtime,
|
||||
// tmdbMovie.runtime
|
||||
// )
|
||||
// } else {
|
||||
// binding.textEpisodesOrRuntime.visibility = View.GONE
|
||||
// }
|
||||
// }
|
||||
|
||||
// if has similar titles
|
||||
if (media.similar.isNotEmpty()) {
|
||||
MediaFragmentSimilar().also {
|
||||
fragments.add(it)
|
||||
pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
}
|
||||
}
|
||||
// TODO reimplement
|
||||
// if (media.similar.isNotEmpty()) {
|
||||
// MediaFragmentSimilar().also {
|
||||
// fragments.add(it)
|
||||
// pagerAdapter.notifyItemInserted(fragments.indexOf(it))
|
||||
// }
|
||||
// }
|
||||
|
||||
// disable scrolling on appbar, if no tabs where added
|
||||
if(fragments.isEmpty()) {
|
||||
@ -171,28 +182,30 @@ class MediaFragment(private val mediaIdStr: String, mediaCr: Item = NoneItem) :
|
||||
|
||||
private fun initActions() = with(model) {
|
||||
binding.buttonPlay.setOnClickListener {
|
||||
when (media.type) {
|
||||
//MediaType.MOVIE -> playEpisode(media.playlist.first().mediaId) // TODO
|
||||
//MediaType.TVSHOW -> playEpisode(nextEpisodeId) // TODO
|
||||
else -> Log.e(javaClass.name, "Wrong Type: ${media.type}")
|
||||
}
|
||||
// TODO reimplement
|
||||
// when (media.type) {
|
||||
// MediaType.MOVIE -> playEpisode(media.playlist.first().mediaId)
|
||||
// MediaType.TVSHOW -> playEpisode(nextEpisodeId)
|
||||
// else -> Log.e(javaClass.name, "Wrong Type: ${media.type}")
|
||||
// }
|
||||
}
|
||||
|
||||
// add or remove media from myList
|
||||
binding.linearMyListAction.setOnClickListener {
|
||||
if (StorageController.myList.contains(media.aodId)) {
|
||||
StorageController.myList.remove(media.aodId)
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
|
||||
} else {
|
||||
StorageController.myList.add(media.aodId)
|
||||
Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
}
|
||||
StorageController.saveMyList(requireContext())
|
||||
|
||||
// notify home fragment on change
|
||||
parentFragmentManager.findFragmentByTag("HomeFragment")?.let {
|
||||
(it as HomeFragment).updateMyListMedia()
|
||||
}
|
||||
// TODO reimplement
|
||||
// if (StorageController.myList.contains(media.aodId)) {
|
||||
// StorageController.myList.remove(media.aodId)
|
||||
// Glide.with(requireContext()).load(R.drawable.ic_baseline_add_24).into(binding.imageMyListAction)
|
||||
// } else {
|
||||
// StorageController.myList.add(media.aodId)
|
||||
// Glide.with(requireContext()).load(R.drawable.ic_baseline_check_24).into(binding.imageMyListAction)
|
||||
// }
|
||||
// StorageController.saveMyList(requireContext())
|
||||
//
|
||||
// // notify home fragment on change
|
||||
// parentFragmentManager.findFragmentByTag("HomeFragment")?.let {
|
||||
// (it as HomeFragment).updateMyListMedia()
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user