Skip to content

Commit

Permalink
Make the example app dead simple (#326)
Browse files Browse the repository at this point in the history
* 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 <julian.dreissig@solarisbank.de>
  • Loading branch information
mblcdr and thirtified authored Apr 14, 2022
1 parent 35ec126 commit 43f21db
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 396 deletions.
13 changes: 7 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<application
android:allowBackup="false"
android:name=".ExampleApplication"
android:name=".ExampleIdentHubApplication"
android:icon="@mipmap/ic_launcher"
android:label="@string/identhub_app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MaterialComponents.Light.NoActionBar.Bridge">
<activity android:name=".IdentitySelectionActivity">
<activity android:name=".ExampleIdentHubActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand All @@ -34,10 +34,6 @@
android:host="person-onboarding.solaris-staging.de" />
</intent-filter>
</activity>
<activity android:name=".IdentHubInteractionActivity"
android:exported="false">
</activity>

</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
// }
}
}
}

This file was deleted.

Loading

0 comments on commit 43f21db

Please sign in to comment.