Ċ package Ġcom . example . g ues st he ch ord Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . databinding . Data Binding Util Ċ import Ġandroidx . drawer layout . widget . Drawer Layout Ċ import Ġandroidx . navigation . Nav Controller Ċ import Ġandroidx . navigation . Nav Destination Ċ import Ġandroidx . navigation . find Nav Controller Ċ import Ġandroidx . navigation . ui . Navigation UI Ċ import Ġcom . example . g ues st he ch ord . navigation . R Ċ import Ġcom . example . g ues st he ch ord . navigation . databinding . Activity Main Binding Ċ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĊĠĠĠ Ġlateinit Ġvar Ġdrawer Layout : ĠDraw er Layout ĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġ@ Suppress (" UNUSED _ VARIABLE ") ĊĠĠĠĠĠĠĠ Ġval Ġbinding Ġ= ĠData Binding Util . set ContentView < Activity Main Binding >( this , ĠR . layout . activity _ main ) ĊĠĠĠĠĠĠĠ Ġdrawer Layout Ġ= Ġbinding . drawer Layout ĊĊĠĠĠĠĠĠĠ Ġval Ġnav Controller Ġ= Ġthis . find Nav Controller ( R . id . nav Host Fragment ) ĊĠĠĠĠĠĠĠ ĠNavigation UI . setup ActionBar With Nav Controller ( this , nav Controller , Ġdrawer Layout ) ĊĠĠĠĠĠĠĠ ĠNavigation UI . setup With Nav Controller ( binding . nav View , Ġnav Controller ) ĊĊĠĠĠĠĠĠĠ Ġnav Controller . add On Destination Changed Listener { nc , Ġnd , Ġargs Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( nd . id Ġ== Ġnc . graph . start Destination ){ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdrawer Layout . set Drawer Lock Mode ( Drawer Layout . LOCK _ MODE _ UNLOCK ED ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} else { ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdrawer Layout . set Drawer Lock Mode ( Drawer Layout . LOCK _ MODE _ LOCK ED _ CLOSED ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Support Navigate Up (): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnav Controller Ġ= Ġthis . find Nav Controller ( R . id . nav Host Fragment ) ĊĠĠĠĠĠĠĠ Ġreturn ĠNavigation UI . navigate Up ( nav Controller , Ġdrawer Layout ) ĊĠĠĠĠĠĠĠ Ġ// return Ġnav Controller . navigate Up () ĊĠĠĠ Ġ} Ċ Ċ } Ċ