commit 06ef90be69ac7aa0726218c4e7f5d8d8dd37189e Author: Marc-André Date: Fri Feb 20 17:21:50 2026 -0500 mac diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..7643783 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,123 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..2173449 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..02c4aa5 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..f0c6ad0 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,50 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..8d404a6 --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,83 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.compose) + alias(libs.plugins.ksp) + alias(libs.plugins.secrets) +} + +android { + namespace = "com.example.coloricam" + compileSdk = 35 + + defaultConfig { + applicationId = "com.example.coloricam" + minSdk = 24 + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + buildFeatures { + compose = true + buildConfig = true + } +} + +secrets { + // A list of keys that should be ignored by the plugin by default. + ignoreList.add("properties") +} + +dependencies { + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.graphics) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.material3) + implementation(libs.google.generativeai) + implementation(libs.coil.compose) + implementation(libs.androidx.exifinterface) + + // Navigation + implementation(libs.androidx.navigation.compose) + + // Room + implementation(libs.androidx.room.runtime) + implementation(libs.androidx.room.ktx) + ksp(libs.androidx.room.compiler) + + // Network & Strava Auth + implementation(libs.retrofit.core) + implementation(libs.retrofit.gson) + implementation(libs.okhttp.logging) + implementation(libs.androidx.browser) + + // Google Sign-In + implementation(libs.play.services.auth) + + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.tooling) + debugImplementation(libs.androidx.compose.ui.test.manifest) +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/release/app-release.apk b/app/release/app-release.apk new file mode 100644 index 0000000..7d9350a Binary files /dev/null and b/app/release/app-release.apk differ diff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dm new file mode 100644 index 0000000..d5295c6 Binary files /dev/null and b/app/release/baselineProfiles/0/app-release.dm differ diff --git a/app/release/baselineProfiles/1/app-release.dm b/app/release/baselineProfiles/1/app-release.dm new file mode 100644 index 0000000..63650e7 Binary files /dev/null and b/app/release/baselineProfiles/1/app-release.dm differ diff --git a/app/release/output-metadata.json b/app/release/output-metadata.json new file mode 100644 index 0000000..6b9a14a --- /dev/null +++ b/app/release/output-metadata.json @@ -0,0 +1,37 @@ +{ + "version": 3, + "artifactType": { + "type": "APK", + "kind": "Directory" + }, + "applicationId": "com.example.coloricam", + "variantName": "release", + "elements": [ + { + "type": "SINGLE", + "filters": [], + "attributes": [], + "versionCode": 1, + "versionName": "1.0", + "outputFile": "app-release.apk" + } + ], + "elementType": "File", + "baselineProfiles": [ + { + "minApi": 28, + "maxApi": 30, + "baselineProfiles": [ + "baselineProfiles/1/app-release.dm" + ] + }, + { + "minApi": 31, + "maxApi": 2147483647, + "baselineProfiles": [ + "baselineProfiles/0/app-release.dm" + ] + } + ], + "minSdkVersionForDexing": 24 +} \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/coloricam/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/coloricam/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..a1da6aa --- /dev/null +++ b/app/src/androidTest/java/com/example/coloricam/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.coloricam + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.coloricam", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..3d96b27 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/example/coloricam/Database.kt b/app/src/main/java/com/example/coloricam/Database.kt new file mode 100644 index 0000000..6e45f9d --- /dev/null +++ b/app/src/main/java/com/example/coloricam/Database.kt @@ -0,0 +1,64 @@ +package com.example.coloricam + +import android.content.Context +import androidx.room.* +import kotlinx.coroutines.flow.Flow + +@Entity(tableName = "meals") +data class Meal( + @PrimaryKey(autoGenerate = true) val id: Int = 0, + val date: Long, + val name: String = "Repas", + val analysisText: String, + val totalCalories: Int, + val type: String = "Collation" +) + +@Entity(tableName = "glycemia") +data class Glycemia( + @PrimaryKey(autoGenerate = true) val id: Int = 0, + val date: Long, + val value: Double, + val moment: String +) + +@Entity(tableName = "sports") +data class SportActivity( + @PrimaryKey val id: Long, + val name: String, + val type: String, + val distance: Float, + val movingTime: Int, + val calories: Float?, + val date: Long // timestamp +) + +@Dao +interface AppDao { + @Insert suspend fun insertMeal(meal: Meal): Long + @Delete suspend fun deleteMeal(meal: Meal) + @Query("SELECT * FROM meals ORDER BY date DESC") fun getAllMeals(): Flow> + + @Insert suspend fun insertGlycemia(glycemia: Glycemia): Long + @Delete suspend fun deleteGlycemia(glycemia: Glycemia) + @Query("SELECT * FROM glycemia ORDER BY date DESC") fun getAllGlycemia(): Flow> + + @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun insertSports(sports: List) + @Query("SELECT * FROM sports ORDER BY date DESC") fun getAllSports(): Flow> + @Query("SELECT * FROM sports WHERE date >= :startOfDay AND date < :endOfDay ORDER BY date DESC") + fun getSportsForDay(startOfDay: Long, endOfDay: Long): Flow> +} + +@Database(entities = [Meal::class, Glycemia::class, SportActivity::class], version = 5) +abstract class AppDatabase : RoomDatabase() { + abstract fun appDao(): AppDao + companion object { + @Volatile private var INSTANCE: AppDatabase? = null + fun getDatabase(context: Context): AppDatabase = + INSTANCE ?: synchronized(this) { + Room.databaseBuilder(context.applicationContext, AppDatabase::class.java, "app_db") + .fallbackToDestructiveMigration() + .build().also { INSTANCE = it } + } + } +} diff --git a/app/src/main/java/com/example/coloricam/MainActivity.kt b/app/src/main/java/com/example/coloricam/MainActivity.kt new file mode 100644 index 0000000..594735b --- /dev/null +++ b/app/src/main/java/com/example/coloricam/MainActivity.kt @@ -0,0 +1,381 @@ +package com.example.coloricam + +import android.Manifest +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.content.pm.PackageManager +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.net.Uri +import android.os.Bundle +import android.util.Base64 +import android.util.Log +import androidx.activity.ComponentActivity +import androidx.activity.compose.rememberLauncherForActivityResult +import androidx.activity.compose.setContent +import androidx.activity.result.contract.ActivityResultContracts +import androidx.browser.customtabs.CustomTabsIntent +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowLeft +import androidx.compose.material.icons.automirrored.filled.KeyboardArrowRight +import androidx.compose.material.icons.filled.* +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.asImageBitmap +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import androidx.core.content.ContextCompat +import androidx.exifinterface.media.ExifInterface +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.rememberNavController +import com.example.coloricam.ui.theme.ColoricamTheme +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 kotlinx.coroutines.launch +import okhttp3.OkHttpClient +import okhttp3.ResponseBody +import okhttp3.logging.HttpLoggingInterceptor +import retrofit2.Retrofit +import java.text.SimpleDateFormat +import java.util.* +import java.util.concurrent.TimeUnit +import retrofit2.converter.gson.GsonConverterFactory +import retrofit2.http.* +import java.io.ByteArrayOutputStream +import org.json.JSONObject +import org.json.JSONArray + +// --- API MODELS --- +data class N8nMealRequest( + val imageBase64: String?, + val mealName: String?, + val prompt: String +) + +interface N8nApi { + @POST("webhook/v1/gemini-proxy") + suspend fun analyzeMeal( + @Header("X-API-KEY") apiKey: String, + @Body request: N8nMealRequest + ): ResponseBody +} + +// --- STRAVA API --- +data class StravaActivity( + val id: Long, + val name: String, + val type: String, + val distance: Float, + val moving_time: Int, + val elapsed_time: Int, + val calories: Float?, + val start_date: String, + val start_date_local: String +) + +data class StravaTokenResponse( + val access_token: String, + val refresh_token: String, + val expires_at: Long +) + +interface StravaApi { + @GET("athlete/activities") + suspend fun getActivities( + @Header("Authorization") token: String, + @Query("before") before: Long? = null, + @Query("after") after: Long? = null, + @Query("page") page: Int? = null, + @Query("per_page") perPage: Int? = 30 + ): List + + @POST("oauth/token") + suspend fun exchangeToken( + @Query("client_id") clientId: String, + @Query("client_secret") clientSecret: String, + @Query("code") code: String, + @Query("grant_type") grantType: String = "authorization_code" + ): StravaTokenResponse + + @POST("oauth/token") + suspend fun refreshToken( + @Query("client_id") clientId: String, + @Query("client_secret") clientSecret: String, + @Query("refresh_token") refreshToken: String, + @Query("grant_type") grantType: String = "refresh_token" + ): StravaTokenResponse +} + +// Helpers +object ApiClient { + private val loggingInterceptor = HttpLoggingInterceptor().apply { + level = HttpLoggingInterceptor.Level.BODY + } + + private val okHttpClient = OkHttpClient.Builder() + .addInterceptor(loggingInterceptor) + .connectTimeout(60, TimeUnit.SECONDS) + .readTimeout(60, TimeUnit.SECONDS) + .writeTimeout(60, TimeUnit.SECONDS) + .build() + + private val retrofitStrava = Retrofit.Builder() + .baseUrl("https://www.strava.com/api/v3/") + .addConverterFactory(GsonConverterFactory.create()) + .build() + + private val retrofitN8n = Retrofit.Builder() + .baseUrl("https://n8n.marquis1987.com/") + .client(okHttpClient) + .addConverterFactory(GsonConverterFactory.create()) + .build() + + val stravaApi: StravaApi = retrofitStrava.create(StravaApi::class.java) + val n8nApi: N8nApi = retrofitN8n.create(N8nApi::class.java) + + suspend fun getValidStravaToken(prefs: SharedPreferences): String? { + val stravaToken = prefs.getString("strava_token", null) ?: return null + val expiresAt = prefs.getLong("strava_expires_at", 0) + val refreshToken = prefs.getString("strava_refresh_token", null) + val clientId = prefs.getString("strava_client_id", "") ?: "" + val clientSecret = prefs.getString("strava_client_secret", "") ?: "" + + val currentTime = System.currentTimeMillis() / 1000 + if (currentTime >= expiresAt && refreshToken != null && clientId.isNotBlank()) { + try { + val refreshResponse = stravaApi.refreshToken(clientId, clientSecret, refreshToken) + prefs.edit() + .putString("strava_token", refreshResponse.access_token) + .putString("strava_refresh_token", refreshResponse.refresh_token) + .putLong("strava_expires_at", refreshResponse.expires_at) + .apply() + return refreshResponse.access_token + } catch (e: Exception) { + return null + } + } + return stravaToken + } + + fun parseStravaDate(dateStr: String): Long { + return try { + val inputFormat = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US) + inputFormat.timeZone = TimeZone.getTimeZone("UTC") + inputFormat.parse(dateStr)?.time ?: 0L + } catch (e: Exception) { 0L } + } + + fun estimateCaloriesFromDb(activity: SportActivity, weightKg: Double): Int { + if (activity.calories != null && activity.calories > 0) return activity.calories.toInt() + val met = when (activity.type.lowercase()) { + "run" -> 10.0 + "ride" -> 8.0 + "walk" -> 3.5 + "hike" -> 6.0 + "swim" -> 7.0 + "weighttraining" -> 5.0 + "workout" -> 4.5 + else -> 5.0 + } + val durationHours = activity.movingTime / 3600.0 + return (met * weightKg * durationHours).toInt() + } +} + +// --- UI COMPONENTS --- + +class MainActivity : ComponentActivity() { + private lateinit var dao: AppDao + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + dao = AppDatabase.getDatabase(this).appDao() + handleStravaCallback(intent) + setContent { + ColoricamTheme { + AuthWrapper(dao) + } + } + } + + override fun onNewIntent(intent: Intent) { + super.onNewIntent(intent) + handleStravaCallback(intent) + } + + private fun handleStravaCallback(intent: Intent) { + val data: Uri? = intent.data + if (data != null && data.toString().startsWith("coloricam://localhost")) { + val code = data.getQueryParameter("code") + if (code != null) { + val prefs = getSharedPreferences("user_prefs", Context.MODE_PRIVATE) + prefs.edit().putString("strava_code", code).apply() + } + } + } +} + +@Composable +fun AuthWrapper(dao: AppDao) { + val context = LocalContext.current + val gso = remember { + GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) + .requestEmail() + .build() + } + val googleSignInClient = remember { GoogleSignIn.getClient(context, gso) } + var account by remember { mutableStateOf(GoogleSignIn.getLastSignedInAccount(context)) } + + // Whitelist + val allowedEmails = listOf("marcandre.charest@gmail.com") + + val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) { result -> + val task = GoogleSignIn.getSignedInAccountFromIntent(result.data) + try { + account = task.getResult(ApiException::class.java) + } catch (e: ApiException) { + Log.e("Auth", "signInResult:failed code=" + e.statusCode) + } + } + + val onLogout: () -> Unit = { + googleSignInClient.signOut().addOnCompleteListener { + account = null + } + } + + if (account == null) { + LoginScreen { launcher.launch(googleSignInClient.signInIntent) } + } else { + if (allowedEmails.contains(account?.email)) { + MainApp(dao, onLogout) + } else { + AccessDeniedScreen(onLogout) + } + } +} + +@Composable +fun LoginScreen(onLoginClick: () -> Unit) { + Column( + modifier = Modifier.fillMaxSize().padding(16.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Text("Coloricam", style = MaterialTheme.typography.displayLarge, color = MaterialTheme.colorScheme.primary) + Spacer(Modifier.height(32.dp)) + Button(onClick = onLoginClick, modifier = Modifier.fillMaxWidth().height(56.dp)) { + Icon(Icons.Default.AccountCircle, null) + Spacer(Modifier.width(8.dp)) + Text("Se connecter avec Google") + } + } +} + +@Composable +fun AccessDeniedScreen(onLogout: () -> Unit) { + Column( + modifier = Modifier.fillMaxSize().padding(32.dp), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Icon(Icons.Default.Warning, null, modifier = Modifier.size(80.dp), tint = MaterialTheme.colorScheme.error) + Spacer(Modifier.height(16.dp)) + Text("Accès Refusé", style = MaterialTheme.typography.headlineMedium, color = MaterialTheme.colorScheme.error) + Spacer(Modifier.height(8.dp)) + Text("Votre compte n'est pas autorisé à utiliser cette application.", style = MaterialTheme.typography.bodyLarge) + Spacer(Modifier.height(32.dp)) + Button(onClick = onLogout) { Text("Changer de compte") } + } +} + +@Composable +fun MainApp(dao: AppDao, onLogout: () -> Unit) { + val context = LocalContext.current + val prefs = remember { context.getSharedPreferences("user_prefs", Context.MODE_PRIVATE) } + var showSetup by remember { mutableStateOf(!prefs.contains("target_calories")) } + var isDiabetic by remember { mutableStateOf(prefs.getBoolean("is_diabetic", false)) } + + if (showSetup) { + SetupScreen(prefs) { + showSetup = false + isDiabetic = prefs.getBoolean("is_diabetic", false) + } + } else { + val navController = rememberNavController() + Scaffold( + bottomBar = { + NavigationBar { + NavigationBarItem(icon = { Icon(Icons.Default.Home, "Repas") }, label = { Text("Repas") }, selected = false, onClick = { navController.navigate("capture") }) + NavigationBarItem(icon = { Icon(Icons.Default.Add, "Sport") }, label = { Text("Sport") }, selected = false, onClick = { navController.navigate("sport") }) + NavigationBarItem(icon = { Icon(Icons.Default.Settings, "Paramètres") }, label = { Text("Paramètres") }, selected = false, onClick = { navController.navigate("settings") }) + } + } + ) { innerPadding -> + NavHost(navController, "capture", Modifier.padding(innerPadding)) { + composable("capture") { CaptureScreen(dao, prefs, isDiabetic) } + composable("sport") { SportScreen(dao, prefs) } + composable("settings") { SettingsScreen(prefs, onLogout) } + } + } + } +} + +@Composable +fun SetupScreen(prefs: SharedPreferences, onComplete: () -> Unit) { + var targetCalories by remember { mutableStateOf("2000") } + var targetCarbs by remember { mutableStateOf("250") } + var weightKg by remember { mutableStateOf("70") } + var isDiabetic by remember { mutableStateOf(false) } + + Column( + modifier = Modifier.fillMaxSize().padding(24.dp).verticalScroll(rememberScrollState()), + horizontalAlignment = Alignment.CenterHorizontally, + verticalArrangement = Arrangement.Center + ) { + Text("Configuration initiale", style = MaterialTheme.typography.headlineLarge) + Spacer(Modifier.height(24.dp)) + OutlinedTextField(value = targetCalories, onValueChange = { targetCalories = it }, label = { Text("Objectif Calories / jour") }, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth()) + Spacer(Modifier.height(16.dp)) + OutlinedTextField(value = targetCarbs, onValueChange = { targetCarbs = it }, label = { Text("Objectif Glucides / jour (g)") }, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth()) + Spacer(Modifier.height(16.dp)) + OutlinedTextField(value = weightKg, onValueChange = { weightKg = it }, label = { Text("Poids (kg)") }, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth()) + Spacer(Modifier.height(24.dp)) + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth()) { + Checkbox(checked = isDiabetic, onCheckedChange = { isDiabetic = it }) + Text("Je suis diabétique (ajoute l'estimation d'insuline)") + } + Spacer(Modifier.height(32.dp)) + Button(onClick = { + prefs.edit() + .putString("target_calories", targetCalories) + .putString("target_carbs", targetCarbs) + .putString("weight_kg", weightKg) + .putBoolean("is_diabetic", isDiabetic) + .apply() + onComplete() + }, modifier = Modifier.fillMaxWidth().height(56.dp)) { + Text("Commencer") + } + } +} diff --git a/app/src/main/java/com/example/coloricam/ui/theme/Color.kt b/app/src/main/java/com/example/coloricam/ui/theme/Color.kt new file mode 100644 index 0000000..ea581a9 --- /dev/null +++ b/app/src/main/java/com/example/coloricam/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.example.coloricam.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/app/src/main/java/com/example/coloricam/ui/theme/Theme.kt b/app/src/main/java/com/example/coloricam/ui/theme/Theme.kt new file mode 100644 index 0000000..b409f6b --- /dev/null +++ b/app/src/main/java/com/example/coloricam/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package com.example.coloricam.ui.theme + +import android.app.Activity +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.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun ColoricamTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + 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 + ) +} \ No newline at end of file diff --git a/app/src/main/java/com/example/coloricam/ui/theme/Type.kt b/app/src/main/java/com/example/coloricam/ui/theme/Type.kt new file mode 100644 index 0000000..26d473e --- /dev/null +++ b/app/src/main/java/com/example/coloricam/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.example.coloricam.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 + ) + */ +) \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..7796a25 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + coloricam + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..d6097da --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +