package Ġcom . github . a stra ube . state flow binding . ui . names Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . widget . Toast Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġcom . github . a stra ube . state flow binding . R Ċ import Ġcom . github . a stra ube . state flow binding . data . repository . Main Repository Ċ import Ġcom . github . a stra ube . state flow binding . common . extensions . view Binding Ċ import Ġcom . github . a stra ube . state flow binding . data . source . is Failure Ċ import Ġcom . github . a stra ube . state flow binding . data . source . status Message Ċ import Ġcom . github . a stra ube . state flow binding . databinding . Fragment Names Binding Ċ Ċ /** Ċ Ġ* ĠA Ġsimple Ġ[ Fragment ] Ġsubclass Ġas Ġthe Ġdefault Ġdestination Ġin Ġthe Ġnavigation . Ċ Ġ*/ Ċ class ĠNames Fragment Ġ: ĠFragment ( R . layout . fragment _ names ) Ġ{ ĊĊĠĠĠ Ġprivate Ġval Ġbinding Ġby Ġview Binding ( Fragment Names Binding :: bind ) ĊĊĠĠĠ Ġprivate Ġval ĠviewModel : ĠNames ViewModel Ġ= ĠNames ViewModel ( Main Repository ()) ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġbind To ViewModel () ĊĊĠĠĠĠĠĠĠ Ġinit UI ( savedInstanceState ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġbind To ViewModel () Ġ{ ĊĠĠĠĠĠĠĠ Ġbinding . lifecycle Owner Ġ= Ġthis ĊĠĠĠĠĠĠĠ Ġbinding . viewModel Ġ= ĠviewModel ĊĠĠĠĠĠĠĠ Ġbinding . execute Pending Bindings () ĊĊĠĠĠĠĠĠĠ Ġlifecycle . add Observer ( viewModel ) ĊĊĠĠĠĠĠĠĠ ĠviewModel . ui State . observe ( view Lifecycle Owner ) Ġ{ Ġresult Source Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d (" @@ @ ", Ġ" ui State . observe : Ġ$ result Source ") ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( result Source . is Failure ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠToast . makeText ( this @ Names Fragment . require Context (), Ġresult Source . status Message , ĠToast . LENGTH _ LONG ). show () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit UI ( savedInstanceState : ĠBundle ?) Ġ{ ĊĊĠĠĠ Ġ} Ċ }