feat: support meal photo URIs and improve UI events

- Add `photoUris` field to `MealEntry` and update Firestore rules.
- Implement `UiEvent` handling in `MainActivity` for navigation/links.
- Remove sensitive email data from error logs and clean up manifest.
This commit is contained in:
bleackstorm committed 2026-11-08 19:25:03 +01:00
1 parent f0487453c9
commit 87bbb448c2
34 files changed
+2026 -1170

No files matched your search

@@ -0,0 +1,87 @@
package com.example.domain
import android.content.Context
import android.content.Intent
import com.example.data.model.MealEntry
import com.example.data.preferences.GoogleSheetsPreferencesManager
import com.example.data.repository.MealRepository
import com.example.util.GoogleSheetsAuthHelper
import com.example.util.GoogleSheetsSyncResult
import com.example.util.GoogleSheetsSyncService
import com.google.android.gms.auth.UserRecoverableAuthException
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
sealed interface SheetsSyncResult {
data class Success(val url: String, val count: Int, val timestamp: Long) : SheetsSyncResult
data class RecoverableAuth(val message: String, val intent: Intent?) : SheetsSyncResult
data class Failure(val message: String) : SheetsSyncResult
}
class GoogleSheetsSyncUseCase(
private val context: Context,
private val repository: MealRepository,
private val sheetsPrefs: GoogleSheetsPreferencesManager
) {
suspend fun execute(): SheetsSyncResult = withContext(Dispatchers.IO) {
val tokenResult = GoogleSheetsAuthHelper.getAccessToken(context)
if (tokenResult.isFailure) {
val exception = tokenResult.exceptionOrNull()
return@withContext if (exception is UserRecoverableAuthException) {
SheetsSyncResult.RecoverableAuth(
message = "Autorisation requise pour Google Sheets & Drive",
intent = exception.intent
)
} else {
SheetsSyncResult.Failure(exception?.localizedMessage ?: "Impossible d'obtenir l'autorisation Google")
}
}
val token = tokenResult.getOrThrow()
val spreadsheetResult = GoogleSheetsSyncService.getOrCreateSpreadsheet(token, sheetsPrefs.spreadsheetId)
if (spreadsheetResult.isFailure) {
val err = spreadsheetResult.exceptionOrNull()?.localizedMessage ?: "Erreur de création du classeur"
return@withContext SheetsSyncResult.Failure(err)
}
val (id, url) = spreadsheetResult.getOrThrow()
sheetsPrefs.spreadsheetId = id
sheetsPrefs.spreadsheetUrl = url
val currentMeals = repository.getAllMealsSnapshot()
val syncResult = GoogleSheetsSyncService.syncMeals(token, id, currentMeals)
if (syncResult.isSuccess) {
val res = syncResult.getOrThrow()
sheetsPrefs.lastSyncTimestamp = res.timestamp
sheetsPrefs.lastSyncCount = res.mealsCount
sheetsPrefs.lastSyncStatus = "Synchronisé avec succès"
SheetsSyncResult.Success(res.spreadsheetUrl, res.mealsCount, res.timestamp)
} else {
val err = syncResult.exceptionOrNull()?.localizedMessage ?: "Erreur lors de la synchronisation des repas"
SheetsSyncResult.Failure(err)
}
}
suspend fun executeAutoSyncQuietly(): GoogleSheetsSyncResult? = withContext(Dispatchers.IO) {
if (!sheetsPrefs.isAutoSyncEnabled) return@withContext null
try {
val token = GoogleSheetsAuthHelper.getAccessToken(context).getOrNull() ?: return@withContext null
val (id, url) = GoogleSheetsSyncService.getOrCreateSpreadsheet(token, sheetsPrefs.spreadsheetId).getOrNull() ?: return@withContext null
sheetsPrefs.spreadsheetId = id
sheetsPrefs.spreadsheetUrl = url
val currentMeals = repository.getAllMealsSnapshot()
val syncResult = GoogleSheetsSyncService.syncMeals(token, id, currentMeals)
if (syncResult.isSuccess) {
val res = syncResult.getOrThrow()
sheetsPrefs.lastSyncTimestamp = res.timestamp
sheetsPrefs.lastSyncCount = res.mealsCount
sheetsPrefs.lastSyncStatus = "Synchronisé automatiquement"
res
} else null
} catch (_: Exception) {
null
}
}
}