Add similar titles to media fragment #28

Merged
Seil0 merged 7 commits from feature/similar into develop 2021-02-06 19:02:13 +01:00
4 changed files with 8 additions and 10 deletions
Showing only changes of commit 25294c2d87 - Show all commits

View File

@ -183,7 +183,7 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
(activity as MainActivity).startPlayer(model.media.id, ep.id)
Log.d(javaClass.name, "Started Player with episodeId: ${ep.id}")
model.updateNextEpisode() // set the correct next episode
model.updateNextEpisode(ep) // set the correct next episode
}
/**

View File

@ -55,7 +55,7 @@ class MediaFragmentEpisodes : Fragment() {
(activity as MainActivity).startPlayer(model.media.id, ep.id)
Log.d(javaClass.name, "Started Player with episodeId: ${ep.id}")
model.updateNextEpisode() // set the correct next episode
model.updateNextEpisode(ep) // set the correct next episode
}
}

View File

@ -35,18 +35,14 @@ class MediaFragmentViewModel(application: Application) : AndroidViewModel(applic
}
/**
* based on watched state and current episode number set the next episode
* get the next episode based on episode number (the true next episode)
* if no matching is found, use first episode
*/
fun updateNextEpisode() {
fun updateNextEpisode(currentEp: Episode) {
if (media.type == MediaType.MOVIE) return // return if movie
val currentEpNumber = nextEpisode.number
nextEpisode = if (media.episodes.firstOrNull{ !it.watched } != null) {
media.episodes.first{ !it.watched && it.number > currentEpNumber }
} else {
media.episodes.first()
}
nextEpisode = media.episodes.firstOrNull{ it.number > currentEp.number }
?: media.episodes.first()
}
}

View File

@ -55,6 +55,7 @@ data class Media(
fun getEpisodeById(id: Int) = episodes.first { it.id == id }
}
// TODO all val?
data class Info(
var title: String = "",
var posterUrl: String = "",
@ -97,6 +98,7 @@ data class Stream(
/**
* this class is used for tmdb responses
* TODO why is runtime var?
*/
data class TMDBResponse(
val id: Int = 0,