VancedManager/core-ui/src/main/java/com/vanced/manager/core/ui/base/BindingBottomSheetDialogFra...

48 lines
1.5 KiB
Kotlin
Raw Normal View History

package com.vanced.manager.core.ui.base
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
2021-01-15 16:02:50 +00:00
import android.widget.FrameLayout
import androidx.viewbinding.ViewBinding
2021-01-15 16:02:50 +00:00
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
abstract class BindingBottomSheetDialogFragment<VB : ViewBinding> : BottomSheetDialogFragment() {
private var _binding: VB? = null
protected val binding: VB get() = requireNotNull(_binding)
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = binding(inflater, container, savedInstanceState)
2021-10-08 15:10:24 +00:00
dialog?.setOnShowListener {
2021-01-15 16:02:50 +00:00
val bottomSheetDialogFragment = (it as BottomSheetDialog).findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
if (bottomSheetDialogFragment != null) {
BottomSheetBehavior.from(bottomSheetDialogFragment).apply {
state = BottomSheetBehavior.STATE_EXPANDED
}
}
}
2021-10-08 15:10:24 +00:00
otherSetups()
return binding.root
2021-01-15 16:02:50 +00:00
}
protected abstract fun binding(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): VB
protected open fun otherSetups() = Unit
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}