diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0f4c973..18e07e9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,6 +1,7 @@ plugins { - alias(libs.plugins.android.application) - alias(libs.plugins.kotlin.android) + id("com.android.application") version "8.6.1" // AGP version + id("org.jetbrains.kotlin.android") version "1.9.0" // Kotlin plugin for Android + id("org.jetbrains.kotlin.plugin.serialization") version "1.9.0" // Kotlin serialization plugin } android { @@ -51,19 +52,33 @@ android { 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.ui) - implementation(libs.androidx.ui.graphics) - implementation(libs.androidx.ui.tooling.preview) - implementation(libs.androidx.material3) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.espresso.core) - androidTestImplementation(platform(libs.androidx.compose.bom)) - androidTestImplementation(libs.androidx.ui.test.junit4) - debugImplementation(libs.androidx.ui.tooling) - debugImplementation(libs.androidx.ui.test.manifest) + + // Supabase dependencies + implementation(platform("io.github.jan-tennert.supabase:bom:3.0.0")) + implementation("io.github.jan-tennert.supabase:postgrest-kt") + implementation("io.ktor:ktor-client-android:3.0.0-rc-1") + + // AndroidX dependencies + implementation("androidx.core:core-ktx:1.13.1") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.6") + implementation("androidx.activity:activity-compose:1.9.2") + + // Compose dependencies + implementation(platform("androidx.compose:compose-bom:2024.09.03")) + implementation("androidx.compose.ui:ui") + implementation("androidx.compose.ui:ui-graphics") + implementation("androidx.compose.ui:ui-tooling-preview") + implementation("androidx.compose.material3:material3:1.3.0") + + // Testing dependencies + testImplementation("junit:junit:4.13.2") + androidTestImplementation("androidx.test.ext:junit:1.2.1") + androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") + androidTestImplementation(platform("androidx.compose:compose-bom:2024.09.03")) + androidTestImplementation("androidx.compose.ui:ui-test-junit4") + + // Debug dependencies + debugImplementation("androidx.compose.ui:ui-tooling") + debugImplementation("androidx.compose.ui:ui-test-manifest") + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c1eede0..fb516a9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,7 @@ - + Unit) { - Column( - modifier = Modifier - .fillMaxSize() - .padding(16.dp), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally -) { - Text(text = "Log in", fontSize = 24.sp) - Spacer(modifier = Modifier.height(24.dp)) - - Text(text = "eco", fontSize = 48.sp, color = androidx.compose.ui.graphics.Color(0xFF4A6A2B)) - Text(text = "bites", fontSize = 48.sp, color = androidx.compose.ui.graphics.Color(0xFF4A6A2B)) - - Spacer(modifier = Modifier.height(24.dp)) - - OutlinedTextField( - value = "", - onValueChange = {}, - label = { Text("Username") }, - modifier = Modifier.fillMaxWidth() - ) - - OutlinedTextField( - value = "", - onValueChange = {}, - label = { Text("Password") }, - modifier = Modifier.fillMaxWidth(), - visualTransformation = PasswordVisualTransformation() - ) - - Spacer(modifier = Modifier.height(16.dp)) - - Button( - onClick = {onSignInClicked() }, - modifier = Modifier.fillMaxWidth() - ) { - Text("Sign in") - } - - Spacer(modifier = Modifier.height(10.dp)) - - Button( - onClick = { /* Implement sign-up logic */ }, - modifier = Modifier.fillMaxWidth() - ) { - Text("Sign Up") - } -} -} diff --git a/app/src/main/java/com/uniandes/ecobites/ui/screens/LoginScreen.kt b/app/src/main/java/com/uniandes/ecobites/ui/screens/LoginScreen.kt index 4e88c97..72673af 100644 --- a/app/src/main/java/com/uniandes/ecobites/ui/screens/LoginScreen.kt +++ b/app/src/main/java/com/uniandes/ecobites/ui/screens/LoginScreen.kt @@ -1,29 +1,41 @@ -package com.example.ecobites +package com.uniandes.ecobites.ui.screens import android.os.Bundle +import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.layout.* import androidx.compose.material3.* -import androidx.compose.runtime.Composable +import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.text.input.PasswordVisualTransformation import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.tooling.preview.Preview +import io.github.jan.supabase.createSupabaseClient +import kotlinx.coroutines.launch +import io.github.jan.supabase.auth.Auth +import io.github.jan.supabase.auth.auth +import io.github.jan.supabase.auth.providers.builtin.Email -class LoginScreen : ComponentActivity() { - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContent { - LoginScreenContent() - } - } +// Initialize Supabase +val supabase = createSupabaseClient( + supabaseUrl = "https://nlhcaanwwchxdzdiyizf.supabase.co", // Replace with your actual Supabase URL + supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im5saGNhYW53d2NoeGR6ZGl5aXpmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc5MDc0OTQsImV4cCI6MjA0MzQ4MzQ5NH0.LrcRGkVH1qjPE09xDngX7wrtrUmfIYbTGrgbPKarTeM" // Replace with your actual Supabase anon key +){ + install(Auth) } +val auth = supabase.auth @Composable -fun LoginScreenContent() { +fun LoginScreen(onLoginSuccess: () -> Unit) { + val context = LocalContext.current + var email by remember { mutableStateOf("") } + var password by remember { mutableStateOf("") } + val coroutineScope = rememberCoroutineScope() // For launching coroutines + Column( modifier = Modifier .fillMaxSize() @@ -31,24 +43,28 @@ fun LoginScreenContent() { verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { + // Title Text(text = "Log in", fontSize = 24.sp) Spacer(modifier = Modifier.height(24.dp)) + // App name Text(text = "eco", fontSize = 48.sp, color = androidx.compose.ui.graphics.Color(0xFF4A6A2B)) Text(text = "bites", fontSize = 48.sp, color = androidx.compose.ui.graphics.Color(0xFF4A6A2B)) Spacer(modifier = Modifier.height(24.dp)) + // Email Input Field OutlinedTextField( - value = "", - onValueChange = {}, - label = { Text("Username") }, + value = email, + onValueChange = { email = it }, + label = { Text("Email") }, modifier = Modifier.fillMaxWidth() ) + // Password Input Field OutlinedTextField( - value = "", - onValueChange = {}, + value = password, + onValueChange = { password = it }, label = { Text("Password") }, modifier = Modifier.fillMaxWidth(), visualTransformation = PasswordVisualTransformation() @@ -56,8 +72,22 @@ fun LoginScreenContent() { Spacer(modifier = Modifier.height(16.dp)) + // Sign-In Button Button( - onClick = { /* Implement sign-in logic */ }, + onClick = { + coroutineScope.launch { + try { + auth.signInWith(Email) { + this.email = email + this.password = password + } + Toast.makeText(context, "Signed in successfully!", Toast.LENGTH_LONG).show() + onLoginSuccess() // Call the callback to update the login state + } catch (e: Exception) { + Toast.makeText(context, "Sign in failed: ${e.message}", Toast.LENGTH_LONG).show() + } + } + }, modifier = Modifier.fillMaxWidth() ) { Text("Sign in") @@ -65,8 +95,12 @@ fun LoginScreenContent() { Spacer(modifier = Modifier.height(10.dp)) + // Sign-Up Button Button( - onClick = { /* Implement sign-up logic */ }, + onClick = { + // Handle sign-up logic (optional) + Toast.makeText(context, "Sign Up clicked", Toast.LENGTH_SHORT).show() + }, modifier = Modifier.fillMaxWidth() ) { Text("Sign Up") @@ -74,10 +108,3 @@ fun LoginScreenContent() { } } -@Preview(showBackground = true) -@Composable -fun PreviewLoginScreen() { - LoginScreenContent() -} - - diff --git a/build.gradle.kts b/build.gradle.kts index 922f551..8de1877 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { - alias(libs.plugins.android.application) apply false - alias(libs.plugins.kotlin.android) apply false + id("com.android.application") version "8.6.1" apply false // AGP version + id("org.jetbrains.kotlin.android") version "1.9.0" apply false // Kotlin version } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml deleted file mode 100644 index e75a874..0000000 --- a/gradle/libs.versions.toml +++ /dev/null @@ -1,34 +0,0 @@ -[versions] -agp = "8.6.0" -kotlin = "1.9.0" -coreKtx = "1.13.1" -junit = "4.13.2" -junitVersion = "1.2.1" -espressoCore = "3.6.1" -lifecycleRuntimeKtx = "2.8.5" -activityCompose = "1.9.2" -composeBom = "2024.04.01" -composeVersion = "1.3.0" -runtimeAndroid = "1.7.2" - -[libraries] -androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } -junit = { group = "junit", name = "junit", version.ref = "junit" } -androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } -androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } -androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } -androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } -androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } -androidx-ui = { group = "androidx.compose.ui", name = "ui" } -androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } -androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } -androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } -androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } -androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } -androidx-material3 = { group = "androidx.compose.material3", name = "material3", version.ref="composeVersion" } -androidx-runtime-android = { group = "androidx.compose.runtime", name = "runtime-android", version.ref = "runtimeAndroid" } - -[plugins] -android-application = { id = "com.android.application", version.ref = "agp" } -kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } -