package Ġde . r ki . cor on aw arn app . ui . view model Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġde . r ki . cor on aw arn app . exception . Exception Category Ċ import Ġde . r ki . cor on aw arn app . exception . Invalid QR Code Exc pet ion Ċ import Ġde . r ki . cor on aw arn app . exception . report Ċ import Ġde . r ki . cor on aw arn app . service . submission . Submission Service Ċ import Ġde . r ki . cor on aw arn app . storage . Local Data Ċ import Ġde . r ki . cor on aw arn app . storage . Submission Repository Ċ import Ġde . r ki . cor on aw arn app . ui . submission . ApiRequest State Ċ import Ġde . r ki . cor on aw arn app . ui . submission . Scan Status Ċ import Ġde . r ki . cor on aw arn app . util . formatter . TestResult Ċ import Ġkotlinx . coroutines . launch Ċ import Ġjava . util . Date Ċ Ċ class ĠSubmission ViewModel Ġ: ĠViewModel () Ġ{ ĊĠĠĠ Ġprivate Ġval Ġ_ scan Status Ġ= ĠMutable LiveData ( Scan Status . STARTED ) ĊĠĠĠ Ġprivate Ġval Ġ_ registration State Ġ= ĠMutable LiveData ( ApiRequest State . IDLE ) ĊĠĠĠ Ġprivate Ġval Ġ_ test Result State Ġ= ĠMutable LiveData ( ApiRequest State . IDLE ) ĊĠĠĠ Ġprivate Ġval Ġ_ auth Code State Ġ= ĠMutable LiveData ( ApiRequest State . IDLE ) ĊĠĠĠ Ġprivate Ġval Ġ_ submission State Ġ= ĠMutable LiveData ( ApiRequest State . IDLE ) ĊĊĠĠĠ Ġval Ġscan Status : ĠLive Data < Scan Status > Ġ= Ġ_ scan Status ĊĠĠĠ Ġval Ġregistration State : ĠLive Data < ApiRequest State > Ġ= Ġ_ registration State ĊĠĠĠ Ġval Ġtest Result State : ĠLive Data < ApiRequest State > Ġ= Ġ_ test Result State ĊĠĠĠ Ġval Ġauth Code State : ĠLive Data < ApiRequest State > Ġ= Ġ_ auth Code State ĊĠĠĠ Ġval Ġsubmission State : ĠLive Data < ApiRequest State > Ġ= Ġ_ submission State ĊĊĠĠĠ Ġval Ġdevice Registered Ġget () Ġ= ĠLocal Data . registration Token () Ġ!= Ġnull ĊĊĠĠĠ Ġval Ġtest Result : ĠLive Data < TestResult > Ġ= ĊĠĠĠĠĠĠĠ ĠSubmission Repository . test Result ĊĠĠĠ Ġval Ġtest Result Received Date : ĠLive Data < Date > Ġ= ĠSubmission Repository . test Result Received Date ĊĊĠĠĠ Ġfun Ġsubmit Di agnosis Keys () Ġ= ĊĠĠĠĠĠĠĠ Ġexecute Request With State ( Submission Service :: async Submit Exposure Keys , Ġ_ submission State ) ĊĊĠĠĠ Ġfun Ġdo Device Registration () Ġ= ĊĠĠĠĠĠĠĠ Ġexecute Request With State ( Submission Service :: async Register Device , Ġ_ registration State ) ĊĊĠĠĠ Ġfun Ġrefresh TestResult () Ġ= ĊĠĠĠĠĠĠĠ Ġexecute Request With State ( Submission Repository :: refresh TestResult , Ġ_ test Result State ) ĊĊĠĠĠ Ġfun Ġvalidate And Store Test GUID ( test GUID : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠSubmission Service . validate And Store Test GUID ( test GUID ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ scan Status . value Ġ= ĠScan Status . SUCCESS ĊĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( ex : ĠInvalid QR Code Exc pet ion ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ_ scan Status . value Ġ= ĠScan Status . INVALID ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdelete Test GUID () Ġ{ ĊĠĠĠĠĠĠĠ ĠSubmission Service . delete Test GUID () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdere gister Test From Device () Ġ{ ĊĠĠĠĠĠĠĠ Ġdelete Test GUID () ĊĠĠĠĠĠĠĠ ĠSubmission Service . delete Registration Token () ĊĠĠĠĠĠĠĠ ĠLocal Data . is Allowed To Submit Di agnosis Keys ( false ) ĊĠĠĠĠĠĠĠ ĠLocal Data . init ital TestResult Received Timestamp ( 0 L ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġexecute Request With State ( api Request : Ġsuspend Ġ() Ġ-> ĠUnit , Ġstate : ĠMutable LiveData < ApiRequest State >) Ġ{ ĊĠĠĠĠĠĠĠ Ġstate . value Ġ= ĠApi Request State . STARTED ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġapi Request () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstate . value Ġ= ĠApi Request State . SUCCESS ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġcatch Ġ( err : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġstate . value Ġ= ĠApi Request State . FAILED ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġerr . report ( Exception Category . INTERNAL ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ