Interfaces I have to extend in my Activity
IEnrollmentUseCase,IValidationUseCase:
class EnrollmentActivity : AppCompatActivity() , IEnrollmentUseCase, IValidationUseCase {
In the IEnrollmentUseCase interface you must override the following methods, they will be called internally to control the validation status:
- fun doAfterEnrollmentStarted()
- fun doAfterEnrollmentFinished(pinVerificationID: String)
- fun showErrorEnrollment(exception: BioException)
interface IEnrollmentUseCase {
val enrollmentUseCase : EnrollmentUseCase
fun doAfterEnrollmentStarted()
fun doAfterEnrollmentFinished(pinVerificationID: String)
fun showErrorEnrollment(exception: BioException)
}
In the IValidationUseCase interface you must override the following methods, they will be called internally to control the validation status:
- fun doAfterValidationStarted()
- fun doAfterFieldValidating(field: Field)
- fun doAfterFieldValidated(field: Field)
- fun doAfterValidationFinished()
- fun showErrorValidation(exception: BioException)
interface IValidationUseCase {
val enrollmentUseCase : EnrollmentUseCase
fun doAfterValidationStarted()
fun doAfterFieldValidating(field: Field)
fun doAfterFieldValidated(field: Field)
fun doAfterValidationFinished()
fun showErrorValidation(exception: BioException)
sealed class Field {
object Email: Field()
object Phone: Field()
}
}
How to integrate user registration?
This is a use case that allows, by means of a call, to create or recover an account from a user depending on whether it is already created in the Biocryptology database.
- Call: enrollmentUseCase.enrollment(user)
- Input parameter: User() object with {email, prefix, phone, name, lastName} fields.
- locale is a non-mandatory field, if no argument is passed it will be set to English by default.
binding.btnSend.setOnClickListener {
hideKeyboard()
val user = EnrollmentUseCase.User(
binding.etEmail.text.toString(),
34,
binding.etPhone.text.toString(),
binding.etName.text.toString(),
binding.etLastName.text.toString(),
locale = getLocale())
enrollmentUseCase.enrollment(user)
}
The EnrollmentUseCase and ValidationUseCase interfaces shall trigger events reporting the status of the registration:
interface IEnrollmentUseCase {
|
interface IValidationUseCase { |
Once the enrollment has been completed, the overwritten doAfterEnrollmentFinished method is skipped and, at this point, we will know that the enrollment has been successfully completed.
Use case that allows to see the state of the validation of the pin with the following states
- PIN { AccountCreated, EmailValidating, PhoneValidating, Error}
sealed class PinStatus {
object AccountCreated: PinStatus()
object PhoneValidating: PinStatus()
object EmailValidating: PinStatus()
data class Error(val error: BioException): PinStatus()
}
Do we know the registration status when starting the app from 0?
You can store in BioSharedPreferences the User object of the user and query the userStatus method with the email and phone fields and it will return the validation status of the user:
bioSharedPreferences.currentUser?.let {
PublicDataSource(bioSharedPreferences).userStatus(it.email?:"",it.mobilePhone?:"") { status ->
when (status) {
PublicDataSource.EnrollmentStatus.ValidateEmail -> {
enrollmentUseCase.validate()
validatingField(IValidationUseCase.Field.Email)
}
PublicDataSource.EnrollmentStatus.ValidatePhone -> {
enrollmentUseCase.validate()
validatingField(IValidationUseCase.Field.Phone)
}
PublicDataSource.EnrollmentStatus.AccountCreated -> {
// Enrollment success
}
PublicDataSource.EnrollmentStatus.Enrollment -> {
// Init enrollment
}
PublicDataSource.EnrollmentStatus.Error -> {
// Error
}
}
}
}