feat: integrate Google Authentication and track email editor in maintenance history
This commit is contained in:
@@ -120,6 +120,7 @@ dependencies {
|
||||
implementation(libs.moshi.kotlin)
|
||||
implementation(libs.okhttp)
|
||||
implementation(libs.google.auth.library.oauth2.http)
|
||||
implementation(libs.play.services.auth)
|
||||
// implementation(libs.play.services.location)
|
||||
implementation(libs.retrofit)
|
||||
testImplementation(libs.androidx.compose.ui.test.junit4)
|
||||
@@ -140,4 +141,6 @@ dependencies {
|
||||
debugImplementation(libs.androidx.compose.ui.tooling)
|
||||
"ksp"(libs.androidx.room.compiler)
|
||||
"ksp"(libs.moshi.kotlin.codegen)
|
||||
implementation(platform("com.google.firebase:firebase-bom:34.16.0"))
|
||||
implementation("com.google.firebase:firebase-analytics")
|
||||
}
|
||||
|
||||
47
app/google-services.json
Normal file
47
app/google-services.json
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "461441632355",
|
||||
"project_id": "gestao-parada-os",
|
||||
"storage_bucket": "gestao-parada-os.firebasestorage.app"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:461441632355:android:8ea9121be8cf81b4ee5056",
|
||||
"android_client_info": {
|
||||
"package_name": "com.aistudio.cargillparadaos.xvyzwt"
|
||||
}
|
||||
},
|
||||
"oauth_client": [
|
||||
{
|
||||
"client_id": "461441632355-rg9go0tcsr8ora2la83aat9pcekqo13p.apps.googleusercontent.com",
|
||||
"client_type": 1,
|
||||
"android_info": {
|
||||
"package_name": "com.aistudio.cargillparadaos.xvyzwt",
|
||||
"certificate_hash": "6274d8aa0709c0454af47340ae8f223b8a0fbd61"
|
||||
}
|
||||
},
|
||||
{
|
||||
"client_id": "461441632355-dc85s9u8dctltfbounegv020qn5aj49d.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAB3uaasLqLgB-Ir5NvzUkVo6wSuQPQtTU"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": [
|
||||
{
|
||||
"client_id": "461441632355-dc85s9u8dctltfbounegv020qn5aj49d.apps.googleusercontent.com",
|
||||
"client_type": 3
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import com.example.data.model.OSUpdateHistory
|
||||
|
||||
@Database(
|
||||
entities = [MaintenanceActivity::class, OSUpdateHistory::class],
|
||||
version = 1,
|
||||
version = 2,
|
||||
exportSchema = false
|
||||
)
|
||||
abstract class AppDatabase : RoomDatabase() {
|
||||
|
||||
@@ -45,9 +45,17 @@ data class OSUpdateHistory(
|
||||
val percentualNovo: Int,
|
||||
val observacao: String? = null,
|
||||
val fotoPath: String? = null,
|
||||
val recurso: String
|
||||
val recurso: String,
|
||||
val emailEditor: String? = null
|
||||
)
|
||||
|
||||
data class GoogleUser(
|
||||
val email: String,
|
||||
val displayName: String,
|
||||
val photoUrl: String? = null
|
||||
)
|
||||
|
||||
|
||||
fun extractDateOnly(dataStr: String): String {
|
||||
val clean = dataStr.trim()
|
||||
if (clean == "N/A" || clean.isBlank()) return "N/A"
|
||||
|
||||
@@ -478,11 +478,11 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
*/
|
||||
fun fetchRemoteHistoryKeys(): Set<String> {
|
||||
val defaultHeaders = listOf(
|
||||
"id", "numeroOs", "timestamp", "percentualAnterior", "percentualNovo", "observacao", "fotoPath", "responsavel"
|
||||
"id", "numeroOs", "timestamp", "percentualAnterior", "percentualNovo", "observacao", "fotoPath", "responsavel", "email_editor"
|
||||
)
|
||||
ensureHeaders("history", defaultHeaders)
|
||||
|
||||
val rows = fetchValues("history!A:H")
|
||||
val rows = fetchValues("history!A:I")
|
||||
val keys = mutableSetOf<String>()
|
||||
if (rows.size <= 1) return keys
|
||||
|
||||
@@ -511,11 +511,11 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
*/
|
||||
fun fetchRemoteHistoryList(): List<OSUpdateHistory> {
|
||||
val defaultHeaders = listOf(
|
||||
"id", "numeroOs", "timestamp", "percentualAnterior", "percentualNovo", "observacao", "fotoPath", "responsavel"
|
||||
"id", "numeroOs", "timestamp", "percentualAnterior", "percentualNovo", "observacao", "fotoPath", "responsavel", "email_editor"
|
||||
)
|
||||
ensureHeaders("history", defaultHeaders)
|
||||
|
||||
val rows = fetchValues("history!A:H")
|
||||
val rows = fetchValues("history!A:I")
|
||||
val historyList = mutableListOf<OSUpdateHistory>()
|
||||
if (rows.size <= 1) return historyList
|
||||
|
||||
@@ -528,6 +528,7 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
val obsIdx = headers.indexOf("observacao")
|
||||
val fotoIdx = headers.indexOf("fotopath")
|
||||
val respIdx = headers.indexOf("responsavel")
|
||||
val emailIdx = headers.indexOf("email_editor")
|
||||
|
||||
val getCell = { row: List<String>, mapIdx: Int, fallbackIdx: Int ->
|
||||
val idx = if (mapIdx != -1) mapIdx else fallbackIdx
|
||||
@@ -550,6 +551,7 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
val obs = getCell(row, obsIdx, 5).takeIf { it.isNotBlank() }
|
||||
val foto = getCell(row, fotoIdx, 6).takeIf { it.isNotBlank() }
|
||||
val resp = getCell(row, respIdx, 7)
|
||||
val email = getCell(row, emailIdx, 8)
|
||||
|
||||
historyList.add(
|
||||
OSUpdateHistory(
|
||||
@@ -560,7 +562,8 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
percentualNovo = new,
|
||||
observacao = obs,
|
||||
fotoPath = foto,
|
||||
recurso = resp
|
||||
recurso = resp,
|
||||
emailEditor = email.takeIf { it.isNotBlank() }
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -582,13 +585,32 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
*/
|
||||
fun pushHistoryToSheet(historyToAppend: List<OSUpdateHistory>) {
|
||||
if (historyToAppend.isEmpty()) return
|
||||
val defaultHeaders = listOf(
|
||||
"id", "numeroOs", "timestamp", "percentualAnterior", "percentualNovo", "observacao", "fotoPath", "responsavel", "email_editor"
|
||||
)
|
||||
ensureHeaders("history", defaultHeaders)
|
||||
|
||||
// Self-heal/add the header row to column I if not present on Google Sheets yet
|
||||
try {
|
||||
val firstRow = fetchValues("history!A1:I1")
|
||||
if (firstRow.isNotEmpty()) {
|
||||
val headers = firstRow[0].map { it.trim().lowercase() }
|
||||
if ("email_editor" !in headers) {
|
||||
updateValues("history!I1", listOf(listOf("email_editor")))
|
||||
Log.d(tag, "Self-healed 'email_editor' column header in remote sheet.")
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(tag, "Failed to self-heal 'email_editor' header in remote sheet.", e)
|
||||
}
|
||||
|
||||
val headerIndices = mapOf(
|
||||
"id" to 0, "numeroos" to 1, "timestamp" to 2, "percentualanterior" to 3, "percentualnovo" to 4,
|
||||
"observacao" to 5, "fotopath" to 6, "responsavel" to 7
|
||||
"observacao" to 5, "fotopath" to 6, "responsavel" to 7, "email_editor" to 8
|
||||
)
|
||||
|
||||
val appendRows = historyToAppend.map { history ->
|
||||
val row = MutableList(8) { "" }
|
||||
val row = MutableList(9) { "" }
|
||||
row[headerIndices["id"] ?: 0] = history.id.toString()
|
||||
row[headerIndices["numeroos"] ?: 1] = history.numeroOs
|
||||
row[headerIndices["timestamp"] ?: 2] = history.timestamp.toString()
|
||||
@@ -597,10 +619,11 @@ class GoogleSheetsSyncService(private val context: Context) {
|
||||
row[headerIndices["observacao"] ?: 5] = history.observacao ?: ""
|
||||
row[headerIndices["fotopath"] ?: 6] = history.fotoPath ?: ""
|
||||
row[headerIndices["responsavel"] ?: 7] = history.recurso
|
||||
row[headerIndices["email_editor"] ?: 8] = history.emailEditor ?: ""
|
||||
row
|
||||
}
|
||||
|
||||
appendValues("history!A:H", appendRows)
|
||||
appendValues("history!A:I", appendRows)
|
||||
Log.d(tag, "Successfully appended ${historyToAppend.size} logs to 'history' sheet.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.net.Uri
|
||||
import com.example.data.local.MaintenanceDao
|
||||
import com.example.data.model.MaintenanceActivity
|
||||
import com.example.data.model.OSUpdateHistory
|
||||
import com.example.data.model.GoogleUser
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
@@ -33,7 +34,8 @@ class MaintenanceRepository(
|
||||
novoPercentual: Int,
|
||||
observacao: String?,
|
||||
fotoPath: String?,
|
||||
recurso: String
|
||||
recurso: String,
|
||||
emailEditor: String?
|
||||
) = withContext(Dispatchers.IO) {
|
||||
val currentActivity = dao.getActivityByOsOneShot(numeroOs) ?: return@withContext
|
||||
|
||||
@@ -54,11 +56,33 @@ class MaintenanceRepository(
|
||||
percentualNovo = novoPercentual,
|
||||
observacao = observacao,
|
||||
fotoPath = fotoPath,
|
||||
recurso = recurso
|
||||
recurso = recurso,
|
||||
emailEditor = emailEditor
|
||||
)
|
||||
dao.insertHistory(historyEntry)
|
||||
}
|
||||
|
||||
// Persist login state
|
||||
fun getSavedUser(): GoogleUser? {
|
||||
val prefs = context.getSharedPreferences("google_auth_prefs", Context.MODE_PRIVATE)
|
||||
val email = prefs.getString("user_email", null) ?: return null
|
||||
val name = prefs.getString("user_name", "") ?: ""
|
||||
return GoogleUser(email, name)
|
||||
}
|
||||
|
||||
fun saveUser(user: GoogleUser) {
|
||||
val prefs = context.getSharedPreferences("google_auth_prefs", Context.MODE_PRIVATE)
|
||||
prefs.edit()
|
||||
.putString("user_email", user.email)
|
||||
.putString("user_name", user.displayName)
|
||||
.apply()
|
||||
}
|
||||
|
||||
fun clearSavedUser() {
|
||||
val prefs = context.getSharedPreferences("google_auth_prefs", Context.MODE_PRIVATE)
|
||||
prefs.edit().clear().apply()
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses an Excel CSV file from a Uri, supporting comma (,) or semicolon (;) separators,
|
||||
* Portuguese headers, and auto-mapping columns.
|
||||
@@ -178,6 +202,7 @@ class MaintenanceRepository(
|
||||
percentualNovo = activity.percentualExecucao,
|
||||
observacao = activity.observacoes,
|
||||
recurso = activity.recurso,
|
||||
emailEditor = "admin@cargill.com",
|
||||
timestamp = now - 3600000 // 1 hour ago
|
||||
)
|
||||
)
|
||||
|
||||
@@ -6,8 +6,13 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.core.*
|
||||
import androidx.compose.foundation.BorderStroke
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import kotlinx.coroutines.delay
|
||||
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 androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
@@ -76,10 +81,50 @@ fun MaintenanceDashboardScreen(
|
||||
val internetAvailable by viewModel.internetAvailable.collectAsStateWithLifecycle()
|
||||
val selectedActivity by viewModel.selectedActivity.collectAsStateWithLifecycle()
|
||||
val selectedActivityHistory by viewModel.selectedActivityHistory.collectAsStateWithLifecycle()
|
||||
val currentUser by viewModel.currentUser.collectAsStateWithLifecycle()
|
||||
|
||||
var showEditSheet by remember { mutableStateOf(false) }
|
||||
var showImporterSheet by remember { mutableStateOf(false) }
|
||||
var isListExpanded by remember { mutableStateOf(false) }
|
||||
var showProfileDropdown by remember { mutableStateOf(false) }
|
||||
|
||||
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()
|
||||
} else {
|
||||
Toast.makeText(context, "Erro ao obter dados da conta Google.", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
} catch (e: ApiException) {
|
||||
val statusCode = e.statusCode
|
||||
android.util.Log.e("GoogleSignIn", "Sign-in failed: status code = $statusCode", e)
|
||||
Toast.makeText(context, "Falha no Google Sign-In (Erro $statusCode). Verifique a console de credenciais do Google.", Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
|
||||
LaunchedEffect(Unit) {
|
||||
val lastAccount = GoogleSignIn.getLastSignedInAccount(context)
|
||||
if (lastAccount != null) {
|
||||
val email = lastAccount.email ?: ""
|
||||
val name = lastAccount.displayName ?: ""
|
||||
viewModel.loginUser(email, name)
|
||||
}
|
||||
}
|
||||
|
||||
val uniqueDates = remember(allActivities) {
|
||||
val datesOnly = allActivities
|
||||
@@ -215,6 +260,108 @@ fun MaintenanceDashboardScreen(
|
||||
modifier = Modifier.rotate(if (isSyncing) angle else 0f)
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
|
||||
if (currentUser == null) {
|
||||
Button(
|
||||
onClick = { googleSignInLauncher.launch(googleSignInClient.signInIntent) },
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
containerColor = Color.White,
|
||||
contentColor = Color(0xFF3C4043)
|
||||
),
|
||||
elevation = ButtonDefaults.buttonElevation(defaultElevation = 1.dp),
|
||||
shape = RoundedCornerShape(20.dp),
|
||||
contentPadding = PaddingValues(horizontal = 12.dp, vertical = 6.dp),
|
||||
border = BorderStroke(1.dp, Color(0xFFDADCE0)),
|
||||
modifier = Modifier
|
||||
.height(36.dp)
|
||||
.testTag("google_login_button")
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
GoogleIcon()
|
||||
Text(
|
||||
text = "Entrar",
|
||||
fontSize = 13.sp,
|
||||
fontWeight = FontWeight.Medium
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Box {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clip(RoundedCornerShape(20.dp))
|
||||
.background(Color(0xFFF1F3F4))
|
||||
.clickable { showProfileDropdown = true }
|
||||
.padding(horizontal = 8.dp, vertical = 4.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(24.dp)
|
||||
.clip(CircleShape)
|
||||
.background(CargillGreen),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
Text(
|
||||
text = (currentUser!!.displayName.firstOrNull() ?: 'U').uppercaseChar().toString(),
|
||||
color = Color.White,
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 11.sp
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Column {
|
||||
Text(
|
||||
text = currentUser!!.displayName.substringBefore(" "),
|
||||
fontSize = 10.sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = CargillBlack
|
||||
)
|
||||
Text(
|
||||
text = currentUser!!.email,
|
||||
fontSize = 8.sp,
|
||||
color = StatusGrey
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.width(2.dp))
|
||||
Icon(
|
||||
imageVector = Icons.Default.ArrowDropDown,
|
||||
contentDescription = "Menu de Usuário",
|
||||
tint = CargillBlack,
|
||||
modifier = Modifier.size(16.dp)
|
||||
)
|
||||
}
|
||||
|
||||
DropdownMenu(
|
||||
expanded = showProfileDropdown,
|
||||
onDismissRequest = { showProfileDropdown = false },
|
||||
modifier = Modifier.background(Color.White)
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text("Desconectar do Google", color = Color.Red) },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = Icons.Default.ExitToApp,
|
||||
contentDescription = "Desconectar",
|
||||
tint = Color.Red
|
||||
)
|
||||
},
|
||||
onClick = {
|
||||
showProfileDropdown = false
|
||||
googleSignInClient.signOut().addOnCompleteListener {
|
||||
viewModel.logoutUser()
|
||||
Toast.makeText(context, "Sessão encerrada", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = Color.White
|
||||
@@ -394,6 +541,7 @@ fun MaintenanceDashboardScreen(
|
||||
EditActivityBottomSheet(
|
||||
activity = selectedActivity!!,
|
||||
history = selectedActivityHistory,
|
||||
currentUser = currentUser,
|
||||
onDismiss = {
|
||||
showEditSheet = false
|
||||
viewModel.selectActivity(null)
|
||||
@@ -404,12 +552,18 @@ fun MaintenanceDashboardScreen(
|
||||
novoPercentual = newPct,
|
||||
observacao = comment,
|
||||
fotoPath = mockPhoto,
|
||||
recurso = "Encarregado Campo"
|
||||
recurso = currentUser?.displayName ?: "Encarregado Campo",
|
||||
emailEditor = currentUser?.email
|
||||
)
|
||||
},
|
||||
onGoogleLoginClick = {
|
||||
googleSignInLauncher.launch(googleSignInClient.signInIntent)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
|
||||
// CSV Importer Utility Sheet
|
||||
if (showImporterSheet) {
|
||||
ImporterConsoleSheet(
|
||||
@@ -880,8 +1034,10 @@ fun OSListItemCard(
|
||||
fun EditActivityBottomSheet(
|
||||
activity: MaintenanceActivity,
|
||||
history: List<OSUpdateHistory>,
|
||||
currentUser: com.example.data.model.GoogleUser?,
|
||||
onDismiss: () -> Unit,
|
||||
onUpdateProgress: (Int, String, String?) -> Unit
|
||||
onUpdateProgress: (Int, String, String?) -> Unit,
|
||||
onGoogleLoginClick: () -> Unit
|
||||
) {
|
||||
ModalBottomSheet(
|
||||
onDismissRequest = onDismiss,
|
||||
@@ -985,7 +1141,8 @@ fun EditActivityBottomSheet(
|
||||
colors = SliderDefaults.colors(
|
||||
thumbColor = if (progressValue >= 100) CargillGreen else StatusBlue,
|
||||
activeTrackColor = if (progressValue >= 100) CargillGreen else StatusBlue
|
||||
)
|
||||
),
|
||||
enabled = currentUser != null
|
||||
)
|
||||
|
||||
// Quick jump buttons for field speed
|
||||
@@ -997,7 +1154,8 @@ fun EditActivityBottomSheet(
|
||||
onClick = { progressValue = 0f },
|
||||
modifier = Modifier.weight(1f).height(36.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFFECEFF1)),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
enabled = currentUser != null
|
||||
) {
|
||||
Text("0% (Zerar)", color = StatusGrey, fontSize = 11.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
@@ -1005,7 +1163,8 @@ fun EditActivityBottomSheet(
|
||||
onClick = { progressValue = 50f },
|
||||
modifier = Modifier.weight(1f).height(36.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFFE3F2FD)),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
enabled = currentUser != null
|
||||
) {
|
||||
Text("50% (Metade)", color = StatusBlue, fontSize = 11.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
@@ -1013,7 +1172,8 @@ fun EditActivityBottomSheet(
|
||||
onClick = { progressValue = 100f },
|
||||
modifier = Modifier.weight(1f).height(36.dp),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFFE8F5E9)),
|
||||
contentPadding = PaddingValues(0.dp)
|
||||
contentPadding = PaddingValues(0.dp),
|
||||
enabled = currentUser != null
|
||||
) {
|
||||
Text("100% (Concluir)", color = CargillGreen, fontSize = 11.sp, fontWeight = FontWeight.Bold)
|
||||
}
|
||||
@@ -1037,7 +1197,8 @@ fun EditActivityBottomSheet(
|
||||
.height(80.dp)
|
||||
.testTag("os_notes_field"),
|
||||
maxLines = 3,
|
||||
shape = RoundedCornerShape(8.dp)
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
enabled = currentUser != null
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1062,7 +1223,7 @@ fun EditActivityBottomSheet(
|
||||
items(mockPhotos) { (label, mockName) ->
|
||||
val isSelected = selectedMockPhotoPath == mockName
|
||||
Surface(
|
||||
onClick = { selectedMockPhotoPath = if (isSelected) null else mockName },
|
||||
onClick = { if (currentUser != null) selectedMockPhotoPath = if (isSelected) null else mockName },
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
color = if (isSelected) Color(0xFFE8F5E9) else Color(0xFFF5F5F5),
|
||||
border = BorderStroke(1.dp, if (isSelected) CargillGreen else Color(0xFFE0E0E0)),
|
||||
@@ -1116,23 +1277,72 @@ fun EditActivityBottomSheet(
|
||||
}
|
||||
}
|
||||
|
||||
// Save Action Button
|
||||
Button(
|
||||
onClick = {
|
||||
isSubmitting = true
|
||||
onUpdateProgress(progressValue.toInt(), observationText, selectedMockPhotoPath)
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
.testTag("save_progress_button"),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = CargillGreen),
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
) {
|
||||
Icon(Icons.Default.Save, contentDescription = "Salvar")
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Text("Salvar Atualizações (Salva Local Offline)", fontWeight = FontWeight.Black)
|
||||
// Save Action Button or Google Login Warning Banner
|
||||
if (currentUser == null) {
|
||||
Card(
|
||||
colors = CardDefaults.cardColors(containerColor = Color(0xFFFCE8E6)),
|
||||
border = BorderStroke(1.dp, Color(0xFFFAD2CF)),
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier.padding(12.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.Lock,
|
||||
contentDescription = "Acesso Restrito",
|
||||
tint = Color(0xFFC5221F),
|
||||
modifier = Modifier.size(24.dp)
|
||||
)
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = "Acesso Restrito",
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 13.sp,
|
||||
color = Color(0xFFC5221F)
|
||||
)
|
||||
Text(
|
||||
text = "Você precisa fazer login com sua conta do Google para atualizar o progresso de qualquer OS.",
|
||||
fontSize = 11.sp,
|
||||
color = Color(0xFFC5221F)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button(
|
||||
onClick = onGoogleLoginClick,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
.testTag("save_progress_button_disabled"),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = Color(0xFF4285F4)),
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
) {
|
||||
GoogleIcon(modifier = Modifier.size(18.dp))
|
||||
Spacer(modifier = Modifier.width(8.dp))
|
||||
Text("Conectar com o Google", fontWeight = FontWeight.Bold, color = Color.White)
|
||||
}
|
||||
} else {
|
||||
Button(
|
||||
onClick = {
|
||||
isSubmitting = true
|
||||
onUpdateProgress(progressValue.toInt(), observationText, selectedMockPhotoPath)
|
||||
onDismiss()
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(48.dp)
|
||||
.testTag("save_progress_button"),
|
||||
colors = ButtonDefaults.buttonColors(containerColor = CargillGreen),
|
||||
shape = RoundedCornerShape(10.dp)
|
||||
) {
|
||||
Icon(Icons.Default.Save, contentDescription = "Salvar")
|
||||
Spacer(modifier = Modifier.width(6.dp))
|
||||
Text("Salvar Atualizações (Salva Local Offline)", fontWeight = FontWeight.Black)
|
||||
}
|
||||
}
|
||||
|
||||
// Chronological Audit Timeline Log / History Section
|
||||
@@ -1385,3 +1595,56 @@ fun ImporterConsoleSheet(
|
||||
// Extension to allow custom vertical scrolling on the BottomSheet contents
|
||||
@Composable
|
||||
fun rememberScrollState() = androidx.compose.foundation.rememberScrollState()
|
||||
|
||||
|
||||
|
||||
@Composable
|
||||
fun GoogleIcon(modifier: Modifier = Modifier.size(16.dp)) {
|
||||
androidx.compose.foundation.Canvas(modifier = modifier) {
|
||||
val sizePx = size.minDimension
|
||||
val strokeWidth = sizePx * 0.18f
|
||||
val r = sizePx / 2
|
||||
|
||||
val blue = Color(0xFF4285F4)
|
||||
val green = Color(0xFF34A853)
|
||||
val yellow = Color(0xFFFBBC05)
|
||||
val red = Color(0xFFEA4335)
|
||||
|
||||
drawArc(
|
||||
color = red,
|
||||
startAngle = 180f,
|
||||
sweepAngle = 140f,
|
||||
useCenter = false,
|
||||
style = androidx.compose.ui.graphics.drawscope.Stroke(width = strokeWidth)
|
||||
)
|
||||
drawArc(
|
||||
color = yellow,
|
||||
startAngle = 140f,
|
||||
sweepAngle = 40f,
|
||||
useCenter = false,
|
||||
style = androidx.compose.ui.graphics.drawscope.Stroke(width = strokeWidth)
|
||||
)
|
||||
drawArc(
|
||||
color = green,
|
||||
startAngle = 0f,
|
||||
sweepAngle = 140f,
|
||||
useCenter = false,
|
||||
style = androidx.compose.ui.graphics.drawscope.Stroke(width = strokeWidth)
|
||||
)
|
||||
drawArc(
|
||||
color = blue,
|
||||
startAngle = 320f,
|
||||
sweepAngle = 40f,
|
||||
useCenter = false,
|
||||
style = androidx.compose.ui.graphics.drawscope.Stroke(width = strokeWidth)
|
||||
)
|
||||
|
||||
val barLength = r * 0.9f
|
||||
drawLine(
|
||||
color = blue,
|
||||
start = center,
|
||||
end = center.copy(x = center.x + barLength),
|
||||
strokeWidth = strokeWidth
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,10 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
private val _searchQuery = MutableStateFlow("")
|
||||
val searchQuery = _searchQuery.asStateFlow()
|
||||
|
||||
// Google User authentication state
|
||||
private val _currentUser = MutableStateFlow<com.example.data.model.GoogleUser?>(null)
|
||||
val currentUser = _currentUser.asStateFlow()
|
||||
|
||||
// UI Operation States
|
||||
private val _isSyncing = MutableStateFlow(false)
|
||||
val isSyncing = _isSyncing.asStateFlow()
|
||||
@@ -145,6 +149,7 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
)
|
||||
|
||||
init {
|
||||
_currentUser.value = repository.getSavedUser()
|
||||
// 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()
|
||||
@@ -263,6 +268,17 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
}
|
||||
}
|
||||
|
||||
fun loginUser(email: String, displayName: String) {
|
||||
val user = com.example.data.model.GoogleUser(email, displayName)
|
||||
repository.saveUser(user)
|
||||
_currentUser.value = user
|
||||
}
|
||||
|
||||
fun logoutUser() {
|
||||
repository.clearSavedUser()
|
||||
_currentUser.value = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Submits progress updates and creates log.
|
||||
*/
|
||||
@@ -271,10 +287,11 @@ class MaintenanceViewModel(private val repository: MaintenanceRepository) : View
|
||||
novoPercentual: Int,
|
||||
observacao: String?,
|
||||
fotoPath: String?,
|
||||
recurso: String
|
||||
recurso: String,
|
||||
emailEditor: String?
|
||||
) {
|
||||
viewModelScope.launch {
|
||||
repository.updateProgress(numeroOs, novoPercentual, observacao, fotoPath, recurso)
|
||||
repository.updateProgress(numeroOs, novoPercentual, observacao, fotoPath, recurso, emailEditor)
|
||||
// Update selected activity model in state to refresh UI
|
||||
_selectedActivity.value?.let { active ->
|
||||
if (active.numeroOs == numeroOs) {
|
||||
|
||||
@@ -40,6 +40,7 @@ firebaseBom = "34.15.0"
|
||||
secretsGradlePlugin = "2.0.1"
|
||||
googleServices = "4.5.0"
|
||||
googleAuth = "1.19.0"
|
||||
playServicesAuth = "21.2.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
@@ -91,6 +92,7 @@ firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.r
|
||||
firebase-ai = { group = "com.google.firebase", name = "firebase-ai" }
|
||||
firebase-appcheck-recaptcha = { group = "com.google.firebase", name = "firebase-appcheck-recaptcha" }
|
||||
google-auth-library-oauth2-http = { group = "com.google.auth", name = "google-auth-library-oauth2-http", version.ref = "googleAuth" }
|
||||
play-services-auth = { group = "com.google.android.gms", name = "play-services-auth", version.ref = "playServicesAuth" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
||||
Reference in New Issue
Block a user