minor code clean up
This commit is contained in:
parent
7a2f3ad265
commit
b05ecf64a6
|
@ -48,7 +48,7 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
binding.frameLoading.visibility = View.VISIBLE
|
binding.frameLoading.visibility = View.VISIBLE
|
||||||
|
|
||||||
// tab layout and pager TODO
|
// tab layout and pager
|
||||||
pagerAdapter = ScreenSlidePagerAdapter(requireActivity())
|
pagerAdapter = ScreenSlidePagerAdapter(requireActivity())
|
||||||
// fix material components issue #1878, if more tabs are added increase
|
// fix material components issue #1878, if more tabs are added increase
|
||||||
binding.pagerEpisodesSimilar.offscreenPageLimit = 2
|
binding.pagerEpisodesSimilar.offscreenPageLimit = 2
|
||||||
|
|
|
@ -50,9 +50,6 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
private lateinit var timerUpdates: TimerTask
|
private lateinit var timerUpdates: TimerTask
|
||||||
|
|
||||||
private var wasInPiP = false
|
private var wasInPiP = false
|
||||||
private var playWhenReady = true
|
|
||||||
private var currentWindow = 0
|
|
||||||
private var playbackPosition: Long = 0
|
|
||||||
private var remainingTime: Long = 0
|
private var remainingTime: Long = 0
|
||||||
|
|
||||||
private val rwdTime: Long = 10000.unaryMinus()
|
private val rwdTime: Long = 10000.unaryMinus()
|
||||||
|
@ -64,12 +61,6 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
setContentView(R.layout.activity_player)
|
setContentView(R.layout.activity_player)
|
||||||
hideBars() // Initial hide the bars
|
hideBars() // Initial hide the bars
|
||||||
|
|
||||||
savedInstanceState?.let {
|
|
||||||
currentWindow = it.getInt(getString(R.string.state_resume_window))
|
|
||||||
playbackPosition = it.getLong(getString(R.string.state_resume_position))
|
|
||||||
playWhenReady = it.getBoolean(getString(R.string.state_is_playing))
|
|
||||||
}
|
|
||||||
|
|
||||||
model.loadMedia(
|
model.loadMedia(
|
||||||
intent.getIntExtra(getString(R.string.intent_media_id), 0),
|
intent.getIntExtra(getString(R.string.intent_media_id), 0),
|
||||||
intent.getIntExtra(getString(R.string.intent_episode_id), 0)
|
intent.getIntExtra(getString(R.string.intent_episode_id), 0)
|
||||||
|
@ -110,34 +101,21 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
super.onPause()
|
super.onPause()
|
||||||
if (isInPiPMode()) { return }
|
|
||||||
|
|
||||||
if (Util.SDK_INT <= 23) {
|
if (isInPiPMode()) { return }
|
||||||
video_view?.onPause()
|
if (Util.SDK_INT <= 23) { onPauseOnStop() }
|
||||||
releasePlayer()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
if (Util.SDK_INT > 23) {
|
|
||||||
video_view?.onPause()
|
|
||||||
releasePlayer()
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (Util.SDK_INT > 23) { onPauseOnStop() }
|
||||||
// if the player was in pip, it's on a different task
|
// if the player was in pip, it's on a different task
|
||||||
if (wasInPiP) { navToLauncherTask() }
|
if (wasInPiP) { navToLauncherTask() }
|
||||||
// if the player is in pip, remove the task, else we'll get a zombie
|
// if the player is in pip, remove the task, else we'll get a zombie
|
||||||
if (isInPiPMode()) { finishAndRemoveTask() }
|
if (isInPiPMode()) { finishAndRemoveTask() }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
|
||||||
outState.putInt(getString(R.string.state_resume_window), currentWindow)
|
|
||||||
outState.putLong(getString(R.string.state_resume_position), playbackPosition)
|
|
||||||
outState.putBoolean(getString(R.string.state_is_playing), playWhenReady)
|
|
||||||
super.onSaveInstanceState(outState)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* used, when the player is in pip and the user selects a new media
|
* used, when the player is in pip and the user selects a new media
|
||||||
*/
|
*/
|
||||||
|
@ -209,7 +187,6 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
* set play when ready and listeners
|
* set play when ready and listeners
|
||||||
*/
|
*/
|
||||||
private fun initExoPlayer() {
|
private fun initExoPlayer() {
|
||||||
model.player.playWhenReady = playWhenReady
|
|
||||||
model.player.addListener(object : Player.EventListener {
|
model.player.addListener(object : Player.EventListener {
|
||||||
override fun onPlaybackStateChanged(state: Int) {
|
override fun onPlaybackStateChanged(state: Int) {
|
||||||
super.onPlaybackStateChanged(state)
|
super.onPlaybackStateChanged(state)
|
||||||
|
@ -233,7 +210,7 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
})
|
})
|
||||||
|
|
||||||
// start playing the current episode, after all needed player components have been initialized
|
// start playing the current episode, after all needed player components have been initialized
|
||||||
model.playEpisode(model.currentEpisode, true, playbackPosition)
|
model.playEpisode(model.currentEpisode, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
@ -308,10 +285,8 @@ class PlayerActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun releasePlayer() {
|
private fun onPauseOnStop() {
|
||||||
playbackPosition = model.player.currentPosition
|
video_view?.onPause()
|
||||||
currentWindow = model.player.currentWindowIndex
|
|
||||||
playWhenReady = model.player.playWhenReady
|
|
||||||
model.player.pause()
|
model.player.pause()
|
||||||
timerUpdates.cancel()
|
timerUpdates.cancel()
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,9 @@ data class Media(
|
||||||
fun getEpisodeById(id: Int) = episodes.first { it.id == id }
|
fun getEpisodeById(id: Int) = episodes.first { it.id == id }
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO all val?
|
/**
|
||||||
|
* uses var, since the values are written in different steps
|
||||||
|
*/
|
||||||
data class Info(
|
data class Info(
|
||||||
var title: String = "",
|
var title: String = "",
|
||||||
var posterUrl: String = "",
|
var posterUrl: String = "",
|
||||||
|
@ -98,7 +100,6 @@ 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,
|
||||||
|
@ -106,7 +107,7 @@ data class TMDBResponse(
|
||||||
val overview: String = "",
|
val overview: String = "",
|
||||||
val posterUrl: String = "",
|
val posterUrl: String = "",
|
||||||
val backdropUrl: String = "",
|
val backdropUrl: String = "",
|
||||||
var runtime: Int = 0
|
val runtime: Int = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue