feat: implement incremental database synchronization and add scroll state persistence to MaintenanceDashboardScreen
This commit is contained in:
@@ -52,6 +52,9 @@ interface MaintenanceDao {
|
||||
@Query("DELETE FROM maintenance_activities")
|
||||
suspend fun clearAllActivities()
|
||||
|
||||
@androidx.room.Delete
|
||||
suspend fun deleteActivities(activities: List<MaintenanceActivity>)
|
||||
|
||||
@Query("DELETE FROM os_update_history")
|
||||
suspend fun clearAllHistory()
|
||||
|
||||
|
||||
@@ -258,10 +258,15 @@ class MaintenanceRepository(
|
||||
}
|
||||
}
|
||||
|
||||
// 7. Save updated OS activities to local Room DB
|
||||
// 7. Save updated OS activities to local Room DB incrementally (preserves UI list state)
|
||||
if (reconciledActivities.isNotEmpty()) {
|
||||
dao.clearAllActivities() // Clear old ones since project sheet is the unique source of truth
|
||||
dao.insertActivities(reconciledActivities)
|
||||
val remoteOsSet = reconciledActivities.map { it.numeroOs }.toSet()
|
||||
val localActivities = dao.getAllActivitiesList()
|
||||
val staleActivities = localActivities.filter { it.numeroOs !in remoteOsSet }
|
||||
if (staleActivities.isNotEmpty()) {
|
||||
dao.deleteActivities(staleActivities)
|
||||
}
|
||||
android.util.Log.d("MaintenanceRepository", "Reconciled and saved ${reconciledActivities.size} OS activities from Google Sheet.")
|
||||
}
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
@@ -102,6 +103,8 @@ fun MaintenanceDashboardScreen(
|
||||
var showProfileDropdown by remember { mutableStateOf(false) }
|
||||
var showAdvancedFilters by remember { mutableStateOf(false) }
|
||||
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
val pendingCount = remember(allActivities) {
|
||||
allActivities.count { it.status != ActivityStatus.CONCLUIDO }
|
||||
}
|
||||
@@ -562,6 +565,7 @@ fun MaintenanceDashboardScreen(
|
||||
}
|
||||
} else {
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.fillMaxWidth(),
|
||||
|
||||
Reference in New Issue
Block a user