init
This commit is contained in:
41
style/src/main/java/com/testapp/ViewBindingDialogFragment.kt
Normal file
41
style/src/main/java/com/testapp/ViewBindingDialogFragment.kt
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.testapp
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AppCompatDialogFragment
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
abstract class ViewBindingDialogFragment<VB : ViewBinding> : AppCompatDialogFragment() {
|
||||
|
||||
private var _binding: ViewBinding? = null
|
||||
abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
protected val binding: VB
|
||||
get() = _binding as VB
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = bindingInflater.invoke(inflater, container, false)
|
||||
return requireNotNull(_binding).root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewSetup()
|
||||
}
|
||||
|
||||
abstract fun viewSetup()
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
39
style/src/main/java/com/testapp/ViewBindingFragment.kt
Normal file
39
style/src/main/java/com/testapp/ViewBindingFragment.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
package com.testapp
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewbinding.ViewBinding
|
||||
|
||||
abstract class ViewBindingFragment<VB : ViewBinding> : Fragment() {
|
||||
|
||||
private var _binding: ViewBinding? = null
|
||||
abstract val bindingInflater: (LayoutInflater, ViewGroup?, Boolean) -> VB
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
protected val binding: VB
|
||||
get() = _binding as VB
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
_binding = bindingInflater.invoke(inflater, container, false)
|
||||
return requireNotNull(_binding).root
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewSetup()
|
||||
}
|
||||
|
||||
abstract fun viewSetup()
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
_binding = null
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user