From 43f21db9745a27bd1bfe584700348766167972be Mon Sep 17 00:00:00 2001 From: Hamid Moazzami <53338603+mblcdr@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:03:50 +0430 Subject: [PATCH] Make the example app dead simple (#326) * Make the example app dead simple * Fix the name of the layout for example identhub activity * Layout improvements for session URL entry field. * Update .gitignore file with more .idea files Co-authored-by: Julian Dreissig --- .gitignore | 13 +- example/src/main/AndroidManifest.xml | 8 +- .../example/ExampleIdentHubActivity.kt | 88 ++++++++++++ ...ation.kt => ExampleIdentHubApplication.kt} | 7 +- .../example/IdentHubInteractionActivity.kt | 127 ------------------ .../example/IdentitySelectionActivity.kt | 105 --------------- .../res/layout/activity_example_identhub.xml | 83 ++++++++++++ .../layout/activity_identhub_interaction.xml | 82 ----------- .../layout/activity_identity_selection.xml | 67 --------- 9 files changed, 184 insertions(+), 396 deletions(-) create mode 100644 example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubActivity.kt rename example/src/main/java/de/solarisbank/identhub/example/{ExampleApplication.kt => ExampleIdentHubApplication.kt} (64%) delete mode 100644 example/src/main/java/de/solarisbank/identhub/example/IdentHubInteractionActivity.kt delete mode 100644 example/src/main/java/de/solarisbank/identhub/example/IdentitySelectionActivity.kt create mode 100644 example/src/main/res/layout/activity_example_identhub.xml delete mode 100644 example/src/main/res/layout/activity_identhub_interaction.xml delete mode 100644 example/src/main/res/layout/activity_identity_selection.xml diff --git a/.gitignore b/.gitignore index e2a6a590..346a088a 100644 --- a/.gitignore +++ b/.gitignore @@ -41,23 +41,24 @@ proguard/ # Android Studio captures folder captures/ -# IntelliJ +#General .DS_Store -*.iml + +# IntelliJ .idea/workspace.xml .idea/tasks.xml -.idea/gradle.xml .idea/assetWizardSettings.xml .idea/dictionaries .idea/libraries -# Android Studio 3 in .gitignore file. .idea/caches .idea/modules.xml -# Comment next line if keeping position of elements in Navigation Editor is relevant for you .idea/navEditor.xml .idea/misc.xml .idea/jarRepositories.xml -.DS_Store +.idea/deploymentTargetDropDown.xml +.idea/compiler.xml +gradle.xml +*.iml # Keystore files # Uncomment the following lines if you do not want to check your keystore files in. diff --git a/example/src/main/AndroidManifest.xml b/example/src/main/AndroidManifest.xml index a913664a..3a8aee8e 100644 --- a/example/src/main/AndroidManifest.xml +++ b/example/src/main/AndroidManifest.xml @@ -6,13 +6,13 @@ - + @@ -34,10 +34,6 @@ android:host="person-onboarding.solaris-staging.de" /> - - - \ No newline at end of file diff --git a/example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubActivity.kt b/example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubActivity.kt new file mode 100644 index 00000000..b02d2ebd --- /dev/null +++ b/example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubActivity.kt @@ -0,0 +1,88 @@ +package de.solarisbank.identhub.example + +import android.graphics.Color +import android.os.Bundle +import android.view.View +import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.widget.ConstraintLayout +import de.solarisbank.identhub.example.databinding.ActivityExampleIdenthubBinding +import de.solarisbank.identhub.session.IdentHub +import de.solarisbank.identhub.session.feature.IdentHubSessionFailure +import de.solarisbank.identhub.session.feature.IdentHubSessionResult +import timber.log.Timber + +class ExampleIdentHubActivity : AppCompatActivity() { + private lateinit var binding: ActivityExampleIdenthubBinding + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = ActivityExampleIdenthubBinding.inflate(layoutInflater) + val view: ConstraintLayout = binding.root + setContentView(view) + + prefillSessionUrl() + binding.startButton.setOnClickListener { + setLoadingState() + IdentHub.sessionWithUrl(binding.sessionInputField.text.toString().trim()) + .apply { + onCompletionCallback( + fragmentActivity = this@ExampleIdentHubActivity, + successCallback = this@ExampleIdentHubActivity::onSuccess, + errorCallback = this@ExampleIdentHubActivity::onFailure, + confirmationSuccessCallback = this@ExampleIdentHubActivity::onConfirmationSuccess + ) + start() + } + } + } + + private fun setLoadingState() { + binding.startButton.isEnabled = false + binding.progressBar.visibility = View.VISIBLE + } + + private fun setResultState() { + binding.startButton.isEnabled = true + binding.progressBar.visibility = View.INVISIBLE + } + + private fun onSuccess(result: IdentHubSessionResult) { + setResultState() + val identificationId = result.identificationId + Timber.d("onSuccess; IdentHubSessionResult identification id: $identificationId") + binding.callbackResult.text = "onSuccess called" + binding.callbackResult.setTextColor(Color.GREEN) + } + + private fun onConfirmationSuccess(result: IdentHubSessionResult) { + setResultState() + Timber.d("onConfirmationSuccess") + binding.callbackResult.text = "onConfirmationSuccess called, identification id: ${result.identificationId}" + binding.callbackResult.setTextColor(Color.BLUE) + } + + private fun onFailure(failure: IdentHubSessionFailure) { + setResultState() + val message = failure.message + Timber.d("onFailure; IdentHubSessionFailure identification has not completed: $message") + binding.callbackResult.text = "onFailure called" + binding.callbackResult.setTextColor(Color.RED) + } + + override fun onDestroy() { + IdentHub.clear() + super.onDestroy() + } + + private fun prefillSessionUrl() { + if (!intent.dataString.isNullOrEmpty()) { + intent.dataString + } else { + BuildConfig.SESSION_URL + }?.let { sessionUrl -> + if (sessionUrl != "null") { + binding.sessionInputField.setText(sessionUrl) + } + } + } +} \ No newline at end of file diff --git a/example/src/main/java/de/solarisbank/identhub/example/ExampleApplication.kt b/example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubApplication.kt similarity index 64% rename from example/src/main/java/de/solarisbank/identhub/example/ExampleApplication.kt rename to example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubApplication.kt index ce1ee6eb..cd6491e8 100644 --- a/example/src/main/java/de/solarisbank/identhub/example/ExampleApplication.kt +++ b/example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubApplication.kt @@ -3,12 +3,13 @@ package de.solarisbank.identhub.example import android.app.Application import timber.log.Timber -class ExampleApplication : Application() { +@Suppress("unused") +class ExampleIdentHubApplication : Application() { override fun onCreate() { super.onCreate() -// if(BuildConfig.DEBUG){ + if(BuildConfig.DEBUG){ Timber.plant(Timber.DebugTree()) -// } + } } } \ No newline at end of file diff --git a/example/src/main/java/de/solarisbank/identhub/example/IdentHubInteractionActivity.kt b/example/src/main/java/de/solarisbank/identhub/example/IdentHubInteractionActivity.kt deleted file mode 100644 index fb5d0234..00000000 --- a/example/src/main/java/de/solarisbank/identhub/example/IdentHubInteractionActivity.kt +++ /dev/null @@ -1,127 +0,0 @@ -package de.solarisbank.identhub.example - -import android.os.Bundle -import android.view.View -import androidx.appcompat.app.AppCompatActivity -import androidx.constraintlayout.widget.ConstraintLayout -import de.solarisbank.identhub.example.databinding.ActivityIdenthubInteractionBinding -import de.solarisbank.identhub.session.IdentHub -import de.solarisbank.identhub.session.feature.IdentHubSessionFailure -import de.solarisbank.identhub.session.feature.IdentHubSessionResult -import timber.log.Timber - -class IdentHubInteractionActivity : AppCompatActivity() { - private lateinit var binding: ActivityIdenthubInteractionBinding - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - binding = ActivityIdenthubInteractionBinding.inflate(layoutInflater) - val view: ConstraintLayout = binding.root - setContentView(view) - Timber.d("onCreate, intent.getStringExtra(IdentHub.SESSION_URL_KEY) : ${intent.getStringExtra( - IdentHub.SESSION_URL_KEY)}") - - binding.startButton.setOnClickListener { - setLoadingState() - IdentHub.sessionWithUrl(intent.getStringExtra(IdentHub.SESSION_URL_KEY)!!) - .apply { - onCompletionCallback( - fragmentActivity = this@IdentHubInteractionActivity, - successCallback = this@IdentHubInteractionActivity::onSuccess, - errorCallback = this@IdentHubInteractionActivity::onFailure - ) - onPaymentCallback(this@IdentHubInteractionActivity::onPayment) - start() - } - } - binding.resumeButton.setOnClickListener { - setLoadingState() - IdentHub.sessionWithUrl(intent.getStringExtra(IdentHub.SESSION_URL_KEY)!!) - .apply { - onCompletionCallback( - fragmentActivity = this@IdentHubInteractionActivity, - successCallback = this@IdentHubInteractionActivity::onSuccess, - errorCallback = this@IdentHubInteractionActivity::onFailure - ) - onPaymentCallback(this@IdentHubInteractionActivity::onPayment) - resume() - } - } - binding.startButtonWithoutOnPayment.setOnClickListener { - setLoadingState() - IdentHub.sessionWithUrl(intent.getStringExtra(IdentHub.SESSION_URL_KEY)!!) - .apply { - onCompletionCallback( - fragmentActivity = this@IdentHubInteractionActivity, - successCallback = this@IdentHubInteractionActivity::onSuccess, - errorCallback = this@IdentHubInteractionActivity::onFailure, - confirmationSuccessCallback = this@IdentHubInteractionActivity::onConfirmationSuccess, - ) - /* - onPaymentCallback is not set here - */ - start() - } - } - } - - private fun setLoadingState() { - binding.startButton.isEnabled = false - binding.resumeButton.isEnabled = false - binding.startButtonWithoutOnPayment.isEnabled = false - binding.progressBar.visibility = View.VISIBLE - } - - private fun setResultState() { - binding.startButton.isEnabled = true - binding.resumeButton.isEnabled = false - binding.startButtonWithoutOnPayment.isEnabled = true - binding.progressBar.visibility = View.INVISIBLE - } - - private fun setOnPaymentResultState() { - binding.startButton.isEnabled = false - binding.resumeButton.isEnabled = true - binding.startButtonWithoutOnPayment.isEnabled = false - binding.progressBar.visibility = View.INVISIBLE - } - - private fun onSuccess(result: IdentHubSessionResult) { - setResultState() - val identificationId = result.identificationId - Timber.d("onSuccess; IdentHubSessionResult identification id: $identificationId") - binding.callbackResult.setText("onSuccess called") - // Do something else. - } - - private fun onPayment(result: IdentHubSessionResult) { - setOnPaymentResultState() - val identificationId = result.identificationId - Timber.d("onPayment; IdentHubSessionResult identification id: $identificationId") - binding.callbackResult.setText("onPayment called") - // Do something else. - } - - private fun onConfirmationSuccess(result: IdentHubSessionResult) { - setResultState() - Timber.d("onConfirmationSuccess") - binding.callbackResult.setText("onConfirmationSuccess called, identification id: ${result.identificationId}") - } - - private fun onFailure(failure: IdentHubSessionFailure) { - setResultState() - val message = failure.message - Timber.d("onFailure; IdentHubSessionFailure identification has not completed: $message") - binding.callbackResult.setText("onFailure called") - // Continue after failed identification. - } - - override fun onDestroy() { - IdentHub.clear() - super.onDestroy() - } - - companion object { - const val TAG = "MainActivity" - } -} \ No newline at end of file diff --git a/example/src/main/java/de/solarisbank/identhub/example/IdentitySelectionActivity.kt b/example/src/main/java/de/solarisbank/identhub/example/IdentitySelectionActivity.kt deleted file mode 100644 index bc22acb2..00000000 --- a/example/src/main/java/de/solarisbank/identhub/example/IdentitySelectionActivity.kt +++ /dev/null @@ -1,105 +0,0 @@ -package de.solarisbank.identhub.example - -import android.content.Context -import android.content.Intent -import android.content.SharedPreferences -import android.os.Bundle -import android.text.Editable -import android.text.TextWatcher -import androidx.appcompat.app.AppCompatActivity -import androidx.constraintlayout.widget.ConstraintLayout -import de.solarisbank.identhub.example.databinding.ActivityIdentitySelectionBinding -import de.solarisbank.identhub.session.IdentHub.SESSION_URL_KEY -import de.solarisbank.identhub.session.feature.utils.buildApiUrl -import de.solarisbank.identhub.session.feature.utils.isFourthlineModuleAvailable -import timber.log.Timber - - -class IdentitySelectionActivity : AppCompatActivity() { - - private lateinit var binding: ActivityIdentitySelectionBinding - private lateinit var urlPreferences: SharedPreferences - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - binding = ActivityIdentitySelectionBinding.inflate(layoutInflater) - val view: ConstraintLayout = binding.root - setContentView(view) - initView() - checkIsFourthlineAvailable() - } - - private fun checkIsFourthlineAvailable() { - if (isFourthlineModuleAvailable(this)) { - startActivity( - Intent(this, IdentHubInteractionActivity::class.java) - .apply { - putExtra(SESSION_URL_KEY, urlPreferences.getString(URL_VALUE,"")) - } - ) - finish() - } - } - - private fun initView() { - Timber.d("initView()") - urlPreferences = getSharedPreferences(URL_PREFERENCES, Context.MODE_PRIVATE) - binding.sessionInputField.addTextChangedListener(object : TextWatcher { - - override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { - Timber.d("beforeTextChanged") - } - - override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { - Timber.d("onTextChanged") - if (s.isNullOrEmpty()) { - Timber.d("onTextChanged 2") - binding.fourthlineFlowButton.isEnabled = false - binding.identHubFlowButton.isEnabled = false - } else { - Timber.d("onTextChanged 3") - urlPreferences.edit().putString(URL_VALUE, s.toString()).apply() - binding.fourthlineFlowButton.isEnabled = true - binding.identHubFlowButton.isEnabled = true - } - } - - override fun afterTextChanged(s: Editable?) { - Timber.d("afterTextChanged") - } - }) - - if (intent.dataString.isNullOrEmpty()) { - urlPreferences.getString(URL_VALUE, null)?.let { - binding.sessionInputField.setText(it) - }.run { - binding.sessionInputField.setText(BuildConfig.SESSION_URL) - } - } else { - binding.sessionInputField.setText(intent.dataString) - } - - binding.identHubFlowButton.setOnClickListener { - Timber.d("initView(), urlPreferences.getString(URL_VALUE,\"\"): ${urlPreferences.getString(URL_VALUE,"")}") - startActivity(Intent(this, IdentHubInteractionActivity::class.java) - .apply { - putExtra(SESSION_URL_KEY, urlPreferences.getString(URL_VALUE,"")) - }) - } - - binding.fourthlineFlowButton.setOnClickListener { - startActivity(Intent().apply { - action = FOURTHLINE_FLOW_ACTIVITY_ACTION - putExtra(SESSION_URL_KEY, buildApiUrl(urlPreferences.getString(URL_VALUE,"")!!)) - }) - } - - } - - companion object { - private const val FOURTHLINE_FLOW_ACTIVITY_ACTION = "de.solarisbank.identhub.FOURTHLINE_FLOW" - private const val URL_PREFERENCES = "URL_PREFERENCES" - private const val URL_VALUE = "URL_VALUE" - } - -} \ No newline at end of file diff --git a/example/src/main/res/layout/activity_example_identhub.xml b/example/src/main/res/layout/activity_example_identhub.xml new file mode 100644 index 00000000..850cf447 --- /dev/null +++ b/example/src/main/res/layout/activity_example_identhub.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + +