package Ġl uc asc amp os . labs . movies . features . movies Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroid . widget . View Flip per Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġandroidx . recyclerview . widget . Grid LayoutManager Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġl uc asc amp os . labs . core . decorators . Divider Grid Item Decoration Ċ import Ġl uc asc amp os . labs . core . extensions . observe Ċ import Ġl uc asc amp os . labs . core . view model . factory ViewModel Ċ import Ġl uc asc amp os . labs . movies . Movie Api Ċ import Ġl uc asc amp os . labs . movies . Movie ViewModel Ċ import Ġl uc asc amp os . labs . movies . R Ċ import Ġl uc asc amp os . labs . movies . models . Movie Ċ Ċ class ĠMov ies Fragment Ġ: ĠFragment () Ġ{ ĊĊĠĠĠ Ġprivate Ġval ĠviewModel Ġby Ġfactory ViewModel ( Movie ViewModel :: class , ĠMovie Api :: class ) ĊĊĠĠĠ Ġprivate Ġval Ġview Flip per Ġby Ġlazy Ġ{ Ġview ?. findViewById < View Flip per >( R . id . view _ flip per ) Ġ} ĊĠĠĠ Ġprivate Ġval Ġre cyclerView Ġby Ġlazy Ġ{ Ġview ?. findViewById < RecyclerView >( R . id . recycler _ view ) Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġinflater . inflate ( R . layout . fragment _ movies , Ġcontainer , Ġfalse ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon View Created ( view : ĠView , ĠsavedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ ĠsetUp ViewModel () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠsetUp ViewModel () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġlifecycle Owner Ġ= Ġthis ĊĊĠĠĠĠĠĠĠ ĠviewModel . run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmovies . observe ( lifecycle Owner ) Ġ{ ĠsetUp RecyclerView ( it . results , Ġmargin Ġ= Ġ 1 6 ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġview State . observe ( lifecycle Owner ) Ġ{ Ġview Flip per ?. display ed Child Ġ= Ġit . index Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġfetch Movies () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun ĠsetUp RecyclerView ( results : ĠList < Movie >, Ġmargin Ġ: ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġmargin Between Items Ġ= Ġ( resources . display Metrics . density Ġ* Ġmargin ). toInt () ĊĊĠĠĠĠĠĠĠ Ġre cyclerView ?. run Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġlayout Manager Ġ= ĠGrid LayoutManager ( context , Ġ 2 ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadapter Ġ= ĠMovie Adapter (). apply Ġ{ Ġmovies Ġ= Ġresults Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġadd Item Decoration ( Divider Grid Item Decoration ( margin Between Items )) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ