package Ġcom . ep am . ny ek il aj os . arch comp p oc . inject Ċ Ċ import Ġandroidx . lifecycle .* Ċ import Ġdagger . android . support . D agger Fragment Ċ import Ġjavax . inject . Inject Ċ import Ġkotlin . reflect . K Class Ċ import Ġkotlin . reflect . K Property Ċ Ċ abstract Ġclass ĠD agger Fragment With ViewModel Ġ: ĠD agger Fragment () Ġ{ ĊĊĠĠĠ Ġ@ Inject ĊĠĠĠ Ġlateinit Ġvar ĠviewModel Factory : ĠViewModel Provider . Factory Ċ Ċ } Ċ Ċ inline Ġfun Ġ< re ified ĠT Ġ: ĠViewModel > Ġdagger ViewModel ( fragment : ĠD agger Fragment With ViewModel ) Ġ= ĠD agger ViewModel Delegate ( fragment , ĠT :: class ) Ċ Ċ class ĠD agger ViewModel Delegate < T Ġ: ĠViewModel >( private Ġval Ġfragment : ĠD agger Fragment With ViewModel , Ġprivate Ġval Ġk Class : ĠK Class < T >) Ġ: ĠDefault Lifecycle Observer Ġ{ ĊĊĠĠĠ Ġprivate Ġvar ĠviewModel : ĠT ? Ġ= Ġnull ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġfragment . lifecycle . add Observer ( this ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( owner : ĠLifecycle Owner ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠViewModel Providers . of ( fragment , Ġfragment . viewModel Factory ). get ( k Class . java ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoperator Ġfun ĠgetValue ( this Ref : ĠAny ?, Ġproperty : ĠK Property < *> ): ĠT Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠviewModel Ġ?: Ġthrow ĠIllegalStateException (" Activity Ġis Ġnot Ġstarted Ġyet .") ĊĠĠĠ Ġ} Ċ } Ċ