Skip to content

Examples

Fi5t edited this page Nov 5, 2020 · 3 revisions

Using blacklists

This library has an inner blacklist of the most frequently PINs

val DEFAULT_BLACKLIST = listOf(
    "1234", // Freq: 10.713%
    "1111", // Freq: 6.016%
    "0000", // Freq: 1.881%
    "1212" // Freq: 1.197%
)

And you can use it as follows:

val pinkman = Pinkman(applicationContext, pinBlacklist = Pinkman.DEFAULT_BLACKLIST)

try {
    pinkman.createPin("0000")
} catch(e: BlacklistedPinException) {
    shameTheUser()
}

Sometimes, you may need to expand or even replace this list with your own.

val pinkman = Pinkman(applicationContext, pinBlacklist = Pinkman.DEFAULT_BLACKLIST + listOf("8557", "2392", "6930"))
val pinkman = Pinkman(applicationContext, pinBlacklist = listOf("8557", "2392", "6930"))

Using coroutines

val pinIsCreated = MutableLiveData<Boolean>()

fun createPin(pin: String) {
    viewModelScope.launch {
        pinkman.createPinAsync(pin)
        pinIsCreated.value = true
    }
}
val pinIsValid = MutableLiveData<Boolean>()

fun validatePin(pin: String) {
    viewModelScope.launch {
        pinIsValid.value = pinkman.isValidPinAsync(pin)
    }
}

Using RxJava

TBD

Clone this wiki locally