package uz.myid.sdk.sample import android.os.Bundle import android.widget.EditText import androidx.appcompat.app.AppCompatActivity import uz.myid.android.sdk.capture.* import uz.myid.sdk.sample.databinding.ActivityMainBinding class MainActivity : AppCompatActivity(), MyIdResultListener { private val binding by lazy { ActivityMainBinding.inflate(layoutInflater) } private val client = MyIdClient() private var clientId = "dev_tester-kYJmOs5F6IGSk9GnXHSfaN6rSPKaxPvz1dyyQqvG" private var entryType = MyIdEntryType.AUTH private var buildType = MyIdBuildType.PROD private var locale = MyIdLocale.EN private var withPhoto = false private var code = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(binding.root) with(binding) { inputClientId.setText(clientId) radioGroupLang.setOnCheckedChangeListener { _, checkedId -> locale = when (checkedId) { R.id.radioUz -> MyIdLocale.UZ R.id.radioEn -> MyIdLocale.EN else -> MyIdLocale.RU } } radioGroupEntry.setOnCheckedChangeListener { _, checkedId -> entryType = if (checkedId == R.id.radioFace) { MyIdEntryType.FACE } else { MyIdEntryType.AUTH } } radioGroupBuildType.setOnCheckedChangeListener { _, checkedId -> buildType = if (checkedId == R.id.radioProd) { MyIdBuildMode.PRODUCTION } else { MyIdBuildMode.DEBUG } } radioGroupPhoto.setOnCheckedChangeListener { _, checkedId -> withPhoto = (checkedId == R.id.radioWith) } buttonStart.setOnClickListener { startMyId() } } } override fun onSuccess(result: MyIdResult) { code = result.code.orEmpty() with(binding) { imageResult.setImageBitmap(result.bitmap) "Result code: ${result.code}".also { textResult.text = it } } } override fun onError(e: MyIdException) { code = "" with(binding) { imageResult.setImageBitmap(null) """ Result error: ${e.message} Result error code: ${e.code} """.trimIndent().also { textResult.text = it } } } override fun onUserExited() { code = "" with(binding) { imageResult.setImageBitmap(null) "User exited".also { textResult.text = it } } } private fun startMyId() { val myIdConfig = MyIdConfig.builder(binding.inputClientId.value) .withPassportData(binding.inputPassportData.value) .withBirthDate(binding.inputDate.value) .withExternalId(binding.inputExternalId.value) .withEntryType(entryType) .withBuildMode(MyIdBuildMode.PRODUCTION) .withLocale(locale) .withPhoto(withPhoto) .build() val intent = client.createIntent(this, myIdConfig) result.launch(intent) } private val result = takeUserResult(this) private inline val EditText.value: String get() = text.toString().trim() }