-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,96 @@ | ||
package com.ewc.eudiwalletoidcandroid | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import com.ewc.eudi_wallet_oidc_android.EudiWallet | ||
import com.ewc.eudiwalletoidcandroid.ui.theme.EudiWalletOIDCAndroidTheme | ||
|
||
class MainActivity : ComponentActivity() { | ||
import android.view.View | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.lifecycle.ViewModelProvider | ||
import com.ewc.eudi_wallet_oidc_android.services.did.DIDService | ||
import com.ewc.eudiwalletoidcandroid.databinding.ActivityMainBinding | ||
import io.igrant.qrcode_scanner_android.qrcode.utils.QRScanner | ||
|
||
class MainActivity : AppCompatActivity() { | ||
|
||
companion object { | ||
const val REQUEST_CODE_SCAN_ISSUE = 101 | ||
const val REQUEST_CODE_SCAN_VERIFY = 102 | ||
} | ||
|
||
private var viewModel: MainViewModel? = null | ||
private lateinit var binding: ActivityMainBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
EudiWalletOIDCAndroidTheme { | ||
// A surface container using the 'background' color from the theme | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background | ||
) { | ||
Greeting("Android") | ||
} | ||
binding = | ||
DataBindingUtil.setContentView(this, R.layout.activity_main) | ||
|
||
viewModel = ViewModelProvider(this)[MainViewModel::class.java] | ||
binding.viewModel = viewModel | ||
binding.lifecycleOwner = this | ||
viewModel?.subJwk = DIDService().createJWK() | ||
viewModel?.did = DIDService().createDID(viewModel?.subJwk!!) | ||
|
||
initClicks() | ||
} | ||
|
||
private fun initClicks() { | ||
binding.addCredential.setOnClickListener { | ||
binding.tvCredential.text = "" | ||
QRScanner().withLocale("en").start( | ||
this, | ||
REQUEST_CODE_SCAN_ISSUE | ||
) | ||
} | ||
|
||
binding.verifyCredential.setOnClickListener { | ||
QRScanner().withLocale("en").start( | ||
this, | ||
REQUEST_CODE_SCAN_VERIFY | ||
) | ||
} | ||
|
||
binding.verifyPin.setOnClickListener { | ||
if (binding.etPin.text.length == 4) { | ||
viewModel?.verifyPin(binding.etPin.text.toString()) | ||
|
||
binding.etPin.visibility = View.GONE | ||
binding.verifyPin.visibility = View.GONE | ||
binding.etPin.text.clear() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun Greeting(name: String, modifier: Modifier = Modifier) { | ||
Text( | ||
text = "Hello ${EudiWallet.sayHello()}!", | ||
modifier = modifier | ||
) | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun GreetingPreview() { | ||
EudiWalletOIDCAndroidTheme { | ||
Greeting("Android") | ||
|
||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
super.onActivityResult(requestCode, resultCode, data) | ||
if (resultCode == Activity.RESULT_OK) { | ||
when (requestCode) { | ||
REQUEST_CODE_SCAN_ISSUE -> { | ||
if (data == null) return | ||
|
||
val url = try { | ||
data.getStringExtra("com.blikoon.qrcodescanner.got_qr_scan_relult") | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
|
||
viewModel?.issueCredential(url ?: "") | ||
} | ||
|
||
REQUEST_CODE_SCAN_VERIFY -> { | ||
if (data == null) return | ||
|
||
val url = try { | ||
data.getStringExtra("com.blikoon.qrcodescanner.got_qr_scan_relult") | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
|
||
viewModel?.verifyCredential(url ?: "") | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |