package Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . ui . registration Ċ Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Mutable LiveData Ċ import Ġandroidx . lifecycle . ViewModel Ċ import Ġar . edu . ut n . fr ba . mobile . a 2 0 1 9 c 1 . super hero es . R Ċ Ċ class ĠRegistration ViewModel Ġ: ĠViewModel () Ġ{ ĊĊ ĉ private Ġval Ġ_ registration Form Ġ= ĠMutable LiveData < Registration Form State >() Ċ ĉ val Ġregistration Form State : ĠLive Data < Registration Form State > Ġ= Ġ_ registration Form ĊĊ ĉ private Ġval Ġ_ registration Result Ġ= ĠMutable LiveData < Registration Result >() Ċ ĉ val Ġregistration Result : ĠLive Data < Registration Result > Ġ= Ġ_ registration Result ĊĊ ĉ fun Ġsuccessful Registration ( nickname : ĠString ) Ġ{ Ċĉ ĉ _ registration Result . value Ġ= ĠRegistration Result ( display Nick name Ġ= Ġnickname ) Ċ ĉ } ĊĊ ĉ fun Ġfailed Registration () Ġ{ Ċĉ ĉ _ registration Result . value Ġ= ĠRegistration Result ( error Ġ= ĠR . string . registration _ failed ) Ċ ĉ } ĊĊ ĉ fun Ġvalidate Form ( username : ĠString ) Ġ= Ġwhen Ġ( username . length ) Ġ{ Ċĉĉ 0 Ġ-> Ġ{ Ċĉĉ ĉ _ registration Form . value Ġ= ĠRegistration Form State ( nickname Error Ġ= ĠR . string . empty _ nickname ) Ċĉĉ ĉ false Ċĉ ĉ } Ċĉ ĉ in Ġ 1 .. 4 Ġ-> Ġ{ Ċĉĉ ĉ _ registration Form . value Ġ= ĠRegistration Form State ( nickname Error Ġ= ĠR . string . invalid _ nickname ) Ċĉĉ ĉ false Ċĉ ĉ } Ċĉ ĉ else Ġ-> Ġtrue Ċ ĉ } Ċ Ċ } Ċ Ċ data Ġclass ĠRegistration Form State ( val Ġnickname Error : ĠInt ? Ġ= Ġnull , Ġval Ġis Data Valid : ĠBoolean Ġ= Ġfalse ) Ċ Ċ data Ġclass ĠRegistration Result ( val Ġdisplay Nick name : ĠString ? Ġ= Ġnull , Ġval Ġerror : ĠInt ? Ġ= Ġnull ) Ċ