package Ġcom . example . android . quiz game Ċ Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroidx . databinding . Data Binding Util Ċ import Ġandroidx . drawer layout . widget . Drawer Layout Ċ import Ġandroidx . navigation . find Nav Controller Ċ import Ġandroidx . navigation . ui . Navigation UI Ċ Ċ import Ġandroidx . navigation . Nav Controller Ċ import Ġandroidx . navigation . Nav Destination Ċ import Ġandroidx . navigation . Navigation Ċ import Ġandroidx . navigation . ui . AppBar Configuration Ċ import Ġcom . example . android . quiz game . databinding . Activity Main Binding ĊĊ Ċ class ĠMainActivity Ġ: ĠAppCompatActivity () Ġ{ ĊĠĠĠ Ġlateinit Ġvar Ġbinding : ĠActivity Main Binding ĊĠĠĠ Ġlateinit Ġvar Ġdrawer Layout : ĠDraw er Layout ĊĠĠĠ Ġlateinit Ġvar Ġapp Bar Configuration : AppBar Configuration ĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġbinding = ĠData Binding Util . set ContentView ( this , R . layout . activity _ main ) ĊĠĠĠĠĠĠĠ Ġdrawer Layout = binding . drawer layout ĊĊĠĠĠĠĠĠĠ Ġval Ġnav Controller = Navigation . find Nav Controller ( this , R . id . my Nav Host Fragment ) ĊĠĠĠĠĠĠĠ ĠNavigation UI . setup ActionBar With Nav Controller ( this , nav Controller , drawer Layout ) ĊĠĠĠĠĠĠĠ Ġapp Bar Configuration = ĠApp Bar Configuration ( nav Controller . graph , drawer Layout ) ĊĠĠĠĠĠĠĠ ĠNavigation UI . setup With Nav Controller ( binding . nav View , nav Controller ) ĊĠĠĠĠĠĠĠ Ġnav Controller . add On Destination Changed Listener Ġ{ Ġnc : ĠNav Controller , Ġnd : ĠNav Destination , Ġargs : ĠBundle ? Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ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 = Navigation . find Nav Controller ( this , R . id . my Nav Host Fragment ) ĊĠĠĠĠĠĠĠ Ġreturn ĠNavigation UI . navigate Up ( nav Controller , app Bar Configuration )|| super . on Support Navigate Up () ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġ} ĊĊ