MediaFragment: update playhead progress/fully watched on resume

This commit is contained in:
Jannik 2022-01-29 20:32:45 +01:00
parent df4f43c0a2
commit f66fca7ebb
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 11 additions and 22 deletions

View File

@ -89,6 +89,7 @@ class MediaFragment(private val mediaIdStr: String) : Fragment() {
binding.textTitle.text = model.upNextSeries.panel.title
}
// needs to be called after model.updateOnResume()
if (fragments.elementAtOrNull(0) is MediaFragmentEpisodes) {
(fragments[0] as MediaFragmentEpisodes).updateWatchedState()
}

View File

@ -54,23 +54,10 @@ class MediaFragmentEpisodes : Fragment() {
}
}
override fun onResume() {
super.onResume()
// if adapterRecEpisodes is initialized, update the watched state for the episodes
if (this::adapterRecEpisodes.isInitialized) {
// TODO reimplement, if needed
// update via playheads?
// model.media.playlist.forEachIndexed { index, episodeInfo ->
// adapterRecEpisodes.updateWatchedState(episodeInfo.watched, index)
// }
// adapterRecEpisodes.notifyDataSetChanged()
}
}
@SuppressLint("NotifyDataSetChanged")
fun updateWatchedState() {
// TODO update watched state of all episodes
// use a mutable list for playheads and notify dataset changed
// model.currentPlayheads is a val mutable map -> notify dataset changed
adapterRecEpisodes.notifyDataSetChanged()
}
private fun showSeasonSelection(v: View) {

View File

@ -3,7 +3,6 @@ package org.mosad.teapod.ui.activity.main.viewmodel
import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.joinAll
import kotlinx.coroutines.launch
import org.mosad.teapod.parser.crunchyroll.*
@ -31,7 +30,7 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
val currentEpisodesCrunchy = arrayListOf<Episode>() // used for EpisodeItemAdapter (easier updates)
// additional media info
var currentPlayheads: PlayheadsMap = emptyMap()
val currentPlayheads: MutableMap<String, PlayheadObject> = mutableMapOf()
var isWatchlist = false
internal set
var upNextSeries = NoneUpNextSeriesItem
@ -85,7 +84,8 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
viewModelScope.launch {
// get playheads (including fully watched state)
val episodeIDs = episodesCrunchy.items.map { it.id }
currentPlayheads = Crunchyroll.playheads(episodeIDs)
currentPlayheads.clear()
currentPlayheads.putAll(Crunchyroll.playheads(episodeIDs))
},
viewModelScope.launch { loadTmdbInfo() } // use tmdb search to get media info
).joinAll()
@ -152,13 +152,14 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
}
suspend fun updateOnResume() {
listOf(
joinAll(
viewModelScope.launch {
val episodeIDs = episodesCrunchy.items.map { it.id }
currentPlayheads = Crunchyroll.playheads(episodeIDs)
currentPlayheads.clear()
currentPlayheads.putAll(Crunchyroll.playheads(episodeIDs))
},
viewModelScope.launch { upNextSeries = Crunchyroll.upNextSeries(seriesCrunchy.id) }
).joinAll()
)
}
/**