fix updateNextEpisode()
the function could crash, if no matching episode was found, if that's the case now, it returns the first episode
This commit is contained in:
parent
e650dc3d13
commit
25294c2d87
|
@ -183,7 +183,7 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||||
(activity as MainActivity).startPlayer(model.media.id, ep.id)
|
(activity as MainActivity).startPlayer(model.media.id, ep.id)
|
||||||
Log.d(javaClass.name, "Started Player with episodeId: ${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
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -55,7 +55,7 @@ class MediaFragmentEpisodes : Fragment() {
|
||||||
(activity as MainActivity).startPlayer(model.media.id, ep.id)
|
(activity as MainActivity).startPlayer(model.media.id, ep.id)
|
||||||
Log.d(javaClass.name, "Started Player with episodeId: ${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
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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
|
* if no matching is found, use first episode
|
||||||
*/
|
*/
|
||||||
fun updateNextEpisode() {
|
fun updateNextEpisode(currentEp: Episode) {
|
||||||
if (media.type == MediaType.MOVIE) return // return if movie
|
if (media.type == MediaType.MOVIE) return // return if movie
|
||||||
|
|
||||||
val currentEpNumber = nextEpisode.number
|
nextEpisode = media.episodes.firstOrNull{ it.number > currentEp.number }
|
||||||
nextEpisode = if (media.episodes.firstOrNull{ !it.watched } != null) {
|
?: media.episodes.first()
|
||||||
media.episodes.first{ !it.watched && it.number > currentEpNumber }
|
|
||||||
} else {
|
|
||||||
media.episodes.first()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -55,6 +55,7 @@ data class Media(
|
||||||
fun getEpisodeById(id: Int) = episodes.first { it.id == id }
|
fun getEpisodeById(id: Int) = episodes.first { it.id == id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO all val?
|
||||||
data class Info(
|
data class Info(
|
||||||
var title: String = "",
|
var title: String = "",
|
||||||
var posterUrl: String = "",
|
var posterUrl: String = "",
|
||||||
|
@ -97,6 +98,7 @@ data class Stream(
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this class is used for tmdb responses
|
* this class is used for tmdb responses
|
||||||
|
* TODO why is runtime var?
|
||||||
*/
|
*/
|
||||||
data class TMDBResponse(
|
data class TMDBResponse(
|
||||||
val id: Int = 0,
|
val id: Int = 0,
|
||||||
|
|
Loading…
Reference in New Issue