¶ 📱 MainActivity Design Document
File: MainActivity.kt
Module: core
Purpose: Acts as the central activity and navigational hub for the app. Provides a hamburger-controlled drawer with links to key submodules.
| Component |
Type |
ID |
Purpose |
| DrawerLayout |
View |
R.id.drawer_layout |
Contains the app’s navigation drawer UI |
| NavigationView |
View |
R.id.nav_view |
Displays navigation menu items |
| ImageButton |
View |
R.id.hamburgerButton |
Triggers drawer open/close |
| OnNavigationItemSelectedListener |
Interface |
– |
Handles selection of menu items in the drawer |
- Navigation drawer opens/closes via the hamburger button.
- Uses
GravityCompat.END to align the drawer on the right side.
- Drawer items handled via
onNavigationItemSelected().
- Routes users to:
ProfileActivity (Profile screen)
SettingsActivity (Settings screen)
LogoutActivity (Logout flow)
¶ 3. Intent Handling
- Accepts optional extras (
user_id) from launching Intent.
- Logs
user_id to Logcat if passed (Log.d()).
| Method |
Purpose |
onCreate() |
Initializes UI, listeners, and logs intent extras. |
toggleDrawer() |
Toggles drawer open/close using GravityCompat.END. |
onNavigationItemSelected() |
Responds to nav item selection and launches corresponding activity. |
routeTo(destination: Class<*>) |
Launches a new activity via an explicit intent. |
| Test Case |
Description |
testToggleDrawerOpensAndCloses() |
Verify drawer toggles correctly when button is tapped. |
testUserIdLogging() |
Pass user_id in intent and confirm correct log output. |
testRouteToProfile() |
Tap nav_profile → verify ProfileActivity launches. |
testRouteToSettings() |
Tap nav_settings → verify SettingsActivity launches. |
testRouteToLogout() |
Tap nav_logout → verify LogoutActivity launches. |
testInvalidNavItem() |
Select unknown nav item → ensure false is returned. |
| Scenario |
Description |
| Drawer Toggle Button |
Tapping hamburger opens/closes drawer. |
| Drawer on Right Side |
Drawer opens from the right (using GravityCompat.END). |
| Navigation Flow |
Selecting drawer items navigates to correct screens. |
| Back Stack Behavior |
New activities are launched on top of MainActivity. |
- Support for role-based drawer items (e.g., admin-specific routes).
- Handle drawer state persistence on rotation or backgrounding.
- Add Espresso UI tests for gesture-based drawer control.
- Support deep linking from notification or external intent.