From 93057d43d5e647725996a8494e8c7b6b2ace8abf Mon Sep 17 00:00:00 2001 From: Reimar Date: Tue, 29 Apr 2025 13:18:43 +0200 Subject: [PATCH 1/3] Implement send http requests to the api --- app/.idea/compiler.xml | 2 +- app/.idea/misc.xml | 3 +- app/app/build.gradle.kts | 10 ++- app/app/src/main/AndroidManifest.xml | 1 + .../tech/mercantec/easyeat/LoginActivity.kt | 29 ++++++-- .../tech/mercantec/easyeat/helpers/api.kt | 73 +++++++++++++++++++ .../tech/mercantec/easyeat/helpers/auth.kt | 28 +++++++ .../src/main/res/layout/activity_login.xml | 2 + app/build.gradle.kts | 1 + app/gradle.properties | 4 +- app/gradle/libs.versions.toml | 2 + 11 files changed, 141 insertions(+), 14 deletions(-) create mode 100644 app/app/src/main/java/tech/mercantec/easyeat/helpers/api.kt create mode 100644 app/app/src/main/java/tech/mercantec/easyeat/helpers/auth.kt diff --git a/app/.idea/compiler.xml b/app/.idea/compiler.xml index b86273d..b589d56 100644 --- a/app/.idea/compiler.xml +++ b/app/.idea/compiler.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/app/.idea/misc.xml b/app/.idea/misc.xml index 2731899..ec453bb 100644 --- a/app/.idea/misc.xml +++ b/app/.idea/misc.xml @@ -1,9 +1,10 @@ + - + diff --git a/app/app/build.gradle.kts b/app/app/build.gradle.kts index 160f3f0..14fe66a 100644 --- a/app/app/build.gradle.kts +++ b/app/app/build.gradle.kts @@ -1,6 +1,9 @@ +import com.android.build.gradle.internal.cxx.configure.gradleLocalProperties + plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.android) + id("org.jetbrains.kotlin.plugin.serialization") } android { @@ -15,6 +18,8 @@ android { versionName = "1.0" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + + buildConfigField("String", "API_BASE_URL", gradleLocalProperties(projectDir, providers).getProperty("API_BASE_URL")) } buildTypes { @@ -36,7 +41,6 @@ android { } dependencies { - implementation(libs.androidx.core.ktx) implementation(libs.androidx.appcompat) implementation(libs.material) @@ -48,7 +52,5 @@ dependencies { implementation(libs.navigation.fragment.ktx) implementation(libs.navigation.ui.ktx) implementation(libs.androidx.activity) - testImplementation(libs.junit) - androidTestImplementation(libs.androidx.junit) - androidTestImplementation(libs.androidx.espresso.core) + implementation(libs.kotlinx.serialization.json) } \ No newline at end of file diff --git a/app/app/src/main/AndroidManifest.xml b/app/app/src/main/AndroidManifest.xml index 830e77d..215816d 100644 --- a/app/app/src/main/AndroidManifest.xml +++ b/app/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + (R.id.login).setOnClickListener { - // TODO authenticate + val email = findViewById(R.id.email).text.toString() + val password = findViewById(R.id.password).text.toString() - val intent = Intent(this, MainActivity::class.java) - intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK // Prevent going back to login screen - startActivity(intent) + thread { + try { + login(email, password) + } catch (e: ApiRequestException) { + runOnUiThread { + Toast.makeText(this, e.message, Toast.LENGTH_LONG).show() + } + + return@thread + } + + val intent = Intent(this, MainActivity::class.java) + intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK // Prevent going back to login screen + startActivity(intent) + } } findViewById