package Ġcom . gy org yz olt an . sp ray App . work . configuration Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . as LiveData Ċ import Ġandroidx . lifecycle . viewModel Scope Ċ import Ġcom . gy org yz olt an . sp ray App . domain . configuration . Configuration UseCase Ċ import Ġcom . gy org yz olt an . sp ray App . domain . configuration . Refresh Configuration UseCase Ċ import Ġcom . gy org yz olt an . sp ray App . main . R Ċ import Ġcom . gy org yz olt an . sp ray App . main . shared . list . List ViewModel Ċ import Ġcom . gy org yz olt an . sp ray App . main . shared . utilities . Consum able Ċ import Ġcom . gy org yz olt an . sp ray App . model . Configuration Ċ import Ġcom . gy org yz olt an . sp ray App . model . shared . Data State Ċ import Ġcom . gy org yz olt an . sp ray App . model . shared . Repository Not Initialized Exception Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Done Button ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration ListItem Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration No Selection ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Selected No zzle Count ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Selected No zzle Dark ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Selected No zzle Distance ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Selected No zzle Light ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Selected Scre w Count ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration Selected Wheel Radius ViewHolder Ċ import Ġcom . gy org yz olt an . sp ray App . work . configuration . list . Configuration TextView Holder Ċ import Ġkotlinx . coroutines . flow . launch In Ċ import Ġkotlinx . coroutines . flow . map Ċ import Ġkotlinx . coroutines . flow . on Each Ċ import Ġkotlinx . coroutines . launch Ċ Ċ internal Ġclass ĠConfiguration ViewModel ( ĊĠĠĠ Ġconfiguration : ĠConfiguration UseCase , ĊĠĠĠ Ġprivate Ġval Ġrefresh Configuration : ĠRefresh Configuration UseCase Ċ ) Ġ: ĠList ViewModel < Configuration ListItem >( true ) Ġ{ ĊĊĠĠĠ Ġoverride Ġval Ġitems Ġ= Ġconfiguration (). map Ġ{ Ġit . to Items () Ġ}. as LiveData () ĊĠĠĠ Ġoverride Ġval Ġshould Show Loading Indicator Ġ= Ġconfiguration (). map Ġ{ Ġit Ġis ĠData State . Loading Ġ}. as LiveData () ĊĠĠĠ Ġoverride Ġval Ġshould Show Error View Ġ= Ġconfiguration (). map Ġ{ Ġit Ġis ĠData State . Error Ġ&& Ġit . data Ġ== Ġnull Ġ}. as LiveData () ĊĠĠĠ Ġprivate Ġval Ġ_ events Ġ= ĠMutable LiveData < Consum able < Event >>() ĊĠĠĠ Ġval Ġevents : ĠLive Data < Consum able < Event >> Ġ= Ġ_ events ĊĠĠĠ Ġprivate Ġvar Ġcurrent Wheel Radius : ĠFloat ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġcurrent Scre w Count : ĠInt ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġcurrent No zzle Count : ĠInt ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġcurrent No zzle Distance : ĠFloat ? Ġ= Ġnull ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġconfiguration (). on Each Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( it Ġis ĠData State . Error Ġ&& Ġit . data Ġ!= Ġnull Ġ&& Ġit . exception Ġ! is ĠRepository Not Initialized Exception ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ_ events . value Ġ= ĠCon sum able ( Event . Show Error Snackbar ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Wheel Radius Ġ= Ġit . data ?. wheel Radius ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Scre w Count Ġ= Ġit . data ?. sc rew Count ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent No zzle Count Ġ= Ġit . data ?. no zzle Count ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent No zzle Distance Ġ= Ġit . data ?. no zzle Distance ĊĠĠĠĠĠĠĠ Ġ}. launch In ( viewModel Scope ) ĊĠĠĠĠĠĠĠ Ġload Data ( false ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġload Data ( is Force Refresh : ĠBoolean ) Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel Scope . launch Ġ{ Ġrefresh Configuration ( is Force Refresh ) Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġon Done Button Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ events . value Ġ= ĠCon sum able ( Event . Close Screen ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġon No Selection Item Clicked ( hint ResourceId : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ events . value Ġ= Ġwhen Ġ( hint ResourceId ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . string . configuration _ no _ no zzle _ selected Ġ-> ĠCon sum able ( Event . Navigate To No zzle Picker ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . string . configuration _ no _ wheel _ radius _ set Ġ-> ĠCon sum able ( Event . Navigate To Wheel Radius Picker ( current Wheel Radius )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . string . configuration _ no _ sc rew _ count _ set Ġ-> ĠCon sum able ( Event . Navigate ToS cre w Count Picker ( current Scre w Count )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . string . configuration _ no _ no zzle _ count _ set Ġ-> ĠCon sum able ( Event . Navigate To No zzle Count Picker ( current No zzle Count )) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . string . configuration _ no _ no zzle _ distance _ set Ġ-> ĠCon sum able ( Event . Navigate To No zzle Distance Picker ( current No zzle Distance )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> Ġthrow Ġ ĠIllegalArgumentException (" Invalid Ġhint Ġresource ĠID : Ġ$ hint ResourceId ") ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġon No zzle Clicked () Ġ{ ĊĠĠĠĠĠĠĠ Ġ_ events . value Ġ= ĠCon sum able ( Event . Navigate To No zzle Picker ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠData State < Configuration >. to Items () Ġ= Ġmutable ListOf < Configuration ListItem >(). apply Ġ{ ĊĠĠĠĠĠĠĠ Ġdata ?. let Ġ{ Ġconfiguration Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd No zzle Section ( configuration ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Wheel Radius Section ( configuration ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Scre w Count Section ( configuration ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd No zzle Count Section ( configuration ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd No zzle Distance Section ( configuration ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd ( Configuration Done Button ViewHolder . Ui Model ( configuration . isValid )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}. toList () ĊĊĠĠĠ Ġprivate Ġfun ĠMutable List < Configuration ListItem >. add No zzle Section ( configuration : ĠConfiguration ) Ġ{ ĊĠĠĠĠĠĠĠ Ġadd ( Configuration TextView Holder . Ui Model ( R . string . configuration _ no zzle )) ĊĠĠĠĠĠĠĠ Ġadd ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . no zzle . let Ġ{ Ġselected No zzle Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġselected No zzle Ġ== Ġnull Ġ-> ĠConfiguration No Selection ViewHolder . Ui Model ( R . string . configuration _ no _ no zzle _ selected ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġselected No zzle . color . is Dark Ġ-> ĠConfiguration Selected No zzle Dark ViewHolder . Ui Model ( configuration . no zzle ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĠConfiguration Selected No zzle Light ViewHolder . Ui Model ( configuration . no zzle ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠMutable List < Configuration ListItem >. add Wheel Radius Section ( configuration : ĠConfiguration ) Ġ{ ĊĠĠĠĠĠĠĠ Ġadd ( Configuration TextView Holder . Ui Model ( R . string . configuration _ wheel _ radius )) ĊĠĠĠĠĠĠĠ Ġadd ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . wheel Radius . let Ġ{ Ġselected Wheel Radius Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( selected Wheel Radius Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration No Selection ViewHolder . Ui Model ( R . string . configuration _ no _ wheel _ radius _ set ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration Selected Wheel Radius ViewHolder . Ui Model ( selected Wheel Radius ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠMutable List < Configuration ListItem >. add Scre w Count Section ( configuration : ĠConfiguration ) Ġ{ ĊĠĠĠĠĠĠĠ Ġadd ( Configuration TextView Holder . Ui Model ( R . string . configuration _ sc rew _ count )) ĊĠĠĠĠĠĠĠ Ġadd ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . sc rew Count . let Ġ{ Ġselected Scre w Count Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( selected Scre w Count Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration No Selection ViewHolder . Ui Model ( R . string . configuration _ no _ sc rew _ count _ set ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration Selected Scre w Count ViewHolder . Ui Model ( selected Scre w Count ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠMutable List < Configuration ListItem >. add No zzle Count Section ( configuration : ĠConfiguration ) Ġ{ ĊĠĠĠĠĠĠĠ Ġadd ( Configuration TextView Holder . Ui Model ( R . string . configuration _ no zzle _ count )) ĊĠĠĠĠĠĠĠ Ġadd ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . no zzle Count . let Ġ{ Ġselected No zzle Count Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( selected No zzle Count Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration No Selection ViewHolder . Ui Model ( R . string . configuration _ no _ no zzle _ count _ set ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration Selected No zzle Count ViewHolder . Ui Model ( selected No zzle Count ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠMutable List < Configuration ListItem >. add No zzle Distance Section ( configuration : ĠConfiguration ) Ġ{ ĊĠĠĠĠĠĠĠ Ġadd ( Configuration TextView Holder . Ui Model ( R . string . configuration _ no zzle _ distance )) ĊĠĠĠĠĠĠĠ Ġadd ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġconfiguration . no zzle Distance . let Ġ{ Ġselected No zzle Distance Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( selected No zzle Distance Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration No Selection ViewHolder . Ui Model ( R . string . configuration _ no _ no zzle _ distance _ set ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠConfiguration Selected No zzle Distance ViewHolder . Ui Model ( selected No zzle Distance ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġsealed Ġclass ĠEvent Ġ{ ĊĠĠĠĠĠĠĠ Ġobject ĠNavigate To No zzle Picker Ġ: ĠEvent () ĊĠĠĠĠĠĠĠ Ġdata Ġclass ĠNavigate To Wheel Radius Picker ( val Ġcurrent Wheel Radius : ĠFloat ?) Ġ: ĠEvent () ĊĠĠĠĠĠĠĠ Ġdata Ġclass ĠNavigate ToS cre w Count Picker ( val Ġcurrent Scre w Count : ĠInt ?) Ġ: ĠEvent () ĊĠĠĠĠĠĠĠ Ġdata Ġclass ĠNavigate To No zzle Count Picker ( val Ġcurrent No zzle Count : ĠInt ?) Ġ: ĠEvent () ĊĠĠĠĠĠĠĠ Ġdata Ġclass ĠNavigate To No zzle Distance Picker ( val Ġcurrent No zzle Distance : ĠFloat ?) Ġ: ĠEvent () ĊĠĠĠĠĠĠĠ Ġobject ĠClose Screen Ġ: ĠEvent () ĊĠĠĠĠĠĠĠ Ġobject ĠShow Error Snackbar Ġ: ĠEvent () ĊĠĠĠ Ġ} Ċ }