Merge pull request #1331 from Bnyro/master

remove findviewbyid
This commit is contained in:
Bnyro 2022-09-20 16:55:44 +02:00 committed by GitHub
commit ff8c1a9c0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 29 deletions

View File

@ -13,12 +13,9 @@ import android.view.View
import android.view.WindowInsets import android.view.WindowInsets
import android.view.WindowInsetsController import android.view.WindowInsetsController
import android.view.WindowManager import android.view.WindowManager
import android.widget.LinearLayout
import android.widget.Toast import android.widget.Toast
import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedCallback
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.navigation.NavController import androidx.navigation.NavController
@ -394,24 +391,34 @@ class MainActivity : BaseActivity() {
.replace(R.id.container, frag) .replace(R.id.container, frag)
.commitNow() .commitNow()
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout) supportFragmentManager.fragments.forEach { fragment ->
motionLayout.transitionToEnd() (fragment as? PlayerFragment)
motionLayout.transitionToStart() ?.binding?.playerMotionLayout?.apply {
transitionToEnd()
transitionToStart()
}
}
}, 100) }, 100)
} }
private fun minimizePlayer() { private fun minimizePlayer() {
binding.mainMotionLayout.transitionToEnd() binding.mainMotionLayout.transitionToEnd()
findViewById<ConstraintLayout>(R.id.main_container).isClickable = false supportFragmentManager.fragments.forEach { fragment ->
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout) (fragment as? PlayerFragment)?.binding?.apply {
mainContainer.isClickable = false
linLayout.visibility = View.VISIBLE
}
}
supportFragmentManager.fragments.forEach { fragment ->
(fragment as? PlayerFragment)?.binding?.playerMotionLayout?.apply {
// set the animation duration // set the animation duration
motionLayout.setTransitionDuration(250) setTransitionDuration(250)
motionLayout.transitionToEnd() transitionToEnd()
with(motionLayout) {
getConstraintSet(R.id.start).constrainHeight(R.id.player, 0) getConstraintSet(R.id.start).constrainHeight(R.id.player, 0)
enableTransition(R.id.yt_transition, true) enableTransition(R.id.yt_transition, true)
} }
findViewById<LinearLayout>(R.id.linLayout).visibility = View.VISIBLE }
val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java] val playerViewModel = ViewModelProvider(this)[PlayerViewModel::class.java]
playerViewModel.isFullscreen.value = false playerViewModel.isFullscreen.value = false
requestedOrientation = if (autoRotationEnabled) { requestedOrientation = if (autoRotationEnabled) {

View File

@ -107,7 +107,7 @@ import kotlin.math.abs
class PlayerFragment : BaseFragment() { class PlayerFragment : BaseFragment() {
private lateinit var binding: FragmentPlayerBinding lateinit var binding: FragmentPlayerBinding
private lateinit var playerBinding: ExoStyledPlayerControlViewBinding private lateinit var playerBinding: ExoStyledPlayerControlViewBinding
private lateinit var doubleTapOverlayBinding: DoubleTapOverlayBinding private lateinit var doubleTapOverlayBinding: DoubleTapOverlayBinding
private val viewModel: PlayerViewModel by activityViewModels() private val viewModel: PlayerViewModel by activityViewModels()

View File

@ -3,7 +3,6 @@ package com.github.libretube.util
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.activities.MainActivity import com.github.libretube.activities.MainActivity
@ -21,14 +20,14 @@ object NavigationHelper {
val bundle = bundleOf(IntentData.channelId to channelId) val bundle = bundleOf(IntentData.channelId to channelId)
activity.navController.navigate(R.id.channelFragment, bundle) activity.navController.navigate(R.id.channelFragment, bundle)
try { try {
val mainMotionLayout = if (activity.binding.mainMotionLayout.progress == 0.toFloat()) {
activity.findViewById<MotionLayout>(R.id.mainMotionLayout) activity.binding.mainMotionLayout.transitionToEnd()
if (mainMotionLayout.progress == 0.toFloat()) { activity.supportFragmentManager.fragments.forEach {
mainMotionLayout.transitionToEnd() (it as PlayerFragment?)?.binding?.playerMotionLayout?.transitionToEnd()
activity.findViewById<MotionLayout>(R.id.playerMotionLayout) }
.transitionToEnd()
} }
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace()
} }
} }
} }

View File

@ -10,12 +10,6 @@ import android.view.View
import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.motion.widget.MotionLayout
import com.github.libretube.R import com.github.libretube.R
/**
*
* Created by Arman Chatikyan on 05 Sep 2018
*
*/
class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeSet? = null) : class SingleViewTouchableMotionLayout(context: Context, attributeSet: AttributeSet? = null) :
MotionLayout(context, attributeSet) { MotionLayout(context, attributeSet) {