/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠMar c ĠD onal d Ċ Ġ* Ċ Ġ* ĠLicensed Ġunder Ġthe ĠApache ĠLicense , ĠVersion Ġ 2 . 0 Ġ( the Ġ" License "); Ċ Ġ* Ġyou Ġmay Ġnot Ġuse Ġthis Ġfile Ġexcept Ġin Ġcompliance Ġwith Ġthe ĠLicense . Ċ Ġ* ĠYou Ġmay Ġobtain Ġa Ġcopy Ġof Ġthe ĠLicense Ġat Ċ Ġ* Ċ Ġ* Ġhttp :// www . apache . org / licenses / LICENSE - 2 . 0 Ċ Ġ* Ċ Ġ* ĠUnless Ġrequired Ġby Ġapplicable Ġlaw Ġor Ġagreed Ġto Ġin Ġwriting , Ġsoftware Ċ Ġ* Ġdistributed Ġunder Ġthe ĠLicense Ġis Ġdistributed Ġon Ġan Ġ" AS ĠIS " ĠBASIS , Ċ Ġ* ĠWITHOUT ĠWARRANTIES ĠOR ĠCONDITIONS ĠOF ĠANY ĠKIND , Ġeither Ġexpress Ġor Ġimplied . Ċ Ġ* ĠSee Ġthe ĠLicense Ġfor Ġthe Ġspecific Ġlanguage Ġgoverning Ġpermissions Ġand Ċ Ġ* Ġlimitations Ġunder Ġthe ĠLicense . Ċ Ġ*/ Ċ package Ġcom . mar cd onal d . hib i . screens . books . main books Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . fragment . app . FragmentManager Ċ import Ġandroidx . navigation . Navigation Ċ import Ġandroidx . recyclerview . widget . RecyclerView Ċ import Ġcom . mar cd onal d . hib i . R Ċ import Ġcom . mar cd onal d . hib i . internal . BOOK _ ID _ KEY Ċ import Ġcom . mar cd onal d . hib i . screens . add book dialog . Add Book Dialog Ċ import Ġcom . mar cd onal d . hib i . screens . main . Main Screen Fragment Directions Ċ Ċ class ĠBooks Fragment RecyclerView Holder ( item View : ĠView , Ġprivate Ġval Ġfragment Manager : ĠFragment Manager ) Ġ: Ċĉ ĉ RecyclerView . ViewHolder ( item View ) Ġ{ ĊĊ ĉ private Ġvar Ġbook Name Display : ĠTextView Ġ= ĠitemView . findViewById ( R . id . book _ item _ name ) Ċ ĉ private Ġvar Ġbook Count Display : ĠTextView Ġ= ĠitemView . findViewById ( R . id . book _ item _ count ) ĊĊ ĉ private Ġvar Ġdisplayed Item : ĠBook Display Item ? Ġ= Ġnull ĊĊ ĉ private Ġval Ġclick Listener Ġ= ĠView . OnClickListener Ġ{ Ċĉ ĉ if ( display ed Item Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ val Ġbook ID Ġ= Ġdisplayed Item !!. book Id Ċĉĉ ĉ val Ġview Entry Action Ġ= ĠMain Screen Fragment Directions . view Book Entries Action ( book ID ) Ċĉĉ ĉ Navigation . find Nav Controller ( item View ). navigate ( view Entry Action ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġval Ġlong ClickListener Ġ= ĠView . On Long ClickListener Ġ{ Ċĉ ĉ init Edit Or Delete Dialog () Ċĉ ĉ true Ċ ĉ } ĊĊ ĉ private Ġfun Ġinit Edit Or Delete Dialog () Ġ{ Ċĉ ĉ val Ġedit Book Dialog Ġ= ĠAdd Book Dialog () Ċĉ ĉ if ( display ed Item Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ val Ġarguments Ġ= ĠBundle () Ċĉĉ ĉ arguments . put Int ( BOOK _ ID _ KEY , Ġdisplayed Item !!. book Id ) Ċĉĉ ĉ edit Book Dialog . arguments Ġ= Ġarguments Ċĉ ĉ } Ċĉ ĉ edit Book Dialog . show ( fragment Manager , Ġ" Edit Ġor ĠDelete ĠBook ĠDialog ") Ċ ĉ } ĊĊ ĉ init Ġ{ Ċĉ ĉ item View . setOnClickListener ( click Listener ) Ċĉ ĉ item View . setOn Long ClickListener ( long ClickListener ) Ċ ĉ } ĊĊ ĉ fun Ġdisplay ( item : ĠBook Display Item ) Ġ{ Ċĉ ĉ display ed Item Ġ= Ġitem Ċĉ ĉ book Name Display . text Ġ= Ġitem . book Name Ċĉ ĉ book Count Display . text Ġ= ĠitemView . resources . getString ( R . string . book _ use _ count _ wc , Ġitem . use Count . toString ()) Ċ ĉ } Ċ }