package Ġcom . ray w ender lich . android . pe ts ave . sharing . presentation Ċ Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . ray w ender lich . android . pe ts ave . common . domain . use cases . Get Animal Details Ċ import Ġcom . ray w ender lich . android . pe ts ave . common . utils . Dispatch ers Provider Ċ import Ġcom . ray w ender lich . android . pe ts ave . sharing . presentation . model . map pers . Ui Animal To Share Mapper Ċ import Ġkotlinx . coroutines . flow . Mutable State Flow Ċ import Ġkotlinx . coroutines . flow . State Flow Ċ import Ġkotlinx . coroutines . launch Ċ import Ġkotlinx . coroutines . with Context Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠSh aring Fragment ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġget Animal Details : ĠGet Animal Details , ĊĠĠĠ Ġprivate Ġval Ġui Animal To Share Mapper : ĠUi Animal To Share Mapper , ĊĠĠĠ Ġprivate Ġval Ġdispatch ers Provider : ĠDispatch ers Provider Ċ ): ĠViewModel () Ġ{ ĊĊĠ Ġval Ġview State : ĠState Flow < Sharing ViewState > Ġget () Ġ= Ġ_ view State ĊĊĠ Ġprivate Ġval Ġ_ view State Ġ= ĠMutable State Flow ( Sharing ViewState ()) ĊĊĠ Ġfun Ġon Event ( event : ĠSh aring Event ) Ġ{ ĊĠĠĠ Ġwhen Ġ( event ) Ġ{ ĊĠĠĠĠĠ Ġis ĠSh aring Event . Get Animal To Share Ġ-> Ġget Animal To Share ( event . animal Id ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġget Animal To Share ( animal Id : ĠLong ) Ġ{ ĊĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠ Ġval Ġanimal Ġ= Ġwith Context ( dispatch ers Provider . io ()) Ġ{ Ġget Animal Details ( animal Id ) Ġ} ĊĊĠĠĠĠĠ Ġ_ view State . value Ġ= Ġview State . value . copy ( ĊĠĠĠĠĠĠĠĠĠ Ġanimal To Share Ġ= Ġ Ġui Animal To Share Mapper . map To View ( animal ) ĊĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }