MOB-41 small changes to the test app

This commit is contained in:
Henrik Lepson 2021-11-07 13:49:19 +02:00
parent cc3a3c10d6
commit eca3f92468
7 changed files with 93 additions and 40 deletions

View File

@ -70,6 +70,7 @@ class AuthFragment : Fragment() {
}
private fun getInfoFromIdCard(adapter: NfcAdapter) {
if (args.reading) {
adapter.enableReaderMode(activity, { tag ->
timer.cancel()
requireActivity().runOnUiThread {
@ -87,7 +88,7 @@ class AuthFragment : Fragment() {
viewModel.setGender(response[3])
viewModel.setCitizenship(response[4])
viewModel.setExpiration(response[5])
requireActivity().runOnUiThread{
requireActivity().runOnUiThread {
binding!!.timeCounter.text = getString(R.string.data_read)
}
} catch (e: Exception) {
@ -104,6 +105,9 @@ class AuthFragment : Fragment() {
}
}
}, NfcAdapter.FLAG_READER_NFC_A, null)
} else { //We want to create a JWT instead of reading the info from the card.
goToNextFragment()
}
}
private fun goToNextFragment() {

View File

@ -38,9 +38,11 @@ class ResultFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding!!.resultBackButton.setOnClickListener {
if (!args.mobile) {
createResponse()
}
}
}
private fun createResponse() {
val resultIntent = Intent()

View File

@ -35,7 +35,7 @@ android {
}
dependencies {
implementation 'com.koushikdutta.ion:ion:3.1.0'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'

View File

@ -4,10 +4,16 @@ import android.app.Activity
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import com.example.testmobileapp.databinding.ActivityMainBinding
import com.koushikdutta.ion.Ion
/**
* Test mobile app to demonstrate how other applications can use MobileAuthApp.
* Single purpose app that launches the MobileAuthApp and gets the response back (JWT).
*/
class MainActivity : AppCompatActivity() {
private lateinit var authLauncher: ActivityResultLauncher<Intent>
@ -32,10 +38,33 @@ class MainActivity : AppCompatActivity() {
}
private fun launchAuth() {
/**
* Method that creates an intent to launch the MobileAuthApp
*/
private fun launchAuth(arg: String = "nothing") {
val launchIntent = Intent()
launchIntent.setClassName("com.tarkvaraprojekt.mobileauthapp", "com.tarkvaraprojekt.mobileauthapp.MainActivity")
launchIntent.putExtra("auth", true)
launchIntent.putExtra("nonce", arg) // Currently nothing
authLauncher.launch(launchIntent)
}
/**
* Method for retrieving data from an endpoint.
* Ion library is used as it is very convenient for making simple GET requests.
*/
private fun getData() {
val url = "real-address-here"
Ion.with(applicationContext)
.load(url)
.asJsonObject()
.setCallback { _, result ->
try {
// Get data from the result and call launchAuth method
launchAuth()
} catch (e: Exception) {
Log.i("GETrequest", "was unsuccessful")
}
}
}
}

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestMobileApp</string>
<string name="login_text">Login</string>
<string name="choose_login_method">Choose login method</string>
<string name="method_nfc">NFC auth</string>
<string name="auth_success">Successful response</string>
<string name="auth_failure">Response failed</string>
</resources>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">TestMobileApp</string>
<string name="login_text">Logi sisse</string>
<string name="choose_login_method">Vali sobiv meetod</string>
<string name="method_nfc">NFC auth</string>
<string name="auth_success">Vastus kätte saadud</string>
<string name="auth_failure">Vastust ei õnnestunud kätte saada</string>
</resources>

View File

@ -1,8 +1,8 @@
<resources>
<string name="app_name">TestMobileApp</string>
<string name="login_text">Logi sisse</string>
<string name="choose_login_method">Vali sobiv meetod</string>
<string name="login_text">Login</string>
<string name="choose_login_method">Choose login method</string>
<string name="method_nfc">NFC auth</string>
<string name="auth_success">Autentimine õnnestus</string>
<string name="auth_failure">Autentimine ebaõnnestus</string>
<string name="auth_success">Successful response</string>
<string name="auth_failure">Response failed</string>
</resources>