package Ġcom . cr ave food . android app model . orders . listing Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view .* Ċ import Ġandroidx . appcompat . widget . Search View Ċ import Ġandroidx . core . os . bundle Of Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . navigation . find Nav Controller Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġcom . cr ave food . android app model . R Ċ import Ġcom . cr ave food . android app model . observe Ċ import Ġcom . cr ave food . data . Order Model Ċ import Ġcom . example . common . De bounce Query Text Listener Ċ import Ġkotlinx . android . synt hetic . main . fragment _ orders _ listing .* Ċ import Ġorg . k oin . android x . view model . ext . android . viewModel Ċ Ċ class ĠOrders Listing Ġ: ĠFragment () Ġ{ ĊĊ ĉ private Ġval ĠviewModel Ġby ĠviewModel < Orders Listing ViewModel >() ĊĊ ĉ override Ġfun ĠonCreate View ( Ċĉ ĉ in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, Ċĉ ĉ savedInstanceState : ĠBundle ? Ċ ĉ ): ĠView ? Ġ{ Ċĉ ĉ return Ġinflater . inflate ( R . layout . fragment _ orders _ listing , Ġcontainer , Ġfalse ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . on View Created ( view , ĠsavedInstanceState ) ĊĊĉ ĉ set Has Options Menu ( true ) ĊĊĉ ĉ configure Observable s () Ċĉ ĉ configure Components () Ċĉ ĉ getData () Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate Options Menu ( menu : ĠMenu ?, Ġinflater : ĠMenu Inflater ?) Ġ{ Ċĉ ĉ in flater ?. inflate ( R . menu . menu _ search , Ġmenu ) Ċĉ ĉ super . onCreate Options Menu ( menu , Ġinflater ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Prepare Options Menu ( menu : ĠMenu ?) Ġ{ Ċĉ ĉ menu ?. let Ġ{ Ċĉĉ ĉ val Ġsearch MenuItem : ĠMenuItem ? Ġ= Ġmenu . find Item ( R . id . action _ search _ view ) Ċĉĉ ĉ val Ġsearch View Ġ= Ġ( search MenuItem ?. action View Ġas ĠSearch View ) Ċĉĉ ĉ search View . query Hint Ġ= ĠgetString ( R . string . search _ orders ) Ċĉĉ ĉ search View . maxWidth Ġ= ĠInteger . MAX _ VALUE Ċĉĉ ĉ search View . setOn Query Text Listener ( object Ġ: ĠDe bounce Query Text Listener ( context ) Ġ{ ĊĊĉĉĉ ĉ override Ġfun Ġdo On TextChanged ( text : ĠString ) Ġ{ Ċĉĉĉĉ ĉ if Ġ( text . isEmpty () Ġ|| Ġtext . length Ġ> Ġ 2 ) Ċĉĉĉĉĉ ĉ viewModel . get Orders ( text ) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ override Ġfun Ġon Query Text Submit ( query : ĠString ): ĠBoolean Ġ{ Ċĉĉĉĉ ĉ do On TextChanged ( query ) Ċĉĉĉĉ ĉ return Ġfalse Ċĉĉĉ ĉ } Ċĉĉ ĉ }) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġconfigure Observable s () Ġ{ Ċĉ ĉ observe ( viewModel . model . re cyclerView Orders Listing Ob , Ġ:: handle Orders Listing ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġconfigure Components () Ġ{ Ċĉ ĉ re cyclerView Orders Listing . apply Ġ{ Ċĉĉ ĉ layout Manager Ġ= ĠLinearLayoutManager ( context ) Ċĉĉ ĉ adapter Ġ= ĠOrders Listing Adapter Ġ{ Ġorder Ġ-> Ċĉĉĉ ĉ val Ġbundle Ġ= Ċĉĉĉĉ ĉ bundle Of ( Ċĉĉĉĉĉ ĉ getString ( R . string . argument _ order _ detail _ orderId ) Ġto Ġorder . id Ċĉĉĉĉ ĉ ) ĊĊĉĉĉ ĉ find Nav Controller (). navigate ( Ċĉĉĉĉ ĉ R . id . action _ fragment Orders _ to _ fragment Order Detail , Ċĉĉĉĉ ĉ bundle Ċĉĉĉ ĉ ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun ĠgetData () Ġ{ Ċĉ ĉ viewModel . get Orders () Ċ ĉ } ĊĊ ĉ private Ġfun Ġhandle Orders Listing ( list : ĠList < Order Model > ?) Ġ{ Ċĉ ĉ ( re cyclerView Orders Listing . adapter Ġas ĠOrders Listing Adapter ). update ( list Ġ?: Ġempty List ()) Ċ ĉ } Ċ Ċ } Ċ