package Ġbr . com . intel ize . t ren ag ps . ui . finish Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . arch . lifecycle . Observer Ċ import Ġandroid . os . Bundle Ċ import Ġbr . com . intel ize . t ren ag ps . R . layout . activity _ save _ or _ cancel Ċ import Ġbr . com . intel ize . t ren ag ps . model . Measure Type Ċ import Ġbr . com . intel ize . t ren ag ps . model . Measure Type . Companion . MEAS URE _ TYPE _ EXTRA Ċ import Ġbr . com . intel ize . t ren ag ps . ui . base . Base Activity Ċ import Ġbr . com . intel ize . t ren ag ps . ui . main . MainActivity . Companion . MEAS URE D _ VALUE _ EXTRA Ċ import Ġkotlinx . android . synt hetic . main . activity _ save _ or _ cancel .* Ċ import Ġorg . k oin . android . architecture . ext . viewModel Ċ Ċ class ĠSave Or Cancel Activity Ġ: ĠBase Activity () Ġ{ ĊĊ ĉ private Ġval ĠviewModel Ġby ĠviewModel < Save Or Cancel ViewModel >() ĊĊ ĉ private Ġval Ġmeasure Type Ġby Ġlazy Ġ{ Ċĉ ĉ Measure Type . Type . values ()[ intent . getInt Extra ( MEAS URE _ TYPE _ EXTRA , Ġ 0 )] Ċ ĉ } ĊĊ ĉ private Ġval Ġmeasured Input Value Ġby Ġlazy Ġ{ Ċĉ ĉ intent . get Float Extra ( MEAS URE D _ VALUE _ EXTRA , Ġ 0 . 0 F ) Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ set ContentView ( activity _ save _ or _ cancel ) ĊĊĉ ĉ configure Actions () Ċĉ ĉ configure Ui () ĊĊĉ ĉ viewModel . success . observe ( this , ĠObserver Ġ{ Ċĉĉ ĉ it ?. let Ġ{ Ċĉĉĉ ĉ if Ġ( it ) Ġ{ Ċĉĉĉĉ ĉ set Result ( Activity . RESULT _ OK ) Ċĉĉĉĉ ĉ on Back Pressed () Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ }) Ċ ĉ } ĊĊ ĉ private Ġfun Ġconfigure Ui () Ġ{ Ċĉ ĉ meas ured Value . text Ġ= ĠString . format ("% . 2 f ", Ġmeasured Input Value ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġconfigure Actions () Ġ{ Ċĉ ĉ save Button . setOnClickListener Ġ{ ĠviewModel . save ( measure Name . text , Ġmeasured Value . text , Ġmeasure Type ) Ġ} Ċĉ ĉ configure Discard Button Action () Ċ ĉ } ĊĊ ĉ private Ġfun Ġconfigure Discard Button Action () Ġ{ Ċĉ ĉ discard Button . setOnClickListener Ġ{ Ċĉĉ ĉ on Back Pressed () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Back Pressed () Ġ{ Ċĉ ĉ super . on Back Pressed () Ċĉ ĉ override Pending Transition ( 0 , Ġ 0 ) Ċĉ ĉ finish () Ċ ĉ } Ċ } Ċ