From 19a46a19c0e4ace1609086c475510845be542436 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Wed, 29 Jun 2022 16:07:58 +0200 Subject: [PATCH] animations --- .../libretube/fragments/PlayerFragment.kt | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt index aa5ac3170..05d306338 100644 --- a/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/fragments/PlayerFragment.kt @@ -166,8 +166,9 @@ class PlayerFragment : Fragment() { hideKeyboard() setSponsorBlockPrefs() + createExoPlayer(view) initializeTransitionLayout(view) - fetchJsonAndInitPlayer(view) + playVideo(view) } private fun initializeTransitionLayout(view: View) { @@ -267,7 +268,7 @@ class PlayerFragment : Fragment() { val descLinLayout = view.findViewById(R.id.desc_linLayout) view.findViewById(R.id.player_title_layout).setOnClickListener { val arrowImageView = view.findViewById(R.id.player_description_arrow) - arrowImageView.animate().rotationBy(180F).setDuration(100).start() + arrowImageView.animate().rotationBy(180F).setDuration(250).start() descLinLayout.visibility = if (descLinLayout.isVisible) View.GONE else View.VISIBLE } @@ -384,7 +385,12 @@ class PlayerFragment : Fragment() { val isScreenOn = pm.isInteractive // pause player if screen off and setting enabled - if (exoPlayer != null && !isScreenOn && pausePlayerOnScreenOffEnabled) { + if ( + this::exoPlayer.isInitialized && + exoPlayer != null && + !isScreenOn && + pausePlayerOnScreenOffEnabled + ) { exoPlayer.pause() } super.onPause() @@ -428,7 +434,7 @@ class PlayerFragment : Fragment() { } } - private fun fetchJsonAndInitPlayer(view: View) { + private fun playVideo(view: View) { fun run() { lifecycleScope.launchWhenCreated { val response = try { @@ -456,7 +462,6 @@ class PlayerFragment : Fragment() { relatedStreams = response.relatedStreams runOnUiThread { - createExoPlayer(view) if (response.chapters != null) initializeChapters(response.chapters) // set media sources for the player setResolutionAndSubtitles(view, response) @@ -542,7 +547,7 @@ class PlayerFragment : Fragment() { if (videoId != nextStreamId) { // save the id of the next stream as videoId and load the next video videoId = nextStreamId - fetchJsonAndInitPlayer(view!!) + playVideo(view!!) } } @@ -571,7 +576,7 @@ class PlayerFragment : Fragment() { private fun fetchSponsorBlockSegments() { fun run() { - lifecycleScope.launchWhenCreated { + lifecycleScope.launch(Dispatchers.IO) { if (sponsorBlockPrefs.sponsorBlockEnabled) { val categories: ArrayList = arrayListOf() if (sponsorBlockPrefs.introEnabled) { @@ -607,14 +612,10 @@ class PlayerFragment : Fragment() { } catch (e: IOException) { println(e) Log.e(TAG, "IOException, you might not have internet connection") - Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT) - .show() - return@launchWhenCreated + return@launch } catch (e: HttpException) { Log.e(TAG, "HttpException, unexpected response") - Toast.makeText(context, R.string.server_error, Toast.LENGTH_SHORT) - .show() - return@launchWhenCreated + return@launch } } }