mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 05:14:23 +00:00
some more progress on android app
This commit is contained in:
@@ -29,4 +29,5 @@
|
|||||||
<uses-feature android:name="android.hardware.camera" android:required="true" />
|
<uses-feature android:name="android.hardware.camera" android:required="true" />
|
||||||
<uses-feature android:name="android.hardware.camera.autofocus" android:required="true" />
|
<uses-feature android:name="android.hardware.camera.autofocus" android:required="true" />
|
||||||
<uses-permission android:name="android.permission.CAMERA" />
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
</manifest>
|
</manifest>
|
||||||
@@ -26,7 +26,7 @@ class ApiClient {
|
|||||||
connection.doOutput = true
|
connection.doOutput = true
|
||||||
|
|
||||||
// Create the JSON request body
|
// 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
|
// Write the JSON data to the output stream
|
||||||
val outputStream = DataOutputStream(connection.outputStream)
|
val outputStream = DataOutputStream(connection.outputStream)
|
||||||
@@ -50,8 +50,7 @@ class ApiClient {
|
|||||||
// Return the response as a String
|
// Return the response as a String
|
||||||
return response.toString()
|
return response.toString()
|
||||||
} else {
|
} else {
|
||||||
// Handle the error (e.g., authentication failed)
|
println(responseCode)
|
||||||
// You can also throw an exception here if needed
|
|
||||||
return "status-code-non-ok"
|
return "status-code-non-ok"
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -61,7 +60,7 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun checkTicket(apiUrl: String, username: String, password: String, ticket: String): String {
|
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
|
val connection = url.openConnection() as HttpURLConnection
|
||||||
|
|
||||||
// Set the request method to POST
|
// Set the request method to POST
|
||||||
@@ -76,7 +75,7 @@ class ApiClient {
|
|||||||
connection.doOutput = true
|
connection.doOutput = true
|
||||||
|
|
||||||
// Create the JSON request body
|
// 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
|
// Write the JSON data to the output stream
|
||||||
val outputStream = DataOutputStream(connection.outputStream)
|
val outputStream = DataOutputStream(connection.outputStream)
|
||||||
|
|||||||
@@ -1,23 +1,43 @@
|
|||||||
package com.janishutz.libreevent
|
package com.janishutz.libreevent
|
||||||
|
|
||||||
|
import android.app.AlertDialog
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.StrictMode
|
||||||
|
import android.os.StrictMode.ThreadPolicy
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.app.AlertDialog
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.janishutz.libreevent.ApiClient
|
|
||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_main)
|
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<Button>(R.id.loginButton)
|
val loginButton = findViewById<Button>(R.id.loginButton)
|
||||||
val urlEditText = findViewById<EditText>(R.id.url)
|
val urlEditText = findViewById<EditText>(R.id.url)
|
||||||
val usernameEditText = findViewById<EditText>(R.id.username)
|
val usernameEditText = findViewById<EditText>(R.id.username)
|
||||||
val passwordEditText = findViewById<EditText>(R.id.password)
|
val passwordEditText = findViewById<EditText>(R.id.password)
|
||||||
|
|
||||||
|
if (sharedPref.getString( "url", null ).toString() != "null" && sharedPref.getString( "username", null ).toString() != "null" ) {
|
||||||
|
urlEditText.setText(sharedPref.getString( "url", null ).toString())
|
||||||
|
usernameEditText.setText(sharedPref.getString( "username", null ).toString())
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sharedPref.getString( "loginOk", null ).toString() != "null" && !hasSwitched) {
|
||||||
|
println(sharedPref.getString( "loginOk", null ).toString())
|
||||||
|
val switchIntent = Intent(this, ScannerActivity::class.java)
|
||||||
|
startActivity(switchIntent)
|
||||||
|
}
|
||||||
|
|
||||||
loginButton.setOnClickListener {
|
loginButton.setOnClickListener {
|
||||||
val url = urlEditText.text.toString()
|
val url = urlEditText.text.toString()
|
||||||
val username = usernameEditText.text.toString()
|
val username = usernameEditText.text.toString()
|
||||||
@@ -30,6 +50,13 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val res = ApiClient().authenticateUser( url, username, password )
|
val res = ApiClient().authenticateUser( url, username, password )
|
||||||
println( res )
|
println( res )
|
||||||
if ( res == "authOk" ) {
|
if ( res == "authOk" ) {
|
||||||
|
val sharedPref = getPreferences( MODE_PRIVATE )
|
||||||
|
val editor = sharedPref.edit()
|
||||||
|
editor.putString( "username", username )
|
||||||
|
editor.putString( "password", password )
|
||||||
|
editor.putString( "url", url )
|
||||||
|
editor.putString( "loginOk", "true" )
|
||||||
|
editor.apply()
|
||||||
val switchIntent = Intent(this, ScannerActivity::class.java)
|
val switchIntent = Intent(this, ScannerActivity::class.java)
|
||||||
startActivity(switchIntent)
|
startActivity(switchIntent)
|
||||||
} else if ( res == "status-code-non-ok" ) {
|
} else if ( res == "status-code-non-ok" ) {
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
package com.janishutz.libreevent
|
package com.janishutz.libreevent
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.app.AlertDialog
|
||||||
|
import android.content.Intent
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.widget.Button
|
||||||
import androidx.core.app.ActivityCompat
|
import androidx.core.app.ActivityCompat
|
||||||
import com.journeyapps.barcodescanner.BarcodeCallback
|
import com.journeyapps.barcodescanner.BarcodeCallback
|
||||||
import com.journeyapps.barcodescanner.BarcodeResult
|
import com.journeyapps.barcodescanner.BarcodeResult
|
||||||
@@ -23,6 +26,19 @@ class ScannerActivity : CaptureActivity() {
|
|||||||
|
|
||||||
barcodeView = findViewById(R.id.barcodeScannerView)
|
barcodeView = findViewById(R.id.barcodeScannerView)
|
||||||
|
|
||||||
|
val logoutButton = findViewById<Button>(R.id.logoutButton)
|
||||||
|
logoutButton.setOnClickListener {
|
||||||
|
val sharedPref = getPreferences( MODE_PRIVATE )
|
||||||
|
val editor = sharedPref.edit()
|
||||||
|
editor.remove( "loginOk" )
|
||||||
|
editor.remove( "username" )
|
||||||
|
editor.remove( "url" )
|
||||||
|
editor.apply()
|
||||||
|
val switchIntent = Intent(this, MainActivity::class.java)
|
||||||
|
switchIntent.putExtra("hasSwitched", true)
|
||||||
|
startActivity(switchIntent)
|
||||||
|
}
|
||||||
|
|
||||||
// Check for camera permission and request if not granted
|
// Check for camera permission and request if not granted
|
||||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), CAMERA_PERMISSION_REQUEST)
|
ActivityCompat.requestPermissions(this, arrayOf(Manifest.permission.CAMERA), CAMERA_PERMISSION_REQUEST)
|
||||||
@@ -43,16 +59,17 @@ class ScannerActivity : CaptureActivity() {
|
|||||||
handleScanResult(scannedData)
|
handleScanResult(scannedData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun possibleResultPoints(resultPoints: List<com.google.zxing.ResultPoint>?) {
|
|
||||||
// Optional: Handle possible result points
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleScanResult(result: String) {
|
private fun handleScanResult(result: String) {
|
||||||
if ( lastScanned != result ) {
|
if ( lastScanned != result ) {
|
||||||
println(result)
|
println(result)
|
||||||
|
val sharedPref = getPreferences( MODE_PRIVATE )
|
||||||
|
|
||||||
|
ApiClient().checkTicket( sharedPref.getString( "url", null ).toString(),
|
||||||
|
sharedPref.getString( "username", null ).toString(),
|
||||||
|
sharedPref.getString( "password", null ).toString(), result )
|
||||||
lastScanned = result
|
lastScanned = result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +96,15 @@ class ScannerActivity : CaptureActivity() {
|
|||||||
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
if (grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
setupScanner()
|
setupScanner()
|
||||||
} else {
|
} else {
|
||||||
// Handle permission denied
|
val alertDialogBuilder = AlertDialog.Builder(this)
|
||||||
|
alertDialogBuilder.setTitle("Camera access required!")
|
||||||
|
alertDialogBuilder.setMessage("Please ensure that camera access is enabled in settings")
|
||||||
|
alertDialogBuilder.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
|
||||||
|
alertDialogBuilder.setPositiveButton("OK") { dialog, _ ->
|
||||||
|
dialog.dismiss()
|
||||||
|
}
|
||||||
|
alertDialogBuilder.show()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,13 @@
|
|||||||
<com.journeyapps.barcodescanner.DecoratedBarcodeView
|
<com.journeyapps.barcodescanner.DecoratedBarcodeView
|
||||||
android:id="@+id/barcodeScannerView"
|
android:id="@+id/barcodeScannerView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" >
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/logoutButton"
|
||||||
|
android:layout_width="122dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Log out" />
|
||||||
|
</com.journeyapps.barcodescanner.DecoratedBarcodeView>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|||||||
Reference in New Issue
Block a user