Compare commits
2 Commits
e696ceb399
...
2466250851
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2466250851 | ||
|
|
694daa1cf3 |
@@ -9,5 +9,6 @@ data class AnalyticsState(
|
|||||||
val timelineDates: List<Date> = emptyList(),
|
val timelineDates: List<Date> = emptyList(),
|
||||||
val plannedProgressPoints: List<Float> = emptyList(),
|
val plannedProgressPoints: List<Float> = emptyList(),
|
||||||
val realizedProgressPoints: List<Float> = emptyList(),
|
val realizedProgressPoints: List<Float> = emptyList(),
|
||||||
val overdueByTag: List<Pair<String, Int>> = emptyList()
|
val overdueByTag: List<Pair<String, Int>> = emptyList(),
|
||||||
|
val overdueBySector: List<Pair<String, Int>> = emptyList()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,12 +1,22 @@
|
|||||||
package com.example.ui.screens
|
package com.example.ui.screens
|
||||||
|
|
||||||
|
import android.widget.Toast
|
||||||
|
import androidx.activity.compose.rememberLauncherForActivityResult
|
||||||
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
|
import androidx.compose.foundation.BorderStroke
|
||||||
import androidx.compose.foundation.Canvas
|
import androidx.compose.foundation.Canvas
|
||||||
import androidx.compose.foundation.background
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.pager.HorizontalPager
|
||||||
|
import androidx.compose.foundation.pager.rememberPagerState
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
import androidx.compose.material.icons.automirrored.filled.ArrowBack
|
||||||
import androidx.compose.material3.*
|
import androidx.compose.material3.*
|
||||||
@@ -21,6 +31,7 @@ import androidx.compose.ui.graphics.Path
|
|||||||
import androidx.compose.ui.graphics.PathEffect
|
import androidx.compose.ui.graphics.PathEffect
|
||||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
import androidx.compose.ui.graphics.nativeCanvas
|
import androidx.compose.ui.graphics.nativeCanvas
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
@@ -35,11 +46,21 @@ import com.example.ui.theme.BrandBlack
|
|||||||
import com.example.ui.theme.BrandGreen
|
import com.example.ui.theme.BrandGreen
|
||||||
import com.example.ui.theme.LightGrey
|
import com.example.ui.theme.LightGrey
|
||||||
import com.example.ui.viewmodel.MaintenanceViewModel
|
import com.example.ui.viewmodel.MaintenanceViewModel
|
||||||
|
import com.google.android.gms.auth.api.signin.GoogleSignIn
|
||||||
|
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
|
||||||
|
import com.google.android.gms.common.api.ApiException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
enum class OverdueGroupType { TAG, SETOR }
|
||||||
|
|
||||||
|
data class SelectedOverdueGroup(
|
||||||
|
val type: OverdueGroupType,
|
||||||
|
val label: String
|
||||||
|
)
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
@Composable
|
@Composable
|
||||||
fun AnalyticsScreen(
|
fun AnalyticsScreen(
|
||||||
@@ -49,6 +70,39 @@ fun AnalyticsScreen(
|
|||||||
) {
|
) {
|
||||||
val activities by viewModel.allActivitiesState.collectAsStateWithLifecycle()
|
val activities by viewModel.allActivitiesState.collectAsStateWithLifecycle()
|
||||||
val analyticsState by viewModel.analyticsState.collectAsStateWithLifecycle()
|
val analyticsState by viewModel.analyticsState.collectAsStateWithLifecycle()
|
||||||
|
val currentUser by viewModel.currentUser.collectAsStateWithLifecycle()
|
||||||
|
val userAccessLevel by viewModel.userAccessLevel.collectAsStateWithLifecycle()
|
||||||
|
val allHistory by viewModel.allHistoryState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
var selectedOverdueGroup by remember { mutableStateOf<SelectedOverdueGroup?>(null) }
|
||||||
|
var selectedActivityToEdit by remember { mutableStateOf<MaintenanceActivity?>(null) }
|
||||||
|
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
|
val gso = remember {
|
||||||
|
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
|
||||||
|
.requestEmail()
|
||||||
|
.requestProfile()
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
val googleSignInClient = remember { GoogleSignIn.getClient(context, gso) }
|
||||||
|
|
||||||
|
val googleSignInLauncher = rememberLauncherForActivityResult(
|
||||||
|
contract = ActivityResultContracts.StartActivityForResult()
|
||||||
|
) { result ->
|
||||||
|
val task = GoogleSignIn.getSignedInAccountFromIntent(result.data)
|
||||||
|
try {
|
||||||
|
val account = task.getResult(ApiException::class.java)
|
||||||
|
if (account != null) {
|
||||||
|
val email = account.email ?: ""
|
||||||
|
val name = account.displayName ?: ""
|
||||||
|
viewModel.loginUser(email, name)
|
||||||
|
Toast.makeText(context, "Conectado como $name", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
} catch (e: ApiException) {
|
||||||
|
Toast.makeText(context, "Falha no Google Sign-In (Erro ${e.statusCode})", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
topBar = {
|
topBar = {
|
||||||
@@ -119,10 +173,58 @@ fun AnalyticsScreen(
|
|||||||
// Card 2: Progresso do Projeto: Planejado vs. Realizado
|
// Card 2: Progresso do Projeto: Planejado vs. Realizado
|
||||||
SCurveCard(analyticsState)
|
SCurveCard(analyticsState)
|
||||||
|
|
||||||
// Card 3: Atrasados por TAG
|
// Card 3: OSs Atrasadas (TAG / Setor alternáveis por swipe e clicáveis)
|
||||||
OverdueByTagCard(analyticsState.overdueByTag)
|
OverdueAnalyticsCard(
|
||||||
|
analyticsState = analyticsState,
|
||||||
|
onBarClick = { type, label ->
|
||||||
|
selectedOverdueGroup = SelectedOverdueGroup(type, label)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Modal 1: Listagem das OSs Atrasadas por Grupo (TAG ou Setor)
|
||||||
|
selectedOverdueGroup?.let { group ->
|
||||||
|
val topSectors = analyticsState.overdueBySector.take(3).map { it.first }
|
||||||
|
OverdueActivitiesListModal(
|
||||||
|
group = group,
|
||||||
|
allActivities = activities,
|
||||||
|
projectEnd = analyticsState.projectEnd,
|
||||||
|
topSectors = topSectors,
|
||||||
|
onDismiss = { selectedOverdueGroup = null },
|
||||||
|
onActivityClick = { activity ->
|
||||||
|
selectedOverdueGroup = null
|
||||||
|
selectedActivityToEdit = activity
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Modal 2: Edição da OS Selecionada
|
||||||
|
selectedActivityToEdit?.let { activity ->
|
||||||
|
val history = remember(allHistory, activity) {
|
||||||
|
allHistory.filter { it.numeroOs == activity.numeroOs }
|
||||||
|
}
|
||||||
|
EditActivityBottomSheet(
|
||||||
|
activity = activity,
|
||||||
|
history = history,
|
||||||
|
currentUser = currentUser,
|
||||||
|
userAccessLevel = userAccessLevel,
|
||||||
|
onDismiss = { selectedActivityToEdit = null },
|
||||||
|
onUpdateProgress = { newPercentual, observation, photoPath ->
|
||||||
|
viewModel.updateProgress(
|
||||||
|
numeroOs = activity.numeroOs,
|
||||||
|
novoPercentual = newPercentual,
|
||||||
|
observacao = observation,
|
||||||
|
fotoPath = photoPath,
|
||||||
|
recurso = currentUser?.displayName ?: "Encarregado Campo",
|
||||||
|
emailEditor = currentUser?.email
|
||||||
|
)
|
||||||
|
},
|
||||||
|
onGoogleLoginClick = {
|
||||||
|
googleSignInLauncher.launch(googleSignInClient.signInIntent)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,11 +463,17 @@ fun SCurveCard(analyticsState: AnalyticsState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gráfico 3: OSs Atrasadas por TAG (Ativo)
|
* Gráfico 3: OSs Atrasadas por TAG e por Setor
|
||||||
* Lista as TAGs com maior volume de OSs pendentes e com prazo vencido
|
* Permite alternar horizontalmente (swipe) entre as duas visualizações e clicar nas barras para ver detalhes.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
fun OverdueAnalyticsCard(
|
||||||
|
analyticsState: AnalyticsState,
|
||||||
|
onBarClick: (OverdueGroupType, String) -> Unit = { _, _ -> }
|
||||||
|
) {
|
||||||
|
val pagerState = rememberPagerState(pageCount = { 2 })
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
|
|
||||||
Card(
|
Card(
|
||||||
modifier = Modifier.fillMaxWidth(),
|
modifier = Modifier.fillMaxWidth(),
|
||||||
colors = CardDefaults.cardColors(containerColor = Color.White),
|
colors = CardDefaults.cardColors(containerColor = Color.White),
|
||||||
@@ -377,18 +485,238 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
|||||||
.padding(16.dp)
|
.padding(16.dp)
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
) {
|
) {
|
||||||
Text(
|
// Header with Dynamic Title & Page Indicator Dots
|
||||||
text = "Atrasados por TAG",
|
Row(
|
||||||
fontSize = 16.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = BrandBlack,
|
|
||||||
textAlign = TextAlign.Center,
|
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.padding(bottom = 16.dp)
|
.padding(bottom = 16.dp),
|
||||||
)
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = if (pagerState.currentPage == 0) "Atrasados por TAG" else "Atrasados por Setor",
|
||||||
|
fontSize = 16.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BrandBlack
|
||||||
|
)
|
||||||
|
|
||||||
if (overdueByTag.isEmpty()) {
|
// Page Indicator Dots
|
||||||
|
Row(
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(6.dp),
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
repeat(2) { index ->
|
||||||
|
val isSelected = pagerState.currentPage == index
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.size(if (isSelected) 10.dp else 8.dp)
|
||||||
|
.background(
|
||||||
|
color = if (isSelected) BrandGreen else Color.LightGray,
|
||||||
|
shape = CircleShape
|
||||||
|
)
|
||||||
|
.clickable {
|
||||||
|
coroutineScope.launch {
|
||||||
|
pagerState.animateScrollToPage(index)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HorizontalPager(
|
||||||
|
state = pagerState,
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) { page ->
|
||||||
|
val (items, emptyMsg) = if (page == 0) {
|
||||||
|
analyticsState.overdueByTag to "Parabéns! Nenhuma OS atrasada por TAG no momento."
|
||||||
|
} else {
|
||||||
|
analyticsState.overdueBySector to "Parabéns! Nenhuma OS atrasada por Setor no momento."
|
||||||
|
}
|
||||||
|
|
||||||
|
OverdueBarChartContent(
|
||||||
|
displayList = items,
|
||||||
|
emptyMessage = emptyMsg,
|
||||||
|
onItemClick = { label ->
|
||||||
|
val groupType = if (page == 0) OverdueGroupType.TAG else OverdueGroupType.SETOR
|
||||||
|
onBarClick(groupType, label)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun OverdueBarChartContent(
|
||||||
|
displayList: List<Pair<String, Int>>,
|
||||||
|
emptyMessage: String,
|
||||||
|
onItemClick: (String) -> Unit = {}
|
||||||
|
) {
|
||||||
|
if (displayList.isEmpty()) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(100.dp),
|
||||||
|
contentAlignment = Alignment.Center
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = emptyMessage,
|
||||||
|
color = Color(0xFF2E7D32),
|
||||||
|
fontWeight = FontWeight.Medium,
|
||||||
|
fontSize = 13.sp,
|
||||||
|
textAlign = TextAlign.Center
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
val maxCount = displayList.maxOfOrNull { it.second } ?: 1
|
||||||
|
|
||||||
|
Column(
|
||||||
|
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||||
|
modifier = Modifier.fillMaxWidth()
|
||||||
|
) {
|
||||||
|
displayList.forEachIndexed { index, (label, count) ->
|
||||||
|
val barColor = when (index) {
|
||||||
|
0 -> Color(0xFF4CAF50) // Green
|
||||||
|
1 -> Color(0xFF2196F3) // Blue
|
||||||
|
2 -> Color(0xFFFF9800) // Orange
|
||||||
|
3 -> Color(0xFFFFC107) // Amber/Yellow
|
||||||
|
else -> Color(0xFF9C27B0) // Purple
|
||||||
|
}
|
||||||
|
|
||||||
|
Row(
|
||||||
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.clickable { onItemClick(label) }
|
||||||
|
.padding(vertical = 4.dp)
|
||||||
|
) {
|
||||||
|
// Label (TAG Name or Sector Name)
|
||||||
|
Text(
|
||||||
|
text = label,
|
||||||
|
fontSize = 12.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BrandBlack,
|
||||||
|
modifier = Modifier.width(90.dp),
|
||||||
|
maxLines = 1
|
||||||
|
)
|
||||||
|
|
||||||
|
// Bar Container
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.weight(1f)
|
||||||
|
.height(18.dp)
|
||||||
|
.background(Color(0xFFEEEEEE), shape = RoundedCornerShape(4.dp))
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(count.toFloat() / maxCount.toFloat())
|
||||||
|
.fillMaxHeight()
|
||||||
|
.background(barColor, shape = RoundedCornerShape(4.dp))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.width(8.dp))
|
||||||
|
|
||||||
|
// Count number
|
||||||
|
Text(
|
||||||
|
text = count.toString(),
|
||||||
|
fontSize = 12.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BrandBlack,
|
||||||
|
modifier = Modifier.width(20.dp),
|
||||||
|
textAlign = TextAlign.End
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modal dialog displaying the list of overdue OSs for a selected TAG or Sector.
|
||||||
|
*/
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun OverdueActivitiesListModal(
|
||||||
|
group: SelectedOverdueGroup,
|
||||||
|
allActivities: List<MaintenanceActivity>,
|
||||||
|
projectEnd: Date,
|
||||||
|
topSectors: List<String>,
|
||||||
|
onDismiss: () -> Unit,
|
||||||
|
onActivityClick: (MaintenanceActivity) -> Unit
|
||||||
|
) {
|
||||||
|
val referenceDate = remember(projectEnd) {
|
||||||
|
if (Date().before(projectEnd)) projectEnd else Date()
|
||||||
|
}
|
||||||
|
|
||||||
|
val filteredActivities = remember(group, allActivities, referenceDate, topSectors) {
|
||||||
|
allActivities.filter { act ->
|
||||||
|
val isNotCompleted = act.percentualExecucao < 100
|
||||||
|
val endDate = parseDateOnly(act.dataFim)
|
||||||
|
val isOverdue = isNotCompleted && endDate != null && endDate.before(referenceDate)
|
||||||
|
|
||||||
|
if (!isOverdue) return@filter false
|
||||||
|
|
||||||
|
when (group.type) {
|
||||||
|
OverdueGroupType.TAG -> {
|
||||||
|
if (group.label == "Sem TAG") act.tag.isBlank() else act.tag == group.label
|
||||||
|
}
|
||||||
|
OverdueGroupType.SETOR -> {
|
||||||
|
val actSetor = if (act.setor.isBlank()) "Sem Setor" else act.setor
|
||||||
|
if (group.label == "Outros") {
|
||||||
|
!topSectors.contains(actSetor)
|
||||||
|
} else if (group.label == "Sem Setor") {
|
||||||
|
act.setor.isBlank()
|
||||||
|
} else {
|
||||||
|
act.setor == group.label
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AlertDialog(
|
||||||
|
onDismissRequest = onDismiss,
|
||||||
|
confirmButton = {
|
||||||
|
TextButton(onClick = onDismiss) {
|
||||||
|
Text("Fechar", color = BrandGreen, fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
title = {
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
|
verticalAlignment = Alignment.CenterVertically
|
||||||
|
) {
|
||||||
|
Column(modifier = Modifier.weight(1f)) {
|
||||||
|
Text(
|
||||||
|
text = "OSs Atrasadas",
|
||||||
|
fontSize = 12.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = Color.Gray
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
text = "${if (group.type == OverdueGroupType.TAG) "TAG" else "Setor"}: ${group.label}",
|
||||||
|
fontSize = 16.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = BrandBlack
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Badge(
|
||||||
|
containerColor = Color(0xFFC5221F),
|
||||||
|
contentColor = Color.White
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "${filteredActivities.size} OS",
|
||||||
|
fontSize = 11.sp,
|
||||||
|
modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
text = {
|
||||||
|
if (filteredActivities.isEmpty()) {
|
||||||
Box(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
@@ -396,73 +724,80 @@ fun OverdueByTagCard(overdueByTag: List<Pair<String, Int>>) {
|
|||||||
contentAlignment = Alignment.Center
|
contentAlignment = Alignment.Center
|
||||||
) {
|
) {
|
||||||
Text(
|
Text(
|
||||||
text = "Parabéns! Nenhuma OS atrasada no momento.",
|
text = "Nenhuma ordem de serviço pendente encontrada nesta categoria.",
|
||||||
color = Color(0xFF2E7D32),
|
fontSize = 13.sp,
|
||||||
fontWeight = FontWeight.Medium,
|
color = Color.Gray,
|
||||||
fontSize = 13.sp
|
textAlign = TextAlign.Center
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val displayList = overdueByTag
|
LazyColumn(
|
||||||
val maxCount = displayList.maxOfOrNull { it.second } ?: 1
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
Column(
|
.heightIn(max = 350.dp),
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
) {
|
||||||
displayList.forEachIndexed { index, (tag, count) ->
|
items(filteredActivities) { activity ->
|
||||||
val barColor = when (index) {
|
Card(
|
||||||
0 -> Color(0xFF4CAF50) // Green
|
modifier = Modifier
|
||||||
1 -> Color(0xFF2196F3) // Blue
|
.fillMaxWidth()
|
||||||
2 -> Color(0xFFFF9800) // Orange
|
.clickable { onActivityClick(activity) },
|
||||||
3 -> Color(0xFFFFC107) // Amber/Yellow
|
colors = CardDefaults.cardColors(containerColor = Color(0xFFF9F9F9)),
|
||||||
else -> Color(0xFF9C27B0) // Purple
|
border = BorderStroke(1.dp, Color(0xFFE0E0E0)),
|
||||||
}
|
shape = RoundedCornerShape(8.dp)
|
||||||
|
|
||||||
Row(
|
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
modifier = Modifier.fillMaxWidth()
|
|
||||||
) {
|
) {
|
||||||
// TAG Name
|
Column(modifier = Modifier.padding(12.dp)) {
|
||||||
Text(
|
Row(
|
||||||
text = tag,
|
modifier = Modifier.fillMaxWidth(),
|
||||||
fontSize = 12.sp,
|
horizontalArrangement = Arrangement.SpaceBetween,
|
||||||
fontWeight = FontWeight.Bold,
|
verticalAlignment = Alignment.CenterVertically
|
||||||
color = BrandBlack,
|
) {
|
||||||
modifier = Modifier.width(90.dp),
|
Text(
|
||||||
maxLines = 1
|
text = activity.numeroOs,
|
||||||
)
|
fontSize = 14.sp,
|
||||||
|
fontWeight = FontWeight.Black,
|
||||||
|
color = BrandBlack
|
||||||
|
)
|
||||||
|
Surface(
|
||||||
|
color = Color(0xFFFFF3E0),
|
||||||
|
shape = RoundedCornerShape(4.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "${activity.percentualExecucao}%",
|
||||||
|
fontSize = 11.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = Color(0xFFE65100),
|
||||||
|
modifier = Modifier.padding(horizontal = 6.dp, vertical = 2.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Bar Container
|
Spacer(modifier = Modifier.height(4.dp))
|
||||||
Box(
|
Text(
|
||||||
modifier = Modifier
|
text = activity.descricao,
|
||||||
.weight(1f)
|
fontSize = 12.sp,
|
||||||
.height(18.dp)
|
fontWeight = FontWeight.Medium,
|
||||||
.background(Color(0xFFEEEEEE), shape = RoundedCornerShape(4.dp))
|
color = Color.DarkGray,
|
||||||
) {
|
maxLines = 2
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(count.toFloat() / maxCount.toFloat())
|
|
||||||
.fillMaxHeight()
|
|
||||||
.background(barColor, shape = RoundedCornerShape(4.dp))
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(6.dp))
|
||||||
|
Row(horizontalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||||
|
if (activity.setor.isNotBlank()) {
|
||||||
|
Text("Setor: ${activity.setor}", fontSize = 10.sp, color = BrandGreen, fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
if (activity.tag.isNotBlank()) {
|
||||||
|
Text("TAG: ${activity.tag}", fontSize = 10.sp, color = Color(0xFF1976D2), fontWeight = FontWeight.Bold)
|
||||||
|
}
|
||||||
|
Text("Fim: ${activity.dataFim}", fontSize = 10.sp, color = Color.Gray)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Spacer(modifier = Modifier.width(8.dp))
|
|
||||||
|
|
||||||
// Count number
|
|
||||||
Text(
|
|
||||||
text = count.toString(),
|
|
||||||
fontSize = 12.sp,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = BrandBlack,
|
|
||||||
modifier = Modifier.width(20.dp),
|
|
||||||
textAlign = TextAlign.End
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}
|
shape = RoundedCornerShape(16.dp),
|
||||||
|
containerColor = Color.White
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Overdue tags
|
// 3. Overdue tags and sectors
|
||||||
val referenceDate = if (Date().before(projectEnd)) projectEnd else Date()
|
val referenceDate = if (Date().before(projectEnd)) projectEnd else Date()
|
||||||
|
|
||||||
val overdueActivities = activities.filter { act ->
|
val overdueActivities = activities.filter { act ->
|
||||||
@@ -581,6 +581,31 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
top + listOf("Outros" to othersCount)
|
top + listOf("Outros" to othersCount)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val overdueBySectorMap = overdueActivities
|
||||||
|
.groupBy { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||||
|
.mapValues { it.value.size }
|
||||||
|
|
||||||
|
val finalOverdueBySector = if (overdueActivities.isEmpty()) {
|
||||||
|
emptyList()
|
||||||
|
} else {
|
||||||
|
val plantSectors = activities
|
||||||
|
.map { if (it.setor.isBlank()) "Sem Setor" else it.setor }
|
||||||
|
.distinct()
|
||||||
|
|
||||||
|
val fullOverdueBySector = plantSectors
|
||||||
|
.map { sector -> sector to (overdueBySectorMap[sector] ?: 0) }
|
||||||
|
.sortedWith(compareByDescending<Pair<String, Int>> { it.second }.thenBy { it.first })
|
||||||
|
|
||||||
|
val displayLimit = 4
|
||||||
|
if (fullOverdueBySector.size <= displayLimit) {
|
||||||
|
fullOverdueBySector
|
||||||
|
} else {
|
||||||
|
val top = fullOverdueBySector.take(displayLimit - 1)
|
||||||
|
val othersCount = fullOverdueBySector.drop(displayLimit - 1).sumOf { it.second }
|
||||||
|
top + listOf("Outros" to othersCount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return AnalyticsState(
|
return AnalyticsState(
|
||||||
teamMetrics = teamMetrics,
|
teamMetrics = teamMetrics,
|
||||||
projectStart = projectStart,
|
projectStart = projectStart,
|
||||||
@@ -588,7 +613,8 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
|||||||
timelineDates = timelineDates,
|
timelineDates = timelineDates,
|
||||||
plannedProgressPoints = plannedProgressPoints,
|
plannedProgressPoints = plannedProgressPoints,
|
||||||
realizedProgressPoints = realizedProgressPoints,
|
realizedProgressPoints = realizedProgressPoints,
|
||||||
overdueByTag = finalOverdueByTag
|
overdueByTag = finalOverdueByTag,
|
||||||
|
overdueBySector = finalOverdueBySector
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider
|
|||||||
import com.example.data.local.AppDatabase
|
import com.example.data.local.AppDatabase
|
||||||
import com.example.data.remote.GoogleSheetsSyncService
|
import com.example.data.remote.GoogleSheetsSyncService
|
||||||
import org.junit.Assert.assertEquals
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Assert.assertNotNull
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.junit.runner.RunWith
|
import org.junit.runner.RunWith
|
||||||
import org.robolectric.RobolectricTestRunner
|
import org.robolectric.RobolectricTestRunner
|
||||||
@@ -252,6 +253,9 @@ class ExampleRobolectricTest {
|
|||||||
// 4. Verify realized progress points has correct count
|
// 4. Verify realized progress points has correct count
|
||||||
assertEquals(5, state.realizedProgressPoints.size)
|
assertEquals(5, state.realizedProgressPoints.size)
|
||||||
|
|
||||||
|
// 5. Verify overdueBySector is present
|
||||||
|
assertNotNull(state.overdueBySector)
|
||||||
|
|
||||||
collectionJob.cancel()
|
collectionJob.cancel()
|
||||||
}
|
}
|
||||||
db.close()
|
db.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user