package Ġcn . al vince . z an pak uto . rx java 2 . k tx Ċ Ċ import Ġandroidx . annotation . MainThread Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . Lifecycle Ċ import Ġandroidx . lifecycle . Lifecycle Event Observer Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġcn . al vince . z an pak uto . rx java 2 . Rx Fragment Lifecycle Registry Ċ import Ġcn . al vince . z an pak uto . rx java 2 . internal . Destroyed Lifecycle Owner Ċ Ċ @ MainThread Ċ fun ĠFragment . rx Lifecycle Registry (): ĠRx Fragment Lifecycle Registry Ġ{ ĊĠĠĠ Ġif Ġ( this Ġis ĠRx Fragment Lifecycle Registry ) Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġthis ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn Ġobtain Rx Registry () Ċ } Ċ Ċ private Ġval Ġfragment Regist ries Record Ġ= ĠRegistry Holder < Rx Fragment Lifecycle Registry >() Ċ Ċ private Ġval Ġdestroyed Registry Holder Ġ= ĠRx Fragment Lifecycle Registry (). apply Ġ{ ĊĠĠĠ ĠDestroy ed Lifecycle Owner (). also Ġ{ ĊĠĠĠĠĠĠĠ Ġattach To Lifecycle ( it ) ĊĠĠĠĠĠĠĠ Ġattach To View Lifecycle ( it ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ @ MainThread Ċ private Ġfun ĠFragment . obtain Rx Registry (): ĠRx Fragment Lifecycle Registry Ġ{ ĊĠĠĠ Ġval Ġkey Ġ= Ġthis . hashCode () ĊĠĠĠ Ġval Ġexist Ġ= Ġfragment Regist ries Record [ key ] ĊĠĠĠ Ġif Ġ( exist Ġ!= Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġexist ĊĠĠĠ Ġ} ĊĠĠĠ Ġif Ġ( lifecycle . currentState Ġ== ĠLifecycle . State . DESTROY ED ) Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġdestroyed Registry Holder ĊĠĠĠ Ġ} ĊĠĠĠ Ġreturn ĠRx Fragment Lifecycle Registry (). also Ġ{ Ġregistry Ġ-> ĊĠĠĠĠĠĠĠ Ġregistry . attach To Lifecycle ( this ) ĊĠĠĠĠĠĠĠ Ġfragment Regist ries Record . put ( key , Ġregistry ) ĊĠĠĠĠĠĠĠ Ġlifecycle . add Observer ( object Ġ: ĠLifecycle Event Observer Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon StateChanged ( source : ĠLifecycle Owner , Ġevent : ĠLifecycle . Event ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( event Ġ== ĠLifecycle . Event . ON _ DESTROY ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsource . lifecycle . remove Observer ( this ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ( source Ġas ? ĠFragment )?. clear () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠ Ġview Lifecycle Owner LiveData . observe ( this ) Ġ{ Ġregistry . attach To View Lifecycle ( it ) Ġ} ĊĠĠĠ Ġ} Ċ } Ċ Ċ private Ġfun ĠFragment . clear () Ġ{ ĊĠĠĠ Ġval Ġhash Key Ġ= Ġthis . hashCode () ĊĠĠĠ Ġfragment Regist ries Record . clear ( hash Key ) Ċ } Ċ