I am using MVVM. I want to implement Firebase Auth in app. But to implement it I need an activity context in my repo class. How can I get it from ViewModel or is there any simple method available?
Here is the firebase code I need to implement:
PhoneAuthProvider.getInstance().verifyPhoneNumber("+91"+phone, // Phone number to verify
60, // Timeout duration
TimeUnit.SECONDS, // Unit of timeout
(Activity) context, // Activity (for callback binding)
new PhoneAuthProvider.OnVerificationStateChangedCallbacks() {
@Override
public void onVerificationCompleted(@NonNull PhoneAuthCredential phoneAuthCredential)
{
signInWithPhoneAuthCredential((Activity)context,phoneAuthCredential);
}
@Override
public void onVerificationFailed(@NonNull FirebaseException e) {
setLoginFailed(e);
}
@Override
public void onCodeSent(@NonNull String s, @NonNull
PhoneAuthProvider.ForceResendingToken forceResendingToken) {
super.onCodeSent(s, forceResendingToken);
loginResponse.setOnProgress(false);
loginResponse.setStatus(true);
loginResponse.setCodeVerified(false);
loginResponseLiveData.setValue(loginResponse);
verificationId =s;
}
});