package Ġcom . ech sy lon . demo . screen . device Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . fragment . app . activity ViewModels Ċ import Ġcom . ech sy lon . demo . R Ċ import Ġcom . ech sy lon . demo . databinding . Device Fragment Binding Ċ import Ġcom . ech sy lon . demo . connection . model . Feature ĊĊ Ċ class ĠDevice Fragment Ġ: ĠFragment () Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġ_ binding : ĠDevice Fragment Binding ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠDevice ViewModel Ġby Ġactivity ViewModels () ĊĠĠĠ Ġprivate Ġval Ġadapter Ġ= ĠFeature Adapter () ĊĊĠĠĠ Ġprivate Ġval Ġbinding ĊĠĠĠĠĠĠĠ Ġget () Ġ= Ġ_ binding !! ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠDevice Fragment Binding . inflate ( in flater , Ġcontainer , Ġfalse ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. also Ġ{ Ġ_ binding Ġ= Ġit Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. let Ġ{ Ġit . root Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĠĠĠĠĠĠĠ Ġadapter . clear Features () ĊĠĠĠĠĠĠĠ Ġadapter . set DefaultValue ( getString ( R . string . not _ available )) ĊĠĠĠĠĠĠĠ Ġbinding . services . adapter Ġ= Ġadapter ĊĠĠĠĠĠĠĠ ĠviewModel . value . observe ( view Lifecycle Owner ) Ġ{ Ġon Value Change ( it . first , Ġit . second ) Ġ} ĊĠĠĠĠĠĠĠ ĠviewModel . features . observe ( view Lifecycle Owner ) Ġ{ Ġon Features Change ( it ) Ġ} ĊĠĠĠĠĠĠĠ ĠviewModel . connect Selected Device () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy View () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy View () ĊĠĠĠĠĠĠĠ ĠviewModel . disconnect Selected Device () ĊĠĠĠĠĠĠĠ Ġ_ binding Ġ= Ġnull ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Features Change ( features : ĠList < Feature >) Ġ{ ĊĠĠĠĠĠĠĠ Ġadapter . set Features ( features ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġon Value Change ( key : ĠString , Ġvalue : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġadapter . update Feature ( key , Ġvalue ) ĊĠĠĠ Ġ} Ċ }