package Ġcom . bl ues ir 9 . as util . library . permissions . check Ċ Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . bl ues ir 9 . as util . library . core . platform _ element . As util ViewModel Ċ import Ġcom . bl ues ir 9 . as util . library . permissions . common . Permission Ċ import Ġkotlinx . coroutines . Coroutine Start Ċ import Ġkotlinx . coroutines . async Ċ import Ġkotlinx . coroutines . coroutine Scope Ċ import Ġkotlinx . coroutines . flow . Mutable Shared Flow Ċ import Ġkotlinx . coroutines . flow . first Ċ import Ġkotlinx . coroutines . launch Ċ Ċ class ĠIs Permission Granted ViewModel Ġ: ĊĠ ĠIs Permission Granted , ĊĠ ĠAs util ViewModel < Permission ? >( init Platform Model Ġ= Ġnull ) Ġ{ ĊĊĠ Ġprivate Ġval Ġpermission Results Ġ= ĠMutable Shared Flow < Pair < Permission , ĠBoolean >>() ĊĊĠ Ġoverride Ġsuspend Ġfun Ġinvoke ( permission : ĠPermission ): ĠBoolean Ġ= ĊĠĠĠ Ġcoroutine Scope Ġ{ ĊĠĠĠĠĠ Ġ/* ĊĠĠĠĠĠ ĠAs Ġsoon Ġas Ġwe Ġcall Ġ` update Model ( permission )`, Ġthe Ġresult Ġof Ġthe Ġpermission Ġstatus Ġcheck ĊĠĠĠĠĠ Ġwill Ġbe Ġemitted Ġand Ġwill Ġbe Ġlost Ġsince Ġwe Ġare Ġusing Ġa Ġ` Shared Flow ` Ġto Ġcapture Ġit . ĊĊĠĠĠĠĠ ĠUsing Ġan Ġ` async ` Ġblock Ġallows Ġus Ġto Ġstore Ġand Ġaccess Ġthe Ġresult Ġof Ġthe Ġpermission Ġcheck Ġand ĊĠĠĠĠĠ Ġwe Ġcan Ġcall Ġ` update Model ( permission )` Ġany time Ġsuitable Ġto Ġexecute Ġthe Ġpermission Ġstatus Ġcheck . ĊĠĠĠĠĠ Ġ*/ ĊĠĠĠĠĠ Ġval Ġresult Ġ= Ġasync ( start Ġ= ĠCor outine Start . UN DISPATCH ED ) Ġ{ ĊĠĠĠĠĠĠĠ Ġpermission Results . first Ġ{ Ġit . first Ġ== Ġpermission Ġ}. second ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġupdate Model ( permission ) ĊĊĠĠĠĠĠ Ġresult . await () ĊĠĠĠ Ġ} ĊĊĠ Ġfun Ġon Permission Result ( permission : ĠPermission , Ġgranted : ĠBoolean ) Ġ{ ĊĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠ Ġpermission Results . emit ( Pair ( permission , Ġgranted )) ĊĠĠĠĠĠ Ġupdate Model ( null ) ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ }