From 5644272d5eb65cb7c91db20811900838d38ad17d Mon Sep 17 00:00:00 2001 From: Janis Hutz Date: Sun, 8 Oct 2023 11:07:25 +0200 Subject: [PATCH] some more progress on android app --- .../Android/app/src/main/AndroidManifest.xml | 1 + .../com/janishutz/libreevent/ApiClient.kt | 9 +++-- .../com/janishutz/libreevent/MainActivity.kt | 33 +++++++++++++++-- .../janishutz/libreevent/ScannerActivity.kt | 35 ++++++++++++++++--- .../src/main/res/layout/activity_scanner.xml | 9 ++++- 5 files changed, 73 insertions(+), 14 deletions(-) diff --git a/src/apps/Android/app/src/main/AndroidManifest.xml b/src/apps/Android/app/src/main/AndroidManifest.xml index 7c61be7..2e9af8d 100644 --- a/src/apps/Android/app/src/main/AndroidManifest.xml +++ b/src/apps/Android/app/src/main/AndroidManifest.xml @@ -29,4 +29,5 @@ + \ No newline at end of file diff --git a/src/apps/Android/app/src/main/java/com/janishutz/libreevent/ApiClient.kt b/src/apps/Android/app/src/main/java/com/janishutz/libreevent/ApiClient.kt index edb9b91..c24ecff 100644 --- a/src/apps/Android/app/src/main/java/com/janishutz/libreevent/ApiClient.kt +++ b/src/apps/Android/app/src/main/java/com/janishutz/libreevent/ApiClient.kt @@ -26,7 +26,7 @@ class ApiClient { connection.doOutput = true // Create the JSON request body - val jsonRequest = "{\"username\":\"$username\",\"password\":\"$password\"}" + val jsonRequest = "{\"email\":\"$username\",\"password\":\"$password\"}" // Write the JSON data to the output stream val outputStream = DataOutputStream(connection.outputStream) @@ -50,8 +50,7 @@ class ApiClient { // Return the response as a String return response.toString() } else { - // Handle the error (e.g., authentication failed) - // You can also throw an exception here if needed + println(responseCode) return "status-code-non-ok" } } catch (e: Exception) { @@ -61,7 +60,7 @@ class ApiClient { } fun checkTicket(apiUrl: String, username: String, password: String, ticket: String): String { - val url = URL("$apiUrl/app/ticketLookup") + val url = URL("https://$apiUrl/app/ticketLookup") val connection = url.openConnection() as HttpURLConnection // Set the request method to POST @@ -76,7 +75,7 @@ class ApiClient { connection.doOutput = true // Create the JSON request body - val jsonRequest = "{\"username\":\"$username\",\"password\":\"$password\",\"ticketID\":$ticket}" + val jsonRequest = "{\"email\":\"$username\",\"password\":\"$password\",\"ticketID\":$ticket}" // Write the JSON data to the output stream val outputStream = DataOutputStream(connection.outputStream) diff --git a/src/apps/Android/app/src/main/java/com/janishutz/libreevent/MainActivity.kt b/src/apps/Android/app/src/main/java/com/janishutz/libreevent/MainActivity.kt index eb8d6ed..80743ae 100644 --- a/src/apps/Android/app/src/main/java/com/janishutz/libreevent/MainActivity.kt +++ b/src/apps/Android/app/src/main/java/com/janishutz/libreevent/MainActivity.kt @@ -1,23 +1,43 @@ package com.janishutz.libreevent +import android.app.AlertDialog import android.content.Intent -import androidx.appcompat.app.AppCompatActivity import android.os.Bundle +import android.os.StrictMode +import android.os.StrictMode.ThreadPolicy import android.widget.Button import android.widget.EditText -import android.app.AlertDialog -import com.janishutz.libreevent.ApiClient +import androidx.appcompat.app.AppCompatActivity + class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) + val policy = ThreadPolicy.Builder().permitAll().build() + StrictMode.setThreadPolicy(policy) + + val sharedPref = getPreferences( MODE_PRIVATE ) + + val hasSwitched = intent.hasExtra("hasSwitched") + val loginButton = findViewById