package Ġcom . example . ex ch anger ates . presentation . fragment . mon etary Fragment Ċ Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . example . ex ch anger ates . domain . model . Money Room Model Ċ import Ġcom . example . ex ch anger ates . domain . model . Result e ApiModel Ċ import Ġcom . example . ex ch anger ates . domain . use case . Make Api UseCase Ċ import Ġcom . example . ex ch anger ates . domain . use case . Make Db Data UseCase Ċ import Ġkotlinx . coroutines . Job Ċ import Ġkotlinx . coroutines . async Ċ import Ġkotlinx . coroutines . flow . Mutable Shared Flow Ċ import Ġkotlinx . coroutines . flow . Shared Flow Ċ import Ġkotlinx . coroutines . flow . as Shared Flow Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjavax . inject . Inject Ċ Ċ class ĠMon etary Rate Menu Fragment ViewModel Ġ@ Inject Ġconstructor ( ĊĠĠĠ Ġprivate Ġval Ġmake Api UseCase : ĠMake Api UseCase , ĊĠĠĠ Ġprivate Ġval Ġmake Db Data UseCase : ĠMake Db Data UseCase , ĊĠĠĠ Ġ): ĠViewModel () Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġjob ViewModel : Job ? Ġ= Ġnull ĊĊĠĠĠ Ġprivate Ġval Ġ_ data Api Ġ= ĠMutable Shared Flow < Result e ApiModel >() ĊĠĠĠ Ġval Ġdata Api : Shared Flow < Result e ApiModel > Ġ= Ġ_ data Api . as Shared Flow () ĊĊĠĠĠ Ġprivate Ġval Ġ_ db Data Ġ= ĠMutable Shared Flow < List < Money Room Model >>() ĊĠĠĠ Ġval Ġdb Data : Shared Flow < List < Money Room Model >> Ġ= Ġ_ db Data . as Shared Flow () ĊĊĠĠĠ Ġfun Ġmake Api (){ ĊĠĠĠĠĠĠĠ Ġjob ViewModel Ġ= ĠviewModel Scope . async Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ data Api . emit ( make Api UseCase . do It ()) ĊĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġjob ViewModel !!. start () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġcancel Coroutine () Ġ{ ĊĠĠĠĠĠĠĠ Ġjob ViewModel !!. cancel () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġmake Db Data (){ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ db Data . emit ( make Db Data UseCase . do It ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }