f038dbe0ee
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
219 lines
9.3 KiB
Kotlin
219 lines
9.3 KiB
Kotlin
package com.planify.mobile.ui
|
|
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxHeight
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.ui.text.style.TextAlign
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
import androidx.compose.foundation.lazy.items
|
|
import androidx.compose.material.icons.Icons
|
|
import androidx.compose.material.icons.filled.FolderOpen
|
|
import androidx.compose.material.icons.outlined.Add
|
|
import androidx.compose.material.icons.outlined.CalendarMonth
|
|
import androidx.compose.material.icons.outlined.FilterList
|
|
import androidx.compose.material.icons.outlined.Inbox
|
|
import androidx.compose.material.icons.outlined.Menu
|
|
import androidx.compose.material.icons.outlined.Search
|
|
import androidx.compose.material.icons.outlined.Settings
|
|
import androidx.compose.material.icons.outlined.Today
|
|
import androidx.compose.foundation.shape.CircleShape
|
|
import androidx.compose.material3.DrawerValue
|
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
import androidx.compose.material3.FloatingActionButton
|
|
import androidx.compose.material3.HorizontalDivider
|
|
import androidx.compose.material3.Icon
|
|
import androidx.compose.material3.IconButton
|
|
import androidx.compose.material3.MaterialTheme
|
|
import androidx.compose.material3.ModalDrawerSheet
|
|
import androidx.compose.material3.ModalNavigationDrawer
|
|
import androidx.compose.material3.NavigationDrawerItem
|
|
import androidx.compose.material3.Scaffold
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.TopAppBar
|
|
import androidx.compose.material3.rememberDrawerState
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.collectAsState
|
|
import androidx.compose.runtime.getValue
|
|
import androidx.compose.runtime.mutableStateOf
|
|
import androidx.compose.runtime.remember
|
|
import androidx.compose.runtime.rememberCoroutineScope
|
|
import androidx.compose.runtime.setValue
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.hilt.navigation.compose.hiltViewModel
|
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
|
import androidx.navigation.compose.rememberNavController
|
|
import com.planify.mobile.ui.navigation.DrawerViewModel
|
|
import com.planify.mobile.ui.navigation.PlanifyNavHost
|
|
import com.planify.mobile.ui.navigation.Route
|
|
import com.planify.mobile.ui.task.TaskEditSheet
|
|
import kotlinx.coroutines.launch
|
|
|
|
@OptIn(ExperimentalMaterial3Api::class)
|
|
@Composable
|
|
fun MainScreen(viewModel: DrawerViewModel = hiltViewModel()) {
|
|
val navController = rememberNavController()
|
|
val drawerState = rememberDrawerState(DrawerValue.Closed)
|
|
val scope = rememberCoroutineScope()
|
|
val projects by viewModel.projects.collectAsState()
|
|
val navBackStack by navController.currentBackStackEntryAsState()
|
|
val currentRoute = navBackStack?.destination?.route
|
|
|
|
var showCreateTask by remember { mutableStateOf(false) }
|
|
val inboxProjectId = projects.find { it.isInbox }?.id ?: ""
|
|
val createProjectId = if (currentRoute?.startsWith("project/") == true)
|
|
currentRoute.removePrefix("project/")
|
|
else
|
|
inboxProjectId
|
|
|
|
val drawerTitles = mapOf(
|
|
Route.Inbox.path to "Inbox",
|
|
Route.Today.path to "Aujourd'hui",
|
|
Route.Scheduled.path to "Planifié",
|
|
Route.Search.path to "Recherche",
|
|
Route.Filter.path to "Filtres",
|
|
Route.Settings.path to "Paramètres",
|
|
)
|
|
val title = drawerTitles[currentRoute]
|
|
?: projects.find { "project/${it.id}" == currentRoute }?.name
|
|
?: "Planify"
|
|
|
|
ModalNavigationDrawer(
|
|
drawerState = drawerState,
|
|
drawerContent = {
|
|
ModalDrawerSheet {
|
|
Text(
|
|
text = "Planify",
|
|
fontWeight = FontWeight.Bold,
|
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 20.dp),
|
|
)
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Outlined.Inbox, null) },
|
|
label = { Text("Inbox") },
|
|
selected = currentRoute == Route.Inbox.path,
|
|
onClick = {
|
|
navController.navigate(Route.Inbox.path)
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Outlined.Today, null) },
|
|
label = { Text("Aujourd'hui") },
|
|
selected = currentRoute == Route.Today.path,
|
|
onClick = {
|
|
navController.navigate(Route.Today.path)
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Outlined.CalendarMonth, null) },
|
|
label = { Text("Planifié") },
|
|
selected = currentRoute == Route.Scheduled.path,
|
|
onClick = {
|
|
navController.navigate(Route.Scheduled.path)
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Outlined.Search, null) },
|
|
label = { Text("Recherche") },
|
|
selected = currentRoute == Route.Search.path,
|
|
onClick = {
|
|
navController.navigate(Route.Search.path)
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Outlined.FilterList, null) },
|
|
label = { Text("Filtres") },
|
|
selected = currentRoute == Route.Filter.path,
|
|
onClick = {
|
|
navController.navigate(Route.Filter.path)
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
HorizontalDivider(Modifier.padding(vertical = 8.dp))
|
|
Text(
|
|
text = "Projets",
|
|
fontWeight = FontWeight.SemiBold,
|
|
modifier = Modifier.padding(horizontal = 16.dp, vertical = 4.dp),
|
|
)
|
|
LazyColumn {
|
|
items(projects) { project ->
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Default.FolderOpen, null) },
|
|
label = { Text(project.name) },
|
|
selected = currentRoute == "project/${project.id}",
|
|
onClick = {
|
|
navController.navigate(Route.Project().buildRoute(project.id))
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
}
|
|
}
|
|
HorizontalDivider(Modifier.padding(vertical = 8.dp))
|
|
NavigationDrawerItem(
|
|
icon = { Icon(Icons.Outlined.Settings, null) },
|
|
label = { Text("Paramètres") },
|
|
selected = currentRoute == Route.Settings.path,
|
|
onClick = {
|
|
navController.navigate(Route.Settings.path)
|
|
scope.launch { drawerState.close() }
|
|
},
|
|
)
|
|
Spacer(Modifier.height(8.dp))
|
|
Text(
|
|
text = "v${com.planify.mobile.BuildConfig.VERSION_NAME}",
|
|
style = MaterialTheme.typography.labelSmall,
|
|
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
|
textAlign = TextAlign.Center,
|
|
modifier = Modifier
|
|
.fillMaxWidth()
|
|
.padding(bottom = 16.dp),
|
|
)
|
|
}
|
|
}
|
|
) {
|
|
Scaffold(
|
|
topBar = {
|
|
TopAppBar(
|
|
title = { Text(title) },
|
|
navigationIcon = {
|
|
IconButton(onClick = { scope.launch { drawerState.open() } }) {
|
|
Icon(Icons.Outlined.Menu, contentDescription = "Menu")
|
|
}
|
|
},
|
|
)
|
|
},
|
|
floatingActionButton = {
|
|
if (currentRoute != Route.Settings.path) {
|
|
FloatingActionButton(
|
|
onClick = { showCreateTask = true },
|
|
containerColor = MaterialTheme.colorScheme.primary,
|
|
shape = CircleShape,
|
|
) {
|
|
Icon(Icons.Outlined.Add, contentDescription = "Nouvelle tâche", tint = MaterialTheme.colorScheme.onPrimary)
|
|
}
|
|
}
|
|
},
|
|
) { padding ->
|
|
PlanifyNavHost(
|
|
navController = navController,
|
|
modifier = Modifier.padding(padding),
|
|
)
|
|
|
|
if (showCreateTask) {
|
|
TaskEditSheet(
|
|
projectId = createProjectId,
|
|
onDismiss = { showCreateTask = false },
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|