add missing play button functionality for highlight media in HomeFragment
This commit is contained in:
parent
34c7f9d081
commit
d3fe81224b
|
@ -39,13 +39,13 @@ import com.facebook.shimmer.ShimmerFrameLayout
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.mosad.teapod.R
|
import org.mosad.teapod.R
|
||||||
import org.mosad.teapod.databinding.FragmentHomeBinding
|
import org.mosad.teapod.databinding.FragmentHomeBinding
|
||||||
import org.mosad.teapod.ui.activity.main.MainActivity
|
|
||||||
import org.mosad.teapod.ui.activity.main.viewmodel.HomeViewModel
|
import org.mosad.teapod.ui.activity.main.viewmodel.HomeViewModel
|
||||||
import org.mosad.teapod.util.adapter.MediaEpisodeListAdapter
|
import org.mosad.teapod.util.adapter.MediaEpisodeListAdapter
|
||||||
import org.mosad.teapod.util.adapter.MediaItemListAdapter
|
import org.mosad.teapod.util.adapter.MediaItemListAdapter
|
||||||
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
import org.mosad.teapod.util.decoration.MediaItemDecoration
|
||||||
import org.mosad.teapod.util.setDrawableTop
|
import org.mosad.teapod.util.setDrawableTop
|
||||||
import org.mosad.teapod.util.showFragment
|
import org.mosad.teapod.util.showFragment
|
||||||
|
import org.mosad.teapod.util.startPlayer
|
||||||
import org.mosad.teapod.util.toItemMediaList
|
import org.mosad.teapod.util.toItemMediaList
|
||||||
|
|
||||||
class HomeFragment : Fragment() {
|
class HomeFragment : Fragment() {
|
||||||
|
@ -70,10 +70,7 @@ class HomeFragment : Fragment() {
|
||||||
|
|
||||||
binding.recyclerUpNext.adapter = MediaEpisodeListAdapter(
|
binding.recyclerUpNext.adapter = MediaEpisodeListAdapter(
|
||||||
MediaEpisodeListAdapter.OnClickListener {
|
MediaEpisodeListAdapter.OnClickListener {
|
||||||
val activity = activity
|
activity?.startPlayer(it.panel.episodeMetadata.seasonId, it.panel.id)
|
||||||
if (activity is MainActivity) {
|
|
||||||
activity.startPlayer(it.panel.episodeMetadata.seasonId, it.panel.id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -109,16 +106,6 @@ class HomeFragment : Fragment() {
|
||||||
// TODO since this might take a few seconds show a loading animation for the watchlist button
|
// TODO since this might take a few seconds show a loading animation for the watchlist button
|
||||||
}
|
}
|
||||||
|
|
||||||
binding.buttonPlayHighlight.setOnClickListener {
|
|
||||||
// TODO implement
|
|
||||||
lifecycleScope.launch {
|
|
||||||
//val media = AoDParser.getMediaById(0)
|
|
||||||
|
|
||||||
// Log.d(javaClass.name, "Starting Player with mediaId: ${media.aodId}")
|
|
||||||
//(activity as MainActivity).startPlayer(media.aodId, media.playlist.first().mediaId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
viewLifecycleOwner.lifecycleScope.launch {
|
viewLifecycleOwner.lifecycleScope.launch {
|
||||||
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
model.onUiState(viewLifecycleOwner.lifecycleScope) { uiState ->
|
model.onUiState(viewLifecycleOwner.lifecycleScope) { uiState ->
|
||||||
|
@ -165,7 +152,37 @@ class HomeFragment : Fragment() {
|
||||||
activity?.showFragment(MediaFragment(uiState.highlightItem.id))
|
activity?.showFragment(MediaFragment(uiState.highlightItem.id))
|
||||||
}
|
}
|
||||||
|
|
||||||
// disable the shimmer effect and hide the shimmer layouts
|
binding.buttonPlayHighlight.setOnClickListener {
|
||||||
|
val panel = uiState.highlightItemUpNext.panel
|
||||||
|
activity?.startPlayer(panel.episodeMetadata.seasonId, panel.id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// disable the shimmer effect
|
||||||
|
disableShimmer()
|
||||||
|
|
||||||
|
// make highlights layout visible again
|
||||||
|
binding.linearHighlight.isVisible = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindUiStateLoading() {
|
||||||
|
// hide highlights layout
|
||||||
|
binding.linearHighlight.isVisible = false
|
||||||
|
println(binding.root.childCount)
|
||||||
|
binding.root.children.filter { it is ShimmerFrameLayout }.forEach {
|
||||||
|
it as ShimmerFrameLayout
|
||||||
|
it.startShimmer()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun bindUiStateError(uiState: HomeViewModel.UiState.Error) {
|
||||||
|
// currently not used
|
||||||
|
Log.e(classTag, "A error occurred while loading a UiState: ${uiState.message}")
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Disable the shimmer effect for all shimmer layouts and hide them.
|
||||||
|
*/
|
||||||
|
private fun disableShimmer() {
|
||||||
binding.shimmerLayoutHighlight.apply {
|
binding.shimmerLayoutHighlight.apply {
|
||||||
stopShimmer()
|
stopShimmer()
|
||||||
isVisible = false
|
isVisible = false
|
||||||
|
@ -190,23 +207,6 @@ class HomeFragment : Fragment() {
|
||||||
stopShimmer()
|
stopShimmer()
|
||||||
isVisible = false
|
isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
// make highlights layout visible again
|
|
||||||
binding.linearHighlight.isVisible = true
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun bindUiStateLoading() {
|
|
||||||
// hide highlights layout
|
|
||||||
binding.linearHighlight.isVisible = false
|
|
||||||
binding.root.children.filter { it is ShimmerFrameLayout }.forEach {
|
|
||||||
it as ShimmerFrameLayout
|
|
||||||
it.startShimmer()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun bindUiStateError(uiState: HomeViewModel.UiState.Error) {
|
|
||||||
// currently not used
|
|
||||||
Log.e(classTag, "A error occurred while loading a UiState: ${uiState.message}")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ class HomeViewModel : ViewModel() {
|
||||||
val recentlyAddedItems: List<Item>,
|
val recentlyAddedItems: List<Item>,
|
||||||
val topTenItems: List<Item>,
|
val topTenItems: List<Item>,
|
||||||
val highlightItem: Item,
|
val highlightItem: Item,
|
||||||
|
val highlightItemUpNext: UpNextSeriesItem,
|
||||||
val highlightIsWatchlist:Boolean
|
val highlightIsWatchlist:Boolean
|
||||||
) : UiState()
|
) : UiState()
|
||||||
data class Error(val message: String?) : UiState()
|
data class Error(val message: String?) : UiState()
|
||||||
|
@ -77,12 +78,17 @@ class HomeViewModel : ViewModel() {
|
||||||
val recentlyAddedItems = recentlyAddedJob.await()
|
val recentlyAddedItems = recentlyAddedJob.await()
|
||||||
// FIXME crashes on newTitles.items.size == 0
|
// FIXME crashes on newTitles.items.size == 0
|
||||||
val highlightItem = recentlyAddedItems[Random.nextInt(recentlyAddedItems.size)]
|
val highlightItem = recentlyAddedItems[Random.nextInt(recentlyAddedItems.size)]
|
||||||
val highlightItemIsWatchlist = Crunchyroll.isWatchlist(highlightItem.id)
|
val highlightItemUpNextJob = viewModelScope.async {
|
||||||
|
Crunchyroll.upNextSeries(highlightItem.id)
|
||||||
|
}
|
||||||
|
val highlightItemIsWatchlistJob = viewModelScope.async {
|
||||||
|
Crunchyroll.isWatchlist(highlightItem.id)
|
||||||
|
}
|
||||||
|
|
||||||
uiState.emit(UiState.Normal(
|
uiState.emit(UiState.Normal(
|
||||||
upNextJob.await(), watchlistJob.await(), recommendationsJob.await(),
|
upNextJob.await(), watchlistJob.await(), recommendationsJob.await(),
|
||||||
recentlyAddedJob.await(), topTenJob.await(), highlightItem,
|
recentlyAddedJob.await(), topTenJob.await(), highlightItem,
|
||||||
highlightItemIsWatchlist
|
highlightItemUpNextJob.await(), highlightItemIsWatchlistJob.await()
|
||||||
))
|
))
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
uiState.emit(UiState.Error(e.message))
|
uiState.emit(UiState.Error(e.message))
|
||||||
|
@ -115,9 +121,6 @@ class HomeViewModel : ViewModel() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.fragment.app.commit
|
import androidx.fragment.app.commit
|
||||||
import org.mosad.teapod.R
|
import org.mosad.teapod.R
|
||||||
|
import org.mosad.teapod.ui.activity.player.PlayerActivity
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -24,6 +25,20 @@ fun FragmentActivity.showFragment(fragment: Fragment) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start the player as new activity.
|
||||||
|
*
|
||||||
|
* @param seasonId The ID of the season the episode to be played is in
|
||||||
|
* @param episodeId The ID of the episode to play
|
||||||
|
*/
|
||||||
|
fun Activity.startPlayer(seasonId: String, episodeId: String) {
|
||||||
|
val intent = Intent(this, PlayerActivity::class.java).apply {
|
||||||
|
putExtra(getString(R.string.intent_season_id), seasonId)
|
||||||
|
putExtra(getString(R.string.intent_episode_id), episodeId)
|
||||||
|
}
|
||||||
|
startActivity(intent)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* hide the status and navigation bar
|
* hide the status and navigation bar
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue