Merge pull request #3341 from Bnyro/master

Fix crash when closing player
This commit is contained in:
Bnyro 2023-03-22 11:01:09 +01:00 committed by GitHub
commit 3eb1a3805e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,7 +20,9 @@ import android.text.format.DateUtils
import android.text.method.LinkMovementMethod import android.text.method.LinkMovementMethod
import android.text.util.Linkify import android.text.util.Linkify
import android.util.Base64 import android.util.Base64
import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup
import android.widget.TextView import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.annotation.RequiresApi
@ -36,7 +38,6 @@ import androidx.fragment.app.commit
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import by.kirich1409.viewbindingdelegate.viewBinding
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.CronetHelper import com.github.libretube.api.CronetHelper
import com.github.libretube.api.JsonHelper import com.github.libretube.api.JsonHelper
@ -119,15 +120,13 @@ import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString import kotlinx.serialization.encodeToString
import retrofit2.HttpException import retrofit2.HttpException
class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions { class PlayerFragment : Fragment(), OnlinePlayerOptions {
val binding by viewBinding(FragmentPlayerBinding::bind) private var _binding: FragmentPlayerBinding? = null
private val playerBinding by viewBinding { it.binding.player.binding } val binding get() = _binding!!
private val doubleTapOverlayBinding by viewBinding {
it.binding.doubleTapOverlay.binding private val playerBinding get() = binding.player.binding
} private val doubleTapOverlayBinding get() = binding.doubleTapOverlay.binding
private val playerGestureControlsViewBinding by viewBinding { private val playerGestureControlsViewBinding get() = binding.playerGestureControlsView.binding
it.binding.playerGestureControlsView.binding
}
private val viewModel: PlayerViewModel by activityViewModels() private val viewModel: PlayerViewModel by activityViewModels()
private val commentsViewModel: CommentsViewModel by activityViewModels() private val commentsViewModel: CommentsViewModel by activityViewModels()
@ -236,6 +235,15 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
) )
} }
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentPlayerBinding.inflate(layoutInflater)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
context?.hideKeyboard(view) context?.hideKeyboard(view)
@ -598,6 +606,8 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace() e.printStackTrace()
} }
_binding = null
} }
private fun disableAutoPiP() { private fun disableAutoPiP() {