Repository: Automattic/pocket-casts-android
File: modules/features/player/src/main/java/au/com/shiftyjelly/pocketcasts/player/view/PlayerBottomSheet.kt (Kotlin)

Code before:
            }

            override fun onSkipForwardClicked() {
                listener?.onSkipForwardClicked()
            }

            override fun onPlayerClicked() {
                openPlayer()
            }

            override fun onUpNextClicked() {
                listener?.onUpNextClicked()
            }

            override fun onLongClick() {
                listener?.onMiniPlayerLongClick()
            }
        }
    }

    fun initializeBottomSheetBehavior() {
        sheetBehavior = BottomSheetBehavior.from(this).apply {
            val callback = createBottomSheetCallback(rootView = parent as CoordinatorLayout)
            addBottomSheetCallback(callback)

            val preFlingInterceptor = createPreFlingInterceptor(behavior = this as ViewPager2AwareBottomSheetBehavior)
            setPreFlingInterceptor(preFlingInterceptor)

            doOnLayout {
                if (state == BottomSheetBehavior.STATE_EXPANDED) {
                    callback.onSlide(this@PlayerBottomSheet, 1f)
                    listener?.onPlayerBottomSheetSlide(this@PlayerBottomSheet, 1f)
                }
            }
        }
    }

    interface PlayerBottomSheetListener {
        fun onMiniPlayerHidden()
        fun onMiniPlayerVisible()
        fun onPlayerOpen()
        fun onPlayerBottomSheetSlide(bottomSheetView: View, slideOffset: Float)
        fun onPlayerClosed()
        fun onPlayClicked()
        fun onPauseClicked()
        fun onSkipBackwardClicked()
        fun onSkipForwardClicked()
        fun onUpNextClicked()
        fun onMiniPlayerLongClick()
    }


Review comment (suggestion):
💡 cast is not necessery here, but for the `setPreflingInterceptor` call:


Code after:
            }

            override fun onSkipForwardClicked() {
                listener?.onSkipForwardClicked()
            }

            override fun onPlayerClicked() {
                openPlayer()
            }

            override fun onUpNextClicked() {
                listener?.onUpNextClicked()
            }

            override fun onLongClick() {
                listener?.onMiniPlayerLongClick()
            }
        }
    }

    fun initializeBottomSheetBehavior() {
        sheetBehavior = BottomSheetBehavior.from(this).apply {
            val callback = createBottomSheetCallback(rootView = parent as CoordinatorLayout)
            addBottomSheetCallback(callback)

            val preFlingInterceptor = createPreFlingInterceptor(behavior = this)
            (this as ViewPager2AwareBottomSheetBehavior).setPreFlingInterceptor(preFlingInterceptor)

            doOnLayout {
                if (state == BottomSheetBehavior.STATE_EXPANDED) {
                    callback.onSlide(this@PlayerBottomSheet, 1f)
                    listener?.onPlayerBottomSheetSlide(this@PlayerBottomSheet, 1f)
                }
            }
        }
    }

    interface PlayerBottomSheetListener {
        fun onMiniPlayerHidden()
        fun onMiniPlayerVisible()
        fun onPlayerOpen()
        fun onPlayerBottomSheetSlide(bottomSheetView: View, slideOffset: Float)
        fun onPlayerClosed()
        fun onPlayClicked()
        fun onPauseClicked()
        fun onSkipBackwardClicked()
        fun onSkipForwardClicked()
        fun onUpNextClicked()
        fun onMiniPlayerLongClick()
    }