Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when closing player #3341

Merged
merged 1 commit into from
Mar 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import android.text.format.DateUtils
import android.text.method.LinkMovementMethod
import android.text.util.Linkify
import android.util.Base64
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.annotation.RequiresApi
Expand All @@ -36,7 +38,6 @@ import androidx.fragment.app.commit
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import by.kirich1409.viewbindingdelegate.viewBinding
import com.github.libretube.R
import com.github.libretube.api.CronetHelper
import com.github.libretube.api.JsonHelper
Expand Down Expand Up @@ -119,15 +120,13 @@ import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import retrofit2.HttpException

class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
val binding by viewBinding(FragmentPlayerBinding::bind)
private val playerBinding by viewBinding { it.binding.player.binding }
private val doubleTapOverlayBinding by viewBinding {
it.binding.doubleTapOverlay.binding
}
private val playerGestureControlsViewBinding by viewBinding {
it.binding.playerGestureControlsView.binding
}
class PlayerFragment : Fragment(), OnlinePlayerOptions {
private var _binding: FragmentPlayerBinding? = null
val binding get() = _binding!!

private val playerBinding get() = binding.player.binding
private val doubleTapOverlayBinding get() = binding.doubleTapOverlay.binding
private val playerGestureControlsViewBinding get() = binding.playerGestureControlsView.binding

private val viewModel: PlayerViewModel by activityViewModels()
private val commentsViewModel: CommentsViewModel by activityViewModels()
Expand Down Expand Up @@ -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?) {
super.onViewCreated(view, savedInstanceState)
context?.hideKeyboard(view)
Expand Down Expand Up @@ -598,6 +606,8 @@ class PlayerFragment : Fragment(R.layout.fragment_player), OnlinePlayerOptions {
} catch (e: Exception) {
e.printStackTrace()
}

_binding = null
}

private fun disableAutoPiP() {
Expand Down