package Ġpl . light mobile . design 0 1 transitions Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . lifecycle . ViewModel Providers Ċ import Ġandroidx . transition . Transition Manager Ċ import Ġkotlinx . android . synt hetic . main . fragment _ simple _ state _ transitions . errorMessage Ċ import Ġkotlinx . android . synt hetic . main . fragment _ simple _ state _ transitions . loader Ċ import Ġkotlinx . android . synt hetic . main . fragment _ simple _ state _ transitions . root Ċ import Ġpl . light mobile . design 0 1 transitions . Simple State ViewModel . Simple State . Error Ċ import Ġpl . light mobile . design 0 1 transitions . Simple State ViewModel . Simple State . Loading Ċ Ċ class ĠSimple State Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . fragment _ simple _ state _ transitions , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġval Ġvm Ġ= ĠViewModel Providers . of ( this )[ Simple State ViewModel :: class . java ] ĊĊĠĠĠĠĠĠĠ Ġvm . view State . observe NotNull ( this ) Ġ{ Ġstate Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhen ( state ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoading Ġ-> Ġshow Loading State () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠError Ġ-> Ġshow Error State () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġvm . load Data () ĊĠĠĠĠĠĠĠ ĠerrorMessage . setOnClickListener Ġ{ Ġvm . load Data () Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Error State () Ġ{ ĊĠĠĠĠĠĠĠ ĠTransition Manager . begin Delayed Transition ( root ) ĊĠĠĠĠĠĠĠ Ġloader . visibility Ġ= ĠView . GONE ĊĠĠĠĠĠĠĠ ĠerrorMessage . visibility Ġ= ĠView . VISIBLE ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġshow Loading State () Ġ{ ĊĠĠĠĠĠĠĠ ĠTransition Manager . begin Delayed Transition ( root ) ĊĠĠĠĠĠĠĠ Ġloader . visibility Ġ= ĠView . VISIBLE ĊĠĠĠĠĠĠĠ ĠerrorMessage . visibility Ġ= ĠView . GONE ĊĠĠĠ Ġ} Ċ } Ċ