package Ġzaw al ich . ros z ak . in poster . views Ċ Ċ import Ġandroid . arch . lifecycle . ViewModel Ċ import Ġandroid . databinding . Data Binding Util Ċ import Ġandroid . databinding . ViewData Binding Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . support . v 4 . app . Fragment Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ Ċ /** Ċ Ġ* ĉ Default Ġimplementation Ġof Ġa Ġfragment Ġthat Ġcreates Ġa Ġlayout Ġand Ġbind s Ġit Ġto Ġa ĠViewModel . Ċ Ġ*/ Ċ abstract Ġclass ĠBase Fragment < B Ġ: ĠView Data Binding , ĠVM Ġ: ĠViewModel > Ġ: ĠFragment (), ĠBase View Ġ{ Ċ ĉ abstract Ġval Ġbinding Class Token : ĠClass < B > Ċ ĉ abstract Ġval ĠviewModel Class Token : ĠClass < VM > Ċ ĉ abstract Ġval Ġlayout Id : ĠInt ĊĊ ĉ open Ġlateinit Ġvar Ġbinding : ĠB Ċ ĉ open Ġlateinit Ġvar Ġvm : ĠViewModel ĊĊ ĉ override Ġfun Ġset ViewModel ( viewModel : ĠViewModel ) Ġ{ Ċĉ ĉ this . vm Ġ= ĠviewModel Ċĉ ĉ bind If Ready () Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ Ċĉ ĉ binding Ġ= ĠData Binding Util . inflate < ViewData Binding >( in flater , Ġlayout Id , Ġcontainer , Ġfalse ) Ġas ĠB ĊĊĉ ĉ bind If Ready () ĊĊĉ ĉ return Ġbinding . root Ċ ĉ } ĊĊ ĉ private Ġfun Ġbind If Ready () Ġ{ Ċĉ ĉ if Ġ(:: vm . isInitialized Ġ&& Ġ:: binding . isInitialized ) Ġ{ Ċĉĉ ĉ val Ġmethod Ġ= Ġbinding Class Token . getMethod (" set ViewModel ", ĠviewModel Class Token ) Ċĉĉ ĉ method . invoke ( binding , Ġvm ) Ċĉ ĉ } Ċ ĉ } Ċ }