package Ġuk . co . v ict oria jan ed avis . chat app . presentation . ui . friend requests . received Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġio . reactivex . dis pos ables . Composite Disposable Ċ import Ġio . reactivex . dis pos ables . Disposable Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ import Ġuk . co . v ict oria jan ed avis . chat app . domain . entities . Friend ship Entity Ċ import Ġuk . co . v ict oria jan ed avis . chat app . domain . inter actors . Accept Received Friend Request Ċ import Ġuk . co . v ict oria jan ed avis . chat app . domain . inter actors . Get Received Friend Requests List Ċ import Ġuk . co . v ict oria jan ed avis . chat app . domain . inter actors . Refresh Received Friend Requests Ċ import Ġuk . co . v ict oria jan ed avis . chat app . domain . inter actors . Reject Received Friend Request Ċ import Ġuk . co . v ict oria jan ed avis . chat app . presentation . common . List State Ċ import Ġuk . co . v ict oria jan ed avis . chat app . presentation . common . List State .* Ċ import Ġuk . co . v ict oria jan ed avis . chat app . domain . common . Stream State .* Ċ import Ġjava . util . UUID Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠReceived Friend Requests ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġget Received Friend Requests : ĠGet Received Friend Requests List , ĊĠĠĠ Ġprivate Ġval Ġrefresh Received Friend Requests : ĠRefresh Received Friend Requests , ĊĠĠĠ Ġprivate Ġval Ġaccept Friend Request : ĠAccept Received Friend Request , ĊĠĠĠ Ġprivate Ġval Ġreject Friend Request : ĠReject Received Friend Request Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġfriend LiveData Ġ= ĠMutable LiveData < List State < List < Friend ship Entity >> >() ĊĠĠĠ Ġprivate Ġval Ġcomposite Disposable Ġ= ĠComposite Disposable () ĊĠĠĠ Ġprivate Ġvar Ġrefresh Disposable : ĠDis posable ? Ġ= Ġnull ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġfriend LiveData . value Ġ= ĠShow Loading ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( bind To UseCase ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Cle ared () Ġ{ ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . dispose () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġget Received Friend Requests LiveData (): ĠLive Data < List State < List < Friend ship Entity >>> Ġ= Ġfriend LiveData ĊĊĠĠĠ Ġfun Ġrefresh Items () Ġ{ ĊĠĠĠĠĠĠĠ Ġrefresh Disposable ?. let Ġ{ Ġit Ġ-> Ġcomposite Disposable . remove ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġrefresh Disposable Ġ= Ġrefresh Received Friend Requests . get Refresh Single ( null ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ({ friend LiveData . value Ġ= ĠStop Loading }, Ġ{ Ġe Ġ-> ĠonError ( e ) Ġ}) ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( refresh Disposable !! ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġaccept Friend Request ( sender User Uuid : ĠUUID ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( bind To Accept Friend Request ( sender User Uuid )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġreject Friend Request ( sender User Uuid : ĠUUID ) Ġ{ ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( bind To Reject Friend Request ( sender User Uuid )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġbind To UseCase () Ġ: ĠDis posable Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġget Received Friend Requests . get Behavior Stream ( null ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe Ġ{ Ġstream State Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwhen Ġ( stream State ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠOnNext Ġ-> Ġon Next ( stream State . content ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġis ĠOn Error Ġ-> ĠonError ( stream State . throwable ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Next ( friend Entities : ĠList < Friend ship Entity >) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! friend Entities . isEmpty ()) Ġfriend LiveData . value Ġ= ĠShow Content ( friend Entities ) ĊĠĠĠĠĠĠĠ Ġelse Ġfriend LiveData . value Ġ= ĠShow Empty ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠonError ( e : ĠThrowable ) Ġ{ ĊĠĠĠĠĠĠĠ Ġfriend LiveData . value Ġ= ĠShow Error ( e . message Ġ?: Ġe . toString ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġbind To Accept Friend Request ( sender User Uuid : ĠUUID ) Ġ: ĠDis posable Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġaccept Friend Request . getAction Comp letable ( sender User Uuid ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. unsubscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ({}, Ġ{ Ġe Ġ-> ĠonError ( e ) Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġbind To Reject Friend Request ( sender User Uuid : ĠUUID ) Ġ: ĠDis posable Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġreject Friend Request . getAction Comp letable ( sender User Uuid ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. unsubscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ({}, Ġ{ Ġe Ġ-> ĠonError ( e ) Ġ}) ĊĠĠĠ Ġ} Ċ }