Browse Source

minor code clean up

pull/37/head
Jannik 1 year ago
parent
commit
b05ecf64a6
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
  1. 2
      app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragment.kt
  2. 37
      app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt
  3. 7
      app/src/main/java/org/mosad/teapod/util/DataTypes.kt

2
app/src/main/java/org/mosad/teapod/ui/activity/main/fragments/MediaFragment.kt

@ -48,7 +48,7 @@ class MediaFragment(private val mediaId: Int) : Fragment() {
super.onViewCreated(view, savedInstanceState)
binding.frameLoading.visibility = View.VISIBLE
// tab layout and pager TODO
// tab layout and pager
pagerAdapter = ScreenSlidePagerAdapter(requireActivity())
// fix material components issue #1878, if more tabs are added increase
binding.pagerEpisodesSimilar.offscreenPageLimit = 2

37
app/src/main/java/org/mosad/teapod/ui/activity/player/PlayerActivity.kt

@ -50,9 +50,6 @@ class PlayerActivity : AppCompatActivity() {
private lateinit var timerUpdates: TimerTask
private var wasInPiP = false
private var playWhenReady = true
private var currentWindow = 0
private var playbackPosition: Long = 0
private var remainingTime: Long = 0
private val rwdTime: Long = 10000.unaryMinus()
@ -64,12 +61,6 @@ class PlayerActivity : AppCompatActivity() {
setContentView(R.layout.activity_player)
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(
intent.getIntExtra(getString(R.string.intent_media_id), 0),
intent.getIntExtra(getString(R.string.intent_episode_id), 0)
@ -110,34 +101,21 @@ class PlayerActivity : AppCompatActivity() {
override fun onPause() {
super.onPause()
if (isInPiPMode()) { return }
if (Util.SDK_INT <= 23) {
video_view?.onPause()
releasePlayer()
}
if (isInPiPMode()) { return }
if (Util.SDK_INT <= 23) { onPauseOnStop() }
}
override fun 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 (wasInPiP) { navToLauncherTask() }
// if the player is in pip, remove the task, else we'll get a zombie
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
*/
@ -209,7 +187,6 @@ class PlayerActivity : AppCompatActivity() {
* set play when ready and listeners
*/
private fun initExoPlayer() {
model.player.playWhenReady = playWhenReady
model.player.addListener(object : Player.EventListener {
override fun onPlaybackStateChanged(state: Int) {
super.onPlaybackStateChanged(state)
@ -233,7 +210,7 @@ class PlayerActivity : AppCompatActivity() {
})
// 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")
@ -308,10 +285,8 @@ class PlayerActivity : AppCompatActivity() {
}
}
private fun releasePlayer() {
playbackPosition = model.player.currentPosition
currentWindow = model.player.currentWindowIndex
playWhenReady = model.player.playWhenReady
private fun onPauseOnStop() {
video_view?.onPause()
model.player.pause()
timerUpdates.cancel()
}

7
app/src/main/java/org/mosad/teapod/util/DataTypes.kt

@ -55,7 +55,9 @@ data class Media(
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(
var title: String = "",
var posterUrl: String = "",
@ -98,7 +100,6 @@ data class Stream(
/**
* this class is used for tmdb responses
* TODO why is runtime var?
*/
data class TMDBResponse(
val id: Int = 0,
@ -106,7 +107,7 @@ data class TMDBResponse(
val overview: String = "",
val posterUrl: String = "",
val backdropUrl: String = "",
var runtime: Int = 0
val runtime: Int = 0
)
/**

Loading…
Cancel
Save

Du besuchst diese Seite mit einem veralteten IPv4-Internetzugang. Möglicherweise treten in Zukunft Probleme mit der Erreichbarkeit und Performance auf. Bitte frage deinen Internetanbieter oder Netzwerkadministrator nach IPv6-Unterstützung.
You are visiting this site with an outdated IPv4 internet access. You may experience problems with accessibility and performance in the future. Please ask your ISP or network administrator for IPv6 support.
Weitere Infos | More Information
Klicke zum schließen | Click to close