Snapshot: Filtro de data corrigido para dd/mm/aa
This commit is contained in:
85
app/src/main/java/com/example/ui/components/CargillLogo.kt
Normal file
85
app/src/main/java/com/example/ui/components/CargillLogo.kt
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.example.ui.components
|
||||
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Path
|
||||
import androidx.compose.ui.graphics.drawscope.Fill
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontStyle
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Official Cargill Colors for Theme Integration
|
||||
val CargillGreen = Color(0xFF005F40) // Beautiful forest/leaf green
|
||||
val CargillBlack = Color(0xFF1A1A1A) // High contrast premium charcoal-black
|
||||
|
||||
@Composable
|
||||
fun CargillLogo(
|
||||
modifier: Modifier = Modifier,
|
||||
showText: Boolean = true,
|
||||
lightMode: Boolean = true
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier.height(48.dp),
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
// Draw the iconic curved leaf logo using Compose Canvas
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.width(52.dp)
|
||||
.fillMaxHeight()
|
||||
.padding(vertical = 4.dp)
|
||||
) {
|
||||
val w = size.width
|
||||
val h = size.height
|
||||
|
||||
// High precision path modeling Cargill's leaf swoosh
|
||||
val path = Path().apply {
|
||||
// Outer arch
|
||||
moveTo(w * 0.05f, h * 0.85f)
|
||||
cubicTo(
|
||||
w * 0.20f, h * 0.05f, // Control 1
|
||||
w * 0.80f, h * 0.05f, // Control 2
|
||||
w * 0.95f, h * 0.85f // End
|
||||
)
|
||||
// Bottom inner curve to create a leaf shape thickness
|
||||
cubicTo(
|
||||
w * 0.75f, h * 0.35f, // Control 1 (tighter)
|
||||
w * 0.25f, h * 0.35f, // Control 2 (tighter)
|
||||
w * 0.05f, h * 0.85f // Back to start
|
||||
)
|
||||
close()
|
||||
}
|
||||
|
||||
drawPath(
|
||||
path = path,
|
||||
color = CargillGreen,
|
||||
style = Fill
|
||||
)
|
||||
}
|
||||
|
||||
if (showText) {
|
||||
Text(
|
||||
text = "Cargill",
|
||||
color = if (lightMode) CargillBlack else Color.White,
|
||||
fontSize = 24.sp,
|
||||
fontFamily = FontFamily.SansSerif,
|
||||
fontWeight = FontWeight.Black,
|
||||
fontStyle = FontStyle.Italic,
|
||||
modifier = Modifier.padding(start = 4.dp, bottom = 2.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
12
app/src/main/java/com/example/ui/theme/Color.kt
Normal file
12
app/src/main/java/com/example/ui/theme/Color.kt
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.example.ui.theme
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
|
||||
val CargillGreen = Color(0xFF005F40)
|
||||
val CargillBlack = Color(0xFF1A1A1A)
|
||||
val CargillLightGreen = Color(0xFFE8F5E9)
|
||||
|
||||
val DarkGreen = Color(0xFF003D28)
|
||||
val Charcoal = Color(0xFF2C2C2C)
|
||||
val LightGrey = Color(0xFFF5F7F6)
|
||||
|
||||
51
app/src/main/java/com/example/ui/theme/Theme.kt
Normal file
51
app/src/main/java/com/example/ui/theme/Theme.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
package com.example.ui.theme
|
||||
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
private val DarkColorScheme =
|
||||
darkColorScheme(
|
||||
primary = CargillGreen,
|
||||
secondary = Charcoal,
|
||||
tertiary = CargillLightGreen,
|
||||
background = CargillBlack,
|
||||
surface = Charcoal
|
||||
)
|
||||
|
||||
private val LightColorScheme =
|
||||
lightColorScheme(
|
||||
primary = CargillGreen,
|
||||
secondary = CargillBlack,
|
||||
tertiary = CargillLightGreen,
|
||||
background = LightGrey,
|
||||
surface = Color.White
|
||||
)
|
||||
|
||||
@Composable
|
||||
fun MyApplicationTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
// Set dynamic color to false by default to strictly preserve our Cargill green identity
|
||||
dynamicColor: Boolean = false,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val colorScheme =
|
||||
when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
val context = LocalContext.current
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
darkTheme -> DarkColorScheme
|
||||
else -> LightColorScheme
|
||||
}
|
||||
|
||||
MaterialTheme(colorScheme = colorScheme, typography = Typography, content = content)
|
||||
}
|
||||
36
app/src/main/java/com/example/ui/theme/Type.kt
Normal file
36
app/src/main/java/com/example/ui/theme/Type.kt
Normal file
@@ -0,0 +1,36 @@
|
||||
package com.example.ui.theme
|
||||
|
||||
import androidx.compose.material3.Typography
|
||||
import androidx.compose.ui.text.TextStyle
|
||||
import androidx.compose.ui.text.font.FontFamily
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.sp
|
||||
|
||||
// Set of Material typography styles to start with
|
||||
val Typography =
|
||||
Typography(
|
||||
bodyLarge =
|
||||
TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 16.sp,
|
||||
lineHeight = 24.sp,
|
||||
letterSpacing = 0.5.sp,
|
||||
)
|
||||
/* Other default text styles to override
|
||||
titleLarge = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Normal,
|
||||
fontSize = 22.sp,
|
||||
lineHeight = 28.sp,
|
||||
letterSpacing = 0.sp
|
||||
),
|
||||
labelSmall = TextStyle(
|
||||
fontFamily = FontFamily.Default,
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.sp,
|
||||
lineHeight = 16.sp,
|
||||
letterSpacing = 0.5.sp
|
||||
)
|
||||
*/
|
||||
)
|
||||
@@ -0,0 +1,297 @@
|
||||
package com.example.ui.viewmodel
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.example.data.model.ActivityStatus
|
||||
import com.example.data.model.MaintenanceActivity
|
||||
import com.example.data.model.OSUpdateHistory
|
||||
import com.example.data.model.extractDateOnly
|
||||
import com.example.data.model.formatToShortDate
|
||||
import com.example.data.model.parseFullDateTime
|
||||
import com.example.data.repository.MaintenanceRepository
|
||||
import com.example.data.repository.SyncResult
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class MaintenanceViewModel(private val repository: MaintenanceRepository) : ViewModel() {
|
||||
|
||||
// Filtering inputs
|
||||
private val _selectedSetor = MutableStateFlow("Todos")
|
||||
val selectedSetor = _selectedSetor.asStateFlow()
|
||||
|
||||
private val _selectedEquipe = MutableStateFlow("Todas")
|
||||
val selectedEquipe = _selectedEquipe.asStateFlow()
|
||||
|
||||
private val _selectedStatus = MutableStateFlow("Todos")
|
||||
val selectedStatus = _selectedStatus.asStateFlow()
|
||||
|
||||
private val _selectedDataInicio = MutableStateFlow("Todas")
|
||||
val selectedDataInicio = _selectedDataInicio.asStateFlow()
|
||||
|
||||
private val _selectedResponsavel = MutableStateFlow("Todos")
|
||||
val selectedResponsavel = _selectedResponsavel.asStateFlow()
|
||||
|
||||
private val _searchQuery = MutableStateFlow("")
|
||||
val searchQuery = _searchQuery.asStateFlow()
|
||||
|
||||
// UI Operation States
|
||||
private val _isSyncing = MutableStateFlow(false)
|
||||
val isSyncing = _isSyncing.asStateFlow()
|
||||
|
||||
private val _syncStatusMessage = MutableStateFlow<String?>(null)
|
||||
val syncStatusMessage = _syncStatusMessage.asStateFlow()
|
||||
|
||||
private val _importStatusMessage = MutableStateFlow<String?>(null)
|
||||
val importStatusMessage = _importStatusMessage.asStateFlow()
|
||||
|
||||
// Simulator Toggle: Allows users to simulate online/offline state explicitly in the UI
|
||||
private val _internetAvailable = MutableStateFlow(true) // Default online to ensure immediate network connectivity on launch
|
||||
val internetAvailable = _internetAvailable.asStateFlow()
|
||||
|
||||
// Selected OS for Detail and Updates
|
||||
private val _selectedActivity = MutableStateFlow<MaintenanceActivity?>(null)
|
||||
val selectedActivity = _selectedActivity.asStateFlow()
|
||||
|
||||
// All activities from repository
|
||||
val allActivitiesState: StateFlow<List<MaintenanceActivity>> = repository.allActivities
|
||||
.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = emptyList()
|
||||
)
|
||||
|
||||
// Filtered activities list
|
||||
val filteredActivities: StateFlow<List<MaintenanceActivity>> = combine(
|
||||
repository.allActivities,
|
||||
_selectedSetor,
|
||||
_selectedEquipe,
|
||||
_selectedStatus,
|
||||
_selectedDataInicio,
|
||||
_selectedResponsavel,
|
||||
_searchQuery
|
||||
) { flowsArray ->
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val activities = flowsArray[0] as List<MaintenanceActivity>
|
||||
val setor = flowsArray[1] as String
|
||||
val equipe = flowsArray[2] as String
|
||||
val status = flowsArray[3] as String
|
||||
val dataInicio = flowsArray[4] as String
|
||||
val responsavel = flowsArray[5] as String
|
||||
val query = flowsArray[6] as String
|
||||
|
||||
val filtered = activities.filter { activity ->
|
||||
val matchSetor = setor == "Todos" || activity.setor == setor
|
||||
val matchEquipe = equipe == "Todas" || activity.equipe == equipe
|
||||
val matchStatus = status == "Todos" || when (status) {
|
||||
"Não iniciado" -> activity.status == ActivityStatus.NAO_INICIADO
|
||||
"Em andamento" -> activity.status == ActivityStatus.EM_ANDAMENTO
|
||||
"Concluído" -> activity.status == ActivityStatus.CONCLUIDO
|
||||
else -> true
|
||||
}
|
||||
val matchDataInicio = dataInicio == "Todas" || formatToShortDate(activity.dataInicio) == dataInicio
|
||||
val matchResponsavel = responsavel == "Todos" || activity.responsavel == responsavel
|
||||
val matchQuery = query.isBlank() ||
|
||||
activity.numeroOs.contains(query, ignoreCase = true) ||
|
||||
activity.descricao.contains(query, ignoreCase = true) ||
|
||||
activity.responsavel.contains(query, ignoreCase = true)
|
||||
|
||||
matchSetor && matchEquipe && matchStatus && matchDataInicio && matchResponsavel && matchQuery
|
||||
}
|
||||
|
||||
if (dataInicio != "Todas") {
|
||||
filtered.sortedWith { a1, a2 ->
|
||||
val p1 = parseFullDateTime(a1.dataInicio)
|
||||
val p2 = parseFullDateTime(a2.dataInicio)
|
||||
when {
|
||||
p1 == null && p2 == null -> a1.numeroOs.compareTo(a2.numeroOs)
|
||||
p1 == null -> 1
|
||||
p2 == null -> -1
|
||||
else -> p1.compareTo(p2)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filtered
|
||||
}
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = emptyList()
|
||||
)
|
||||
|
||||
// Reactive Flow for the current activity's edit history
|
||||
val selectedActivityHistory: StateFlow<List<OSUpdateHistory>> = _selectedActivity
|
||||
.flatMapLatest { activity ->
|
||||
if (activity != null) {
|
||||
repository.getHistoryForOs(activity.numeroOs)
|
||||
} else {
|
||||
flowOf(emptyList())
|
||||
}
|
||||
}
|
||||
.stateIn(
|
||||
scope = viewModelScope,
|
||||
started = SharingStarted.WhileSubscribed(5000),
|
||||
initialValue = emptyList()
|
||||
)
|
||||
|
||||
init {
|
||||
// Automatically check and pull service orders from Sheets on first launch. Fall back to local sample data if sync fails.
|
||||
viewModelScope.launch {
|
||||
val currentList = repository.allActivities.first()
|
||||
if (currentList.isEmpty()) {
|
||||
_internetAvailable.value = true
|
||||
_isSyncing.value = true
|
||||
_syncStatusMessage.value = "Conectando ao servidor Cargill para baixar ordens de serviço..."
|
||||
|
||||
when (val result = repository.synchronizeWithBackend()) {
|
||||
is SyncResult.Success -> {
|
||||
_syncStatusMessage.value = "Sincronização inicial concluída! ${result.syncedItems} OSs sincronizadas."
|
||||
}
|
||||
is SyncResult.Error -> {
|
||||
// Safe offline fallback in case of no connectivity or invalid credentials
|
||||
_syncStatusMessage.value = "Usando dados modelo: ${result.message}"
|
||||
repository.loadSampleData()
|
||||
}
|
||||
}
|
||||
_isSyncing.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun selectActivity(activity: MaintenanceActivity?) {
|
||||
_selectedActivity.value = activity
|
||||
}
|
||||
|
||||
fun setFilterSetor(setor: String) {
|
||||
_selectedSetor.value = setor
|
||||
}
|
||||
|
||||
fun setFilterEquipe(equipe: String) {
|
||||
_selectedEquipe.value = equipe
|
||||
}
|
||||
|
||||
fun setFilterStatus(status: String) {
|
||||
_selectedStatus.value = status
|
||||
}
|
||||
|
||||
fun setFilterDataInicio(dataInicio: String) {
|
||||
_selectedDataInicio.value = dataInicio
|
||||
}
|
||||
|
||||
fun setFilterResponsavel(responsavel: String) {
|
||||
_selectedResponsavel.value = responsavel
|
||||
}
|
||||
|
||||
fun setSearchQuery(query: String) {
|
||||
_searchQuery.value = query
|
||||
}
|
||||
|
||||
fun toggleInternet(available: Boolean) {
|
||||
_internetAvailable.value = available
|
||||
if (!available) {
|
||||
_syncStatusMessage.value = null
|
||||
}
|
||||
}
|
||||
|
||||
fun clearMessages() {
|
||||
_syncStatusMessage.value = null
|
||||
_importStatusMessage.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggers a PCM spreadsheet (CSV) import.
|
||||
*/
|
||||
fun importSpreadsheet(context: Context, uri: Uri) {
|
||||
viewModelScope.launch {
|
||||
_importStatusMessage.value = "Importando..."
|
||||
val result = repository.importCsvFromUri(context, uri)
|
||||
result.onSuccess { count ->
|
||||
_importStatusMessage.value = "Sucesso: $count ordens de serviço importadas/atualizadas!"
|
||||
}.onFailure { error ->
|
||||
_importStatusMessage.value = "Erro na importação: ${error.localizedMessage}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to preload sample data on-demand.
|
||||
*/
|
||||
fun resetToSampleData() {
|
||||
viewModelScope.launch {
|
||||
_importStatusMessage.value = "Carregando planilha modelo..."
|
||||
repository.loadSampleData()
|
||||
_importStatusMessage.value = "Ordens de serviço padrão carregadas com sucesso!"
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs synchronized check.
|
||||
*/
|
||||
fun syncNow() {
|
||||
if (!_internetAvailable.value) {
|
||||
_syncStatusMessage.value = "Sincronização impossível: Sem conectividade de rede na área atual."
|
||||
return
|
||||
}
|
||||
|
||||
viewModelScope.launch {
|
||||
_isSyncing.value = true
|
||||
_syncStatusMessage.value = "Conectando ao servidor central da Cargill..."
|
||||
|
||||
when (val result = repository.synchronizeWithBackend()) {
|
||||
is SyncResult.Success -> {
|
||||
_syncStatusMessage.value = "Sincronização concluída! ${result.syncedItems} OSs sincronizadas com sucesso. Conflitos resolvidos: ${result.conflictsResolved}."
|
||||
// Refresh selected activity if active to show sync badge
|
||||
_selectedActivity.value?.let { active ->
|
||||
_selectedActivity.value = allActivitiesState.value.find { it.numeroOs == active.numeroOs }
|
||||
}
|
||||
}
|
||||
is SyncResult.Error -> {
|
||||
_syncStatusMessage.value = "Falha na sincronização: ${result.message}"
|
||||
}
|
||||
}
|
||||
_isSyncing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits progress updates and creates log.
|
||||
*/
|
||||
fun updateProgress(
|
||||
numeroOs: String,
|
||||
novoPercentual: Int,
|
||||
observacao: String?,
|
||||
fotoPath: String?,
|
||||
responsavel: String
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
repository.updateProgress(numeroOs, novoPercentual, observacao, fotoPath, responsavel)
|
||||
// Update selected activity model in state to refresh UI
|
||||
_selectedActivity.value?.let { active ->
|
||||
if (active.numeroOs == numeroOs) {
|
||||
val updatedList = allActivitiesState.value
|
||||
_selectedActivity.value = updatedList.find { it.numeroOs == numeroOs }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MaintenanceViewModelFactory(private val repository: MaintenanceRepository) : ViewModelProvider.Factory {
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
if (modelClass.isAssignableFrom(MaintenanceViewModel::class.java)) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return MaintenanceViewModel(repository) as T
|
||||
}
|
||||
throw IllegalArgumentException("Unknown ViewModel class")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user