What is MainActivity?
On Android, an Activity is the main entry point for interacting with an app. It hosts everything the user sees and handles key logic like launching screens or managing user sessions.
In Cortest, there's a single Kotlin file called MainActivity.kt. It’s responsible for starting the app and managing how users move between different screens.
Thanks to Jetpack Compose, all screens in the app are built using composable functions. These are reusable blocks of UI, defined in the ui/ folder, and they are connected through a central system called the Navigation Graph.
1 - How navigation works
Inside MainActivity.kt, the app sets up a NavController and a NavHost, which together manage the flow between screens — whether you're logging in, launching a test, or changing your settings.
Everything is declared inside a few key components:
2 - MainActivity
This class is the actual entry point of the app. Here's what it does:
- Handles authentication using Firebase
- Loads user preferences and patient data
- Sets the first screen to show (depending on the context)
- Launches the Compose UI using
setContent { ... } - Handles external triggers, like widgets, by reacting to incoming intents
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
requestPermissionsIfNecessary()
setContent {
// Firebase auth, loading patients, checking start screen...
EpilepsyTestApp(...) // Launches the UI
}
}
If the app is opened from a widget (like a shortcut), it updates its intent and restarts itself with the right screen:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
setIntent(intent)
val startScreen = intent?.getStringExtra("startScreen")
if (!startScreen.isNullOrEmpty()) {
recreate()
}
}
3 - EpilepsyTestApp
This is a composable function that wraps the entire app UI in its theme and initializes the navigation graph.
It checks whether data is still loading and displays either a loading screen or the full app with navigation.
@Composable
fun EpilepsyTestApp(...) {
val navController = rememberNavController()
if (isLoading) {
LoadingScreen()
} else {
AppTheme {
NavigationGraph(
navController = navController,
...
)
}
}
}
4 - NavigationGraph
This composable defines all the app's screens and how to move between them. It uses Jetpack Compose’s NavHost and composable blocks to map out each screen.
@Composable
fun NavigationGraph(...) {
val recordedVideos = remember { mutableStateListOf<String>() }
val cameraViewModel: CameraViewModel = viewModel()
LaunchedEffect(widgetStartScreen) {
widgetStartScreen?.let { target ->
navController.navigate(target) {
popUpTo(navController.graph.startDestinationId) {
inclusive = true
}
launchSingleTop = true
}
}
}
NavHost(
navController = navController,
startDestination = startDestination
) {
composable("home") {
if (isAuthenticated) {
HomePage(...)
} else {
navController.navigate("login") {
popUpTo("home") { inclusive = true }
}
}
}
composable("login") {
LoginScreen(...)
}
// Other screens go here...
}
}
UI Code Structure
All UI screens are defined as composables in files under:
app/src/main/java/com/example/epilepsytestapp/ui
Each file corresponds to a screen or feature of the app:
| File | Description |
|---|---|
HomeScreen.kt | Main dashboard and navigation bar |
DemoScreen.kt | Interactive demo of the app |
FilesPage.kt | List of saved PDFs and videos |
SettingsPage.kt | App settings |
LoginScreen.kt | Login interface |
TypeConfigScreen.kt | Test type selection |
ConfigScreen.kt | Test configuration |
RecapConfigScreen.kt | Test summary |
ConfigHistoryScreen.kt | History of test setups |
SignupScreen.kt | Sign-up (email & password) |
InfoPerso.kt | Sign-up (personal info) |
ProfilePage.kt | User profile |
TestScreen.kt | Active test screen |
ConfirmationScreen.kt | Test confirmation screen |
TestEnregistre.kt | Test saving screen |
QuestionnaireScreen.kt | Post-test survey |