-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 <julian.dreissig@solarisbank.de>
- Loading branch information
1 parent
35ec126
commit 43f21db
Showing
9 changed files
with
184 additions
and
396 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
example/src/main/java/de/solarisbank/identhub/example/ExampleIdentHubActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 0 additions & 127 deletions
127
example/src/main/java/de/solarisbank/identhub/example/IdentHubInteractionActivity.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.