package Ġcom . github . k xf eng . li ved ata Ċ Ċ import Ġandroidx . lifecycle . Com Github K xf eng LiveData Hidden Api . version Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ Ċ private Ġval ĠS IMP LE _ LI VE _ DATA _ TYPES Ġ= ĠarrayOf ( LiveData :: class . java , ĠMutable LiveData :: class . java ) Ċ private Ġval ĠFETCH _ LATE ST _ VERSION _ OB SERVER Ġ= ĠObserver < Any ?> Ġ{ Ġ} Ċ private Ġval ĠTRUE _ PRE D ICATE Ġ= Ġobject Ġ: ĠF resh Predicate Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġis Fresh (): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġtrue ĊĠĠĠ Ġ} Ċ } Ċ Ċ /** Ċ Ġ* ĠOb serve Ġfresh ly , Ġwhich Ġmeans Ġthe Ġobserver Ġwill Ġonly Ġreceive Ġnew Ġvalue Ġafter Ġnow , Ġprevious Ġvalue Ġwon 't Ġdispatch Ġto Ġit . Ċ Ġ* Ċ Ġ* ĠWhen Ġyou Ġobserve Ġyour Ġobserver Ġby Ġthis Ġmethod , Ġif Ġyou Ġwant Ġto Ġmanually Ġremove Ġthe Ġobserver Ġfrom Ġthis ĠLive Data , Ġyou Ġmust Ċ Ġ* Ġuse Ġ[ remove Observer Fresh ly ] Ġinstead Ġof Ġusing Ġ[ LiveData . remove Observer ] Ġdirectly . ĠOr Ġyou Ġcan Ġlet ĠLive Data Ġautomatically Ċ Ġ* Ġremove Ġyour Ġobserver Ġwhen Ġthe ĠLifecycle Owner Ġdestroy . Ċ Ġ* Ċ Ġ* Ġ@ param Ġowner ĠThe ĠLifecycle Owner Ġwhich Ġcontrols Ġthe Ġobserver Ċ Ġ* Ġ@ param Ġobserver ĠThe Ġobserver Ġthat Ġwill Ġreceive Ġthe Ġevents Ċ Ġ* Ġ@ param Ġskip Pending Value ĠSkip Ġvalue Ġwhich Ġhas Ġnot Ġar rived Ġthe ĠLive Data , Ġbut Ġthe Ġvalue Ġwas Ġtriggered Ġbefore . ĠFor Ġexample Ċ Ġ* Ġa ĠMed iator LiveData Ġreturned Ġfrom Ġ[ android x . lifecycle . Transform ations . map ], Ġwhen Ġit Ġhas Ġnone Ġactive Ġob servers , Ġchange Ċ Ġ* Ġvalue Ġof Ġit 's Ġsource ĠLive Data , Ġthe Ġvalue Ġof Ġthis ĠMed iator LiveData Ġwill Ġstill Ġbe Ġit 's Ġprevious Ġvalue , Ġthe Ġmapped Ġnew Ċ Ġ* Ġvalue Ġwill Ġar rive Ġthe ĠMed iator LiveData Ġuntil Ġit Ġhas Ġa Ġactive Ġobserver . ĠThis Ġmethod Ġtreat Ġthis Ġkind Ġof Ġnew Ġvalue Ġas Ġnot Ċ Ġ* Ġfresh Ġvalue Ġby Ġdefault , Ġbut Ġyou Ġcan Ġset Ġthis Ġparameter Ġto Ġfalse Ġto Ġtreat Ġit Ġas Ġfresh Ġvalue . Ċ Ġ*/ Ċ @ Jvm Over loads Ċ fun Ġ< T > ĠLive Data < T >. observe Fresh ly ( owner : ĠLifecycle Owner , Ġobserver : ĠObserver < in ĠT >, Ġskip Pending Value : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġif Ġ( skip Pending Value Ġ&& Ġthis . java Class Ġ! in ĠS IMP LE _ LI VE _ DATA _ TYPES Ġ&& Ġ! has Active Observer s ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . observe Fore ver ( FETCH _ LATE ST _ VERSION _ OB SERVER ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġsince Version Ġ= Ġthis . version () ĊĠĠĠ Ġthis . observe ( owner , ĠF resh Observer < T >( observer , ĠF resh Version Predicate ( this , Ġsince Version ))) Ċ } Ċ Ċ /** Ċ Ġ* ĠOb serve Ġforever Ġfresh ly , Ġwhich Ġmeans Ġthe Ġobserver Ġwill Ġonly Ġreceive Ġnew Ġvalue Ġafter Ġnow , Ġprevious Ġvalue Ġwon 't Ġdispatch Ġto Ġit . Ċ Ġ* Ċ Ġ* ĠWhen Ġyou Ġobserve Ġyour Ġobserver Ġby Ġthis Ġmethod , Ġif Ġyou Ġwant Ġto Ġremove Ġthe Ġobserver Ġfrom Ġthis ĠLive Data , Ġyou Ġmust Ġuse Ċ Ġ* Ġ[ remove Observer Fresh ly ] Ġinstead Ġof Ġusing Ġ[ LiveData . remove Observer ] Ġdirectly . Ċ Ġ* Ċ Ġ* Ġ@ param Ġobserver ĠThe Ġobserver Ġthat Ġwill Ġreceive Ġthe Ġevents Ċ Ġ* Ġ@ param Ġskip Pending Value ĠSee Ġdoc Ġin Ġ[ observe Fresh ly ] Ċ Ġ* Ċ Ġ*/ Ċ @ Jvm Over loads Ċ fun Ġ< T > ĠLive Data < T >. observe Fore ver Fresh ly ( observer : ĠObserver < in ĠT >, Ġskip Pending Value : ĠBoolean Ġ= Ġtrue ) Ġ{ ĊĠĠĠ Ġif Ġ( skip Pending Value Ġ&& Ġthis . java Class Ġ! in ĠS IMP LE _ LI VE _ DATA _ TYPES Ġ&& Ġ! has Active Observer s ()) Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . observe Fore ver ( FETCH _ LATE ST _ VERSION _ OB SERVER ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġval Ġsince Version Ġ= Ġthis . version () ĊĠĠĠ Ġthis . observe Fore ver ( Fresh Observer < T >( observer , ĠF resh Version Predicate ( this , Ġsince Version ))) Ċ } Ċ Ċ /** Ċ Ġ* ĠRemoves Ġthe Ġobserver Ġwhich Ġhas Ġbeen Ġpreviously Ġobserved Ġby Ġ[ observe Fresh ly ] Ġor Ġ[ observe Fore ver Fresh ly ]. Ċ Ġ*/ Ċ fun Ġ< T > ĠLive Data < T >. remove Observer Fresh ly ( observer : ĠObserver < in ĠT >) Ġ{ ĊĠĠĠ Ġthis . remove Observer ( Fresh Observer < T >( observer , ĠTRUE _ PRE D ICATE )) Ċ } Ċ Ċ internal Ġclass ĠF resh Version Predicate ( private Ġval Ġlive Data : ĠLive Data <* >, Ġprivate Ġval Ġsince Version : ĠInt ) Ġ: ĠF resh Predicate Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġis Fresh (): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġlive Data . version () Ġ> Ġsince Version ĊĠĠĠ Ġ} Ċ }