diff --git a/app/src/main/java/com/example/hpos/presentation/MainActivity.kt b/app/src/main/java/com/example/hpos/presentation/MainActivity.kt
index 79ceba0..da9f22f 100644
--- a/app/src/main/java/com/example/hpos/presentation/MainActivity.kt
+++ b/app/src/main/java/com/example/hpos/presentation/MainActivity.kt
@@ -10,9 +10,12 @@ import android.os.Bundle
import android.util.Log
import android.view.Gravity
import android.view.Menu
+import android.view.MenuItem
import android.widget.Toast
+import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
+import androidx.core.view.GravityCompat
import androidx.core.view.get
import androidx.lifecycle.ViewModelProvider
import com.example.hpos.R
@@ -58,7 +61,8 @@ class MainActivity : AppCompatActivity()
)[MainViewModel::class.java]
setSupportActionBar(binding.myToolbar)
-// supportActionBar?.setDisplayHomeAsUpEnabled(true)
+
+ setupNavigationDrawer()
setupListeners()
@@ -68,6 +72,39 @@ class MainActivity : AppCompatActivity()
registerReceiver(mUsbReceiver, filter)
}
+ private fun setupNavigationDrawer() {
+ // Pass the ActionBarToggle action into the drawerListener
+ val actionBarToggle = ActionBarDrawerToggle(this, binding.drawerLayout, 0, 0)
+ binding.drawerLayout.addDrawerListener(actionBarToggle)
+
+ // For the Navigation drawer
+ supportActionBar?.setDisplayHomeAsUpEnabled(true)
+
+ // Call syncState() on the action bar so it'll automatically change to the back button when the drawer layout is open
+ actionBarToggle.syncState()
+
+ // Call setNavigationItemSelectedListener on the NavigationView to detect when items are clicked
+ binding.navView.setNavigationItemSelectedListener { menuItem: MenuItem ->
+ when (menuItem.itemId) {
+ R.id.about_us -> {
+ Toast.makeText(this, "Test clicked", Toast.LENGTH_SHORT).show()
+ true
+ }
+ R.id.download_report -> {
+ Toast.makeText(this, "Download clicked", Toast.LENGTH_SHORT).show()
+ true
+ }
+ R.id.settings -> {
+ Toast.makeText(this, "Settings clicked", Toast.LENGTH_SHORT).show()
+ true
+ }
+ else -> {
+ false
+ }
+ }
+ }
+ }
+
private fun checkAndUpdateUsbConnection() {
val availableDrivers = UsbSerialProber.getDefaultProber().findAllDrivers(getSystemService(Context.USB_SERVICE) as UsbManager)
if (availableDrivers.isNotEmpty() && availableDrivers[0].device.productId == Constants.DEVICE_PRODUCT_ID && availableDrivers[0].device.vendorId == Constants.DEVICE_VENDOR_ID){
@@ -112,4 +149,19 @@ class MainActivity : AppCompatActivity()
return true
}
+ // override the onSupportNavigateUp() function to launch the Drawer when the hamburger icon is clicked
+ override fun onSupportNavigateUp(): Boolean {
+ binding.drawerLayout.openDrawer(binding.navView)
+ return true
+ }
+
+ // override the onBackPressed() function to close the Drawer when the back button is clicked
+ override fun onBackPressed() {
+ if (binding.drawerLayout.isDrawerOpen(GravityCompat.START)) {
+ binding.drawerLayout.closeDrawer(GravityCompat.START)
+ } else {
+ super.onBackPressed()
+ }
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_baseline_info_24.xml b/app/src/main/res/drawable/ic_baseline_info_24.xml
new file mode 100644
index 0000000..1524c2b
--- /dev/null
+++ b/app/src/main/res/drawable/ic_baseline_info_24.xml
@@ -0,0 +1,5 @@
+