feat: implement meal notification system

Add necessary permissions, services, and receivers to support scheduled meal notifications and boot completion handling. Also includes dependency updates and minor test fixes.
This commit is contained in:
bleackstorm committed 2026-11-08 16:57:11 +01:00
1 parent f13d46f778
commit fe69d7621a
31 files changed
+2972 -350

No files matched your search

@@ -0,0 +1,66 @@
package com.example.util
import android.accounts.Account
import android.content.Context
import com.example.R
import com.google.android.gms.auth.GoogleAuthUtil
import com.google.android.gms.auth.UserRecoverableAuthException
import com.google.android.gms.auth.api.signin.GoogleSignIn
import com.google.android.gms.auth.api.signin.GoogleSignInClient
import com.google.android.gms.auth.api.signin.GoogleSignInOptions
import com.google.android.gms.common.api.Scope
import com.google.firebase.Firebase
import com.google.firebase.auth.auth
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
object GoogleSheetsAuthHelper {
const val SCOPE_SPREADSHEETS_URL = "https://www.googleapis.com/auth/spreadsheets"
const val SCOPE_DRIVE_FILE_URL = "https://www.googleapis.com/auth/drive.file"
val SCOPE_SPREADSHEETS = Scope(SCOPE_SPREADSHEETS_URL)
val SCOPE_DRIVE_FILE = Scope(SCOPE_DRIVE_FILE_URL)
const val OAUTH_SCOPE_STRING = "oauth2:$SCOPE_SPREADSHEETS_URL $SCOPE_DRIVE_FILE_URL"
fun getGoogleSignInClient(context: Context): GoogleSignInClient {
val serverClientId = try {
context.getString(R.string.default_web_client_id)
} catch (_: Exception) {
null
}
val gsoBuilder = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestScopes(SCOPE_SPREADSHEETS, SCOPE_DRIVE_FILE)
if (!serverClientId.isNullOrBlank()) {
gsoBuilder.requestIdToken(serverClientId)
}
return GoogleSignIn.getClient(context, gsoBuilder.build())
}
suspend fun getAccessToken(context: Context): Result<String> = withContext(Dispatchers.IO) {
try {
val email = Firebase.auth.currentUser?.email
?: GoogleSignIn.getLastSignedInAccount(context)?.email
if (email.isNullOrBlank()) {
return@withContext Result.failure(
IllegalStateException("Aucun compte Google connecté. Veuillez vous connecter pour synchroniser avec Google Sheets.")
)
}
val account = Account(email, "com.google")
val token = GoogleAuthUtil.getToken(context, account, OAUTH_SCOPE_STRING)
Result.success(token)
} catch (e: UserRecoverableAuthException) {
// Must be handled by prompting user via e.intent
Result.failure(e)
} catch (e: Exception) {
Result.failure(e)
}
}
}