BlackZerg

Untitled

Sep 26th, 2021
879
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. abstract class BaseFragment<VB: ViewBinding> : Fragment() {
  2.  
  3.     abstract val inflate: Inflate<VB>
  4.     protected var binding: VB? = null
  5.  
  6.     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
  7.         binding = inflate.invoke(inflater, container, false)
  8.         return binding?.root
  9.     }
  10.  
  11.     override fun onDestroyView() {
  12.         super.onDestroyView()
  13.         binding = null
  14.     }
  15. }
  16.  
  17. //
  18. class CategoriesFragment : BaseFragment<FragmentCategoriesBinding>() {
  19.  
  20.     private val viewModel by inject<CategoriesVM>()
  21.  
  22.     override val inflate: Inflate<FragmentCategoriesBinding> = FragmentCategoriesBinding::inflate
  23.  
  24.     override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
  25.         super.onViewCreated(view, savedInstanceState)
  26.  
  27.         binding?.apply {
  28.             titleTV.text = "Категории"
  29.         }
  30.     }
  31.  
  32.     companion object {
  33.         fun newInstance() = CategoriesFragment()
  34.     }
  35. }
RAW Paste Data