I have developed one app in JAVA. Now I have made one function for firebase related calls. and Working perfectly. But now I want to convert that function to kotlin also. But I was confused about how to use that function call in kotlin.
Function of Java :
public static void firebaseAuth(FirebaseAuth auth, AuthCredential authCredential, Function<Object, Void> delegate) {
auth.signInWithCredential(authCredential).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
delegate.apply(auth.getCurrentUser());
} else {
delegate.apply(task.getException());
}
});
}
Use of this Function in Java :
FireSignInHelper.firebaseAuth(mFireAuth, authCredential, o -> {
if (o instanceof Exception) {
signIn_UnSuccessful((Exception) o);
} else if (o instanceof FirebaseUser) {
FirePacket firePacket = new FirePacket();
firePacket.setProvider(provider);
firePacket.setToken(((FirebaseUser) o).getUid());
firePacket.setFirebaseUser((FirebaseUser) o);
signIn_Successful(firePacket);
}
return null;
});
Converted Function In Kotlin :
fun firebaseAuth(auth: FirebaseAuth,
authCredential: AuthCredential?,
delegate: Function<Any?, Void?>
) {
auth.signInWithCredential(authCredential!!)
.addOnCompleteListener { task: Task<AuthResult?> ->
if (task.isSuccessful) {
delegate.apply(auth.currentUser)
} else {
delegate.apply(task.exception)
}
}
}
Use Converted function in kotlin:
I want to know this answer. Because I have try through Android studio but the compiler didn't convert properly. So I want to know how to use this function in kotlin.
Thanks In advance.