/* Ċ Ġ* ĠDesign ed Ġand Ġdeveloped Ġby Ġ 2 0 2 0 Ġsky do ves Ġ( Ja ew o ong ĠE um ) Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ Ċ @ file : Suppress (" unused ") Ċ Ċ package Ġcom . sky do ves . lazy bones Ċ Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġjava . io . Serializable Ċ Ċ /** Ċ Ġ* Ġ@ author Ġsky do ves Ġ( Ja ew o ong ĠE um ) Ċ Ġ* Ċ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġdelegate Ġfor Ġinitializing Ġlifecycle Ġaware Ġproperty Ġl az ily . Ċ Ġ* Ċ Ġ* Ġ@ param Ġlazy Thread Safety Mode ĠSpecifies Ġhow Ġa Ġ[ Lazy ] Ġinstance Ġsynchron izes Ġinitialization Ġamong Ġmultiple Ġthreads . Ċ Ġ* Ġ@ param Ġinitializer ĠA Ġinstance Ġinitializer Ġfor Ġinitializing Ġthe Ġ[ T ] Ġl az ily . Ċ Ġ* Ċ Ġ* Ġ@ return Ġ[ Lazy bones ] ĠA Ġlazy bones Ġwrapper Ġfor Ġcreating Ġa Ġlifecycle - aware Ġproperty . Ċ Ġ*/ Ċ @ Jvm Synt hetic Ċ @ Lazy bones With No In lines Ċ public Ġinline Ġfun Ġ< re ified ĠT Ġ: ĠAny > ĠLifecycle Owner . lifecycle Aware ( ĊĠ Ġlazy Thread Safety Mode : ĠLazy Thread Safety Mode Ġ= ĠLazy Thread Safety Mode . NONE , ĊĠ Ġno inline Ġinitializer : Ġ() Ġ-> ĠT , Ċ ): ĠLazy bones < T > Ġ{ ĊĠ Ġreturn ĠLazy bones ( this , Ġlazy ( lazy Thread Safety Mode ) Ġ{ Ġinitializer () Ġ}) Ċ } Ċ Ċ /** Ċ Ġ* Ġ@ author Ġsky do ves Ġ( Ja ew o ong ĠE um ) Ċ Ġ* Ċ Ġ* ĠReturns Ġa Ġ[ Lifecycle Aware Property ] Ġdelegate Ġfor Ġinitializing Ġlifecycle Ġobservable Ġproperty Ġinstant ly . Ċ Ġ* Ċ Ġ* Ġ@ param Ġvalue ĠThe Ġinitialization Ġvalue . Ċ Ġ* Ċ Ġ* Ġ@ return Ġ[ Lifecycle Aware Property ] ĠA Ġwrapper Ġfor Ġcreating Ġlifecycle Ġobservable Ġproperty . Ċ Ġ*/ Ċ @ Jvm Synt hetic Ċ public Ġinline Ġfun Ġ< re ified ĠT Ġ: ĠAny > ĠLifecycle Owner . lifecycle Aware ( ĊĠ Ġvalue : ĠT Ċ ): ĠLifecycle Aware Property < T > Ġ{ ĊĠ Ġreturn ĠLifecycle Aware Property ( this , Ġvalue ) Ċ } Ċ Ċ /** Ċ Ġ* Ġ@ author Ġsky do ves Ġ( Ja ew o ong ĠE um ) Ċ Ġ* Ċ Ġ* Ġ[ Lazy bones ] Ġis Ġa Ġwrapper Ġclass Ġthat Ġinitializes Ġ[ Lazy ] Ġproperty Ġbased Ġon Ġthe Ġlifecycle . Ċ Ġ* Ċ Ġ* Ġ@ property Ġlifecycle Owner ĠA Ġclass Ġthat Ġhas Ġan ĠAndroid Ġlifecycle Ġfor Ġob serving Ġthe Ġlifecycle Ġevents . Ċ Ġ* Ġ@ property Ġlazy ĠA Ġlazy Ġinitialization Ġfor Ġinitializing Ġthe Ġvalue Ġ[ T ] Ġl az ily . Ċ Ġ*/ Ċ public Ġclass ĠLazy bones < out ĠT Ġ: ĠAny > Ġconstructor ( ĊĠ Ġprivate Ġval Ġlifecycle Owner : ĠLifecycle Owner , ĊĠ Ġprivate Ġval Ġlazy : ĠLazy < T > Ċ ) Ġ: ĠSerializable Ġ{ ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġwith Ġan Ġ[ On ] Ġlifecycle Ġstate Ġand Ġa Ġ[ receiver ]. ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġon ĠAndroid Ġlifecycle Ġfor Ġcreating Ġlifecycle - aware Ġproperties . ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġinternal Ġfun Ġon ( on : ĠOn , Ġreceiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= Ġadd Lifecycle Observer ( on , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġand Ġthe Ġreceiver Ġwill Ġbe Ġaware Ġof Ġ[ On . CREATE ] Ġlifecycle Ġstate . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun ĠonCreate ( receiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= ĊĠĠĠ Ġadd Lifecycle Observer ( On . CREATE , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġand Ġthe Ġreceiver Ġwill Ġbe Ġaware Ġof Ġ[ On . START ] Ġlifecycle Ġstate . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun ĠonStart ( receiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= ĊĠĠĠ Ġadd Lifecycle Observer ( On . START , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġand Ġthe Ġreceiver Ġwill Ġbe Ġaware Ġof Ġ[ On . RE SU ME ] Ġlifecycle Ġstate . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun Ġon Resume ( receiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= ĊĠĠĠ Ġadd Lifecycle Observer ( On . RE SU ME , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġand Ġthe Ġreceiver Ġwill Ġbe Ġaware Ġof Ġ[ On . PAUSE ] Ġlifecycle Ġstate . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun Ġon Pause ( receiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= ĊĠĠĠ Ġadd Lifecycle Observer ( On . PAUSE , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġand Ġthe Ġreceiver Ġwill Ġbe Ġaware Ġof Ġ[ On . STOP ] Ġlifecycle Ġstate . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun Ġon Stop ( receiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= Ġadd Lifecycle Observer ( On . STOP , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠReturns Ġa Ġ[ Lazy bones ] Ġand Ġthe Ġreceiver Ġwill Ġbe Ġaware Ġof Ġ[ On . DESTROY ] Ġlifecycle Ġstate . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun Ġon Destroy ( receiver : ĠT . () Ġ-> ĠUnit ): ĠLazy bones < T > Ġ= ĊĠĠĠ Ġadd Lifecycle Observer ( On . DESTROY , Ġreceiver ) ĊĊĠ Ġ/** ĊĠĠ Ġ* ĠAdds Ġa Ġlifecycle Ġobserver Ġbased Ġon Ġ[ On ] Ġlifecycle Ġstate Ġinternally . ĊĠĠ Ġ* ĊĠĠ Ġ* Ġ@ param Ġon ĠAndroid Ġlifecycle Ġfor Ġcreating Ġlifecycle - aware Ġproperties . ĊĠĠ Ġ* Ġ@ param Ġreceiver ĠA Ġreceiver Ġthat Ġwill Ġbe Ġexecuted Ġbased Ġon Ġthe Ġevery Ġlifecycle Ġl az ily . ĊĠĠ Ġ*/ ĊĠ Ġ@ Jvm Synt hetic ĊĠ Ġprivate Ġfun Ġadd Lifecycle Observer ( on : ĠOn , Ġreceiver : ĠT . () Ġ-> ĠUnit ) Ġ= Ġapply Ġ{ ĊĠĠĠ Ġval Ġobserver Ġ= Ġon . get On Lifecycle Observer < T >() ĊĠĠĠ Ġobserver . register Lazy Property ( this . lazy , Ġreceiver ) ĊĠĠĠ Ġthis . lifecycle Owner . lifecycle . add Observer ( observer ) ĊĠ Ġ} ĊĊĠ Ġ/** Ġinitializes Ġthe Ġlifecycle - aware Ġproperty Ġl az ily . Ġ*/ ĊĠ Ġ@ Lazy bones With No In lines ĊĠ Ġpublic Ġfun Ġlazy (): ĠLazy < T > Ġ= Ġthis . lazy ĊĊĠ Ġ/** Ġgets Ġproperty Ġvalue Ġfrom Ġthe Ġlazy Ġclass . Ġ*/ ĊĠ Ġpublic Ġfun Ġvalue (): ĠT Ġ= Ġthis . lazy . value ĊĊĠ Ġoverride Ġfun ĠtoString (): ĠString Ġ= Ġ" Lazy bones (" Ġ+ ĊĠĠĠ Ġ" lifecycle Owner =$ lifecycle Owner ," Ġ+ ĊĠĠĠ Ġ" lazy =$ lazy " Ġ+ ĊĠĠĠ Ġ")" Ċ } Ċ