package Ġcom . example . book store . ui . catalog Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . navigation . fragment . find Nav Controller Ċ import Ġandroidx . recyclerview . widget . Linear LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . example . book store . R Ċ import Ġcom . example . book store . data . Genre Ċ Ċ class ĠCatalog Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġrv Gen res : ĠRecyclerView ĊĠĠĠ Ġprivate Ġval Ġrv Gen res Adapter Ġ= ĠGen re Adapter ( get Genre ClickListener ()) ĊĊĠĠĠ Ġprivate Ġfun Ġget Genre ClickListener (): ĠGen re Adapter . Genre ClickListener Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġobject Ġ: ĠGen re Adapter . Genre ClickListener Ġ{ ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġoverride Ġfun ĠonClick ( current Genre : ĠGen re ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnavigate To Specific Genre Books Fragment ( current Genre . title ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġprivate Ġfun Ġnavigate To Specific Genre Books Fragment ( title : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġaction Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠCatalog Fragment Directions . action Catalog Fragment To Specific Genre Books Fragment ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgenre Ġ= Ġtitle ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfind Nav Controller (). navigate ( action ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( ĊĠĠĠĠĠĠĠ Ġinflater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĊĠĠĠĠĠĠĠ ĠsavedInstanceState : ĠBundle ? ĊĠĠĠ Ġ): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . fragment _ catalog , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on View Created ( view , ĠsavedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġinit Rv Gen res ( view ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġinit Rv Gen res ( view : ĠView ) Ġ{ ĊĠĠĠĠĠĠĠ Ġrv Gen res Ġ= Ġview . findViewById ( R . id . rv _ genres ) ĊĠĠĠĠĠĠĠ Ġrv Gen res . apply Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Manager Ġ= ĠLinearLayoutManager ( context ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġset Has Fixed Size ( true ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter Ġ= Ġrv Gen res Adapter ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Activity Created ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Activity Created ( savedInstanceState ) ĊĊĠĠĠĠĠĠĠ Ġval Ġgen res Ġ= Ġget Gen res () ĊĠĠĠĠĠĠĠ Ġrv Gen res Adapter . set Gen res ( genres ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Gen res (): ĠList < Genre > Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġaction Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ car _ crash , Ġtitle Ġ= Ġ" Action ") ĊĠĠĠĠĠĠĠ Ġval Ġbio graphy Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ gl asses , Ġtitle Ġ= Ġ" Bio graphy ") ĊĠĠĠĠĠĠĠ Ġval Ġcook book Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ apple , Ġtitle Ġ= Ġ" Cook book ") ĊĠĠĠĠĠĠĠ Ġval Ġcri me Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ knife , Ġtitle Ġ= Ġ" Cri me ") ĊĠĠĠĠĠĠĠ Ġval Ġd ram a Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ the ater _ masks , Ġtitle Ġ= Ġ" D ram a ") ĊĠĠĠĠĠĠĠ Ġval Ġf antasy Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ magic , Ġtitle Ġ= Ġ" F antasy ") ĊĠĠĠĠĠĠĠ Ġval Ġguide Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ map _ sign s , Ġtitle Ġ= Ġ" Guide ") ĊĠĠĠĠĠĠĠ Ġval Ġhealth Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ health , Ġtitle Ġ= Ġ" Health ") ĊĠĠĠĠĠĠĠ Ġval Ġhor ror Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ grave , Ġtitle Ġ= Ġ" Hor ror ") ĊĠĠĠĠĠĠĠ Ġval Ġpo etry Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ pen _ nib , Ġtitle Ġ= Ġ" Po etry ") ĊĠĠĠĠĠĠĠ Ġval Ġrel igion Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ pr ay ing _ hands , Ġtitle Ġ= Ġ" Rel igion ") ĊĠĠĠĠĠĠĠ Ġval Ġrom ance Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ heart , Ġtitle Ġ= Ġ" Rom ance ") ĊĠĠĠĠĠĠĠ Ġval Ġscience Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ gen ius , Ġtitle Ġ= Ġ" Science ") ĊĠĠĠĠĠĠĠ Ġval Ġscience Fi ction Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ ali en , Ġtitle Ġ= Ġ" Science Ġfi ction ") ĊĠĠĠĠĠĠĠ Ġval Ġthr iller Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ sk ull , Ġtitle Ġ= Ġ" Th r iller ") ĊĠĠĠĠĠĠĠ Ġval Ġtravel Ġ= ĠGen re ( image Resource Ġ= ĠR . drawable . ic _ air plane , Ġtitle Ġ= Ġ" Travel ") ĊĠĠĠĠĠĠĠ Ġreturn ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġaction , Ġbio graphy , Ġcook book , Ġcri me , Ġd ram a , Ġf antasy , Ġguide , Ġhealth , Ġhor ror , Ġpo etry , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġrel igion , Ġrom ance , Ġscience , Ġscience Fi ction , Ġthr iller , Ġtravel ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ }