ActivityKt.kt 938 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
package chat.rocket.android.helper

import android.app.Activity
import android.content.Intent
import androidx.fragment.app.FragmentActivity
import com.google.android.gms.auth.api.credentials.Credential
import com.google.android.gms.auth.api.credentials.Credentials

fun FragmentActivity.saveCredentials(id: String, password: String) {
    val credentialsClient = Credentials.getClient(this)
    SmartLockHelper.save(credentialsClient, this, id, password)
}

fun Activity.requestStoredCredentials(): Pair<String, String>? {
    val credentialsClient = Credentials.getClient(this)
    return SmartLockHelper.requestStoredCredentials(credentialsClient, this)?.let {
        null
    }
}

fun getCredentials(data: Intent): Pair<String, String>? {
    val credentials: Credential = data.getParcelableExtra(Credential.EXTRA_KEY)
23 24
    return credentials.password?.let {
        Pair(credentials.id, it)
25 26 27 28
    }
}

fun hasCredentialsSupport() = true