Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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")

}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down
82 changes: 22 additions & 60 deletions app/src/main/java/com/uniandes/ecobites/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,26 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.ecobites.LoginScreen
import com.uniandes.ecobites.ui.screens.CartScreen
import com.uniandes.ecobites.ui.screens.home.HomeScreen
import com.uniandes.ecobites.ui.screens.ProfileScreen
import com.uniandes.ecobites.ui.theme.AppTheme
import com.uniandes.ecobites.ui.components.NavBar
import com.uniandes.ecobites.ui.SplashScreen
import com.uniandes.ecobites.ui.screens.LoginScreen
import io.github.jan.supabase.createSupabaseClient
import kotlinx.coroutines.delay
import io.github.jan.supabase.auth.Auth
import io.github.jan.supabase.postgrest.Postgrest

val supabase = createSupabaseClient(
supabaseUrl = "https://nlhcaanwwchxdzdiyizf.supabase.co",
supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Im5saGNhYW53d2NoeGR6ZGl5aXpmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3Mjc5MDc0OTQsImV4cCI6MjA0MzQ4MzQ5NH0.LrcRGkVH1qjPE09xDngX7wrtrUmfIYbTGrgbPKarTeM"
) {
install(Auth)
install(Postgrest)
//install other modules
}

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -44,26 +56,27 @@ class MainActivity : ComponentActivity() {
@Composable
fun MyApp() {
var showSplashScreen by remember { mutableStateOf(true) }
var isLoggedIn by remember { mutableStateOf(false) }
var isLoggedIn by remember { mutableStateOf(false) } // Track login state

// Mostrar pantalla de splash durante 3 segundos antes de navegar al contenido principal
// Show splash screen for 3 seconds before navigating to the main content
LaunchedEffect(Unit) {
delay(3000) // 3 segundos
showSplashScreen = false // Ocultar pantalla de splash después del retardo
delay(3000) // 3 seconds delay
showSplashScreen = false // Hide splash screen after the delay
}

if (showSplashScreen) {
SplashScreen() // Mostrar pantalla de splash
SplashScreen() // Show splash screen
} else if (!isLoggedIn) {
LoginScreen(onSignInClicked = { isLoggedIn = true })
LoginScreen(onLoginSuccess = { isLoggedIn = true }) // Pass a callback to update isLoggedIn
} else {
MainContent()
MainContent() // Show main content if logged in
}
}


@Composable
fun MainContent() {
var selectedTab by remember { mutableStateOf(0) }
var selectedTab by remember { mutableIntStateOf(0) }

Scaffold(
bottomBar = {
Expand All @@ -80,54 +93,3 @@ fun MainContent() {
}
}

@Composable
fun LoginScreen(onSignInClicked: () -> 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")
}
}
}
75 changes: 51 additions & 24 deletions app/src/main/java/com/uniandes/ecobites/ui/screens/LoginScreen.kt
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
){
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()
}
}
},
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()
}


4 changes: 2 additions & 2 deletions build.gradle.kts
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
}
34 changes: 0 additions & 34 deletions gradle/libs.versions.toml

This file was deleted.