package Ġcom . d roid con . speak ers . presentation . speaker detail . view model Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . d roid con . commons . conference . domain . Update Session Star red Value Ċ import Ġcom . d roid con . commons . tracking . Speaker Detail Tracker Ċ import Ġcom . d roid con . speak ers . domain . Get Speaker Ċ import Ġcom . d roid con . speak ers . domain . Get Speaker Sessions Ċ import Ġcom . d roid con . speak ers . domain . Speaker Ċ import Ġcom . d roid con . speak ers . domain . Speaker Session Ċ import Ġcom . d roid con . speak ers . presentation . speaker detail . model .* Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠS peaker Detail ViewModel ( ĊĠĠĠ Ġprivate Ġval Ġget Speaker : ĠGet Speaker , ĊĠĠĠ Ġprivate Ġval Ġget Speaker Sessions : ĠGet Speaker Sessions , ĊĠĠĠ Ġprivate Ġval Ġupdate Session Star red Value : ĠUpdate Session Star red Value , ĊĠĠĠ Ġprivate Ġval Ġspeaker Detail Tracker : ĠS peaker Detail Tracker Ċ ) Ġ: ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġmutable Speaker Detail State Ġ= ĠMutable LiveData < Speaker Detail State >() ĊĠĠĠ Ġval Ġspeaker Detail State : ĠLive Data < Speaker Detail State > Ġ= Ġmutable Speaker Detail State ĊĊĠĠĠ Ġprivate Ġval Ġmutable Speaker Detail Effects Ġ= ĠMutable LiveData < Speaker Detail Effect >() ĊĠĠĠ Ġval Ġspeaker Detail Effects : ĠLive Data < Speaker Detail Effect > Ġ= Ġmutable Speaker Detail Effects ĊĊĠĠĠ Ġfun Ġon Speaker Detail Visible ( speaker Id : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġget Speaker Result Ġ= Ġget Speaker ( speaker Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġspeaker Sessions Ġ= Ġget Speaker Sessions ( speaker Id ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġget Speaker Result . fold ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Left Ġ= Ġ{}, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Right Ġ= Ġ{ Ġspeaker Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġon Get Speaker Success ( speaker , Ġspeaker Sessions ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Get Speaker Success ( speaker : ĠS peaker , Ġspeaker Sessions : ĠList < Speaker Session >) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġspeaker Detail State Ġ= Ġspeaker . to Detail State ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġspeaker Sessions , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ:: on Session Star red , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ:: on Session Clicked ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġmutable Speaker Detail State . value Ġ= Ġspeaker Detail State ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Session Star red ( session : ĠS peaker Detail Row . Session , Ġis Star red : ĠBoolean ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġnew Is Star red Value Ġ= Ġ! is Star red ĊĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Session Star red State ( session . id , Ġnew Is Star red Value ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġis Session Updated Ġ= Ġupdate Session Star red Value ( session . id , Ġnew Is Star red Value ) ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ(! is Session Updated ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Session Star red State ( session . id , Ġis Star red ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġspeaker Detail Tracker . track Session Star red ( session . talk Title , Ġnew Is Star red Value ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Session Star red State ( sessionId : ĠString , Ġis Star red : ĠBoolean ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġspeaker Detail State Ġ= Ġmutable Speaker Detail State . value Ġ?: Ġreturn ĊĠĠĠĠĠĠĠ Ġval Ġupdated Sessions Ġ= Ġspeaker Detail State . speaker Sessions . map Ġ{ Ġsession Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( session . id Ġ== ĠsessionId ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsession . copy ( is Star red Ġ= Ġis Star red ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsession ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġmutable Speaker Detail State . value Ġ= Ġspeaker Detail State . copy ( speaker Sessions Ġ= Ġupdated Sessions ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Session Clicked ( session : ĠS peaker Detail Row . Session ) Ġ{ ĊĠĠĠĠĠĠĠ Ġmutable Speaker Detail Effects . value Ġ= ĠS peaker Detail Effect . Navigate To Session ( session . id ) ĊĠĠĠĠĠĠĠ Ġspeaker Detail Tracker . track Session Opened ( session . talk Title ) ĊĠĠĠ Ġ} Ċ }