-
Notifications
You must be signed in to change notification settings - Fork 1
Closes #22 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Closes #22 #23
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 51 additions & 24 deletions
75
app/src/main/java/com/uniandes/ecobites/ui/screens/LoginScreen.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,83 +1,110 @@ | ||
| 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 | ||
ma-r-s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ){ | ||
| 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() | ||
| .padding(16.dp), | ||
| 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() | ||
| ) | ||
|
|
||
| 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() | ||
ma-r-s marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| }, | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) { | ||
| Text("Sign in") | ||
| } | ||
|
|
||
| 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") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| fun PreviewLoginScreen() { | ||
| LoginScreenContent() | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 | ||
| } |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.