Make work with Android View Binding simpler
allprojects {
repositories {
jcenter()
}
}
dependencies {
implementation 'com.kirich1409.viewbindingpropertydelegate:viewbindingpropertydelegate:1.0.0-beta1'
}
class ProfileFragment : Fragment(R.layout.profile) {
private val viewBinding: ProfileBinding by viewBinding()
}
class ProfileActivity : AppCompatActivity(R.layout.profile) {
private val viewBinding: ProfileBinding by viewBinding(R.id.container)
}
class ProfileDialogFragment : DialogFragment() {
private val viewBinding: ProfileBinding by dialogViewBinding(R.id.container)
// Creating via default way will work too for that case
// private val viewBinding: ProfileBinding by viewBinding()
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
return AlertDialog.Builder(requireContext())
.setView(R.layout.profile)
.create()
}
}
class ProfileDialogFragment : DialogFragment() {
private val viewBinding: ProfileBinding by dialogViewBinding(R.id.container)
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.profile, container, false)
}
}