private void SendVerificationCode() { auth = SessionManager.GetFirebaseAuth(); PhoneAuthProvider.GetInstance(auth) .VerifyPhoneNumber(phone, 30, TimeUnit.Seconds, Activity, new PhoneVerificationCallbacks( onVerificationCompleted: (cred) => { var code = cred.SmsCode; if (string.IsNullOrEmpty(code)) { return; } otpView.Value = code; VerifyCode(code); }, onVerificationFailed: (e) => { try { resendBtn.Enabled = false; cdTimer.Cancel(); throw e; } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (FirebaseTooManyRequestsException ftmre) { OnboardingActivity.ShowError(ftmre.Source, ftmre.Message); } catch (FirebaseAuthInvalidCredentialsException faice) { OnboardingActivity.ShowError(faice.Source, faice.Message); } catch (FirebaseAuthInvalidUserException fiue) { OnboardingActivity.ShowError(fiue.Source, fiue.Message); } catch (Exception ex) { OnboardingActivity.ShowError(ex.Source, ex.Message); } }, onCodeSent: (code, token) => { verificationId = code; })); }
private void VerifyCode(string code) { OnboardingActivity.ShowLoader(); PhoneAuthCredential cred = PhoneAuthProvider.GetCredential(verificationId, code); auth.SignInWithCredential(cred) .AddOnCompleteListener(new OncompleteListener( onComplete: (t) => { try { switch (t.IsSuccessful) { case false: throw t.Exception; default: CheckUserAvailability(); break; } } catch (FirebaseAuthInvalidCredentialsException fiace) { OnboardingActivity.DismissLoader(); OnboardingActivity.ShowError(fiace.Source, fiace.Message); } catch (FirebaseTooManyRequestsException ftmre) { OnboardingActivity.DismissLoader(); OnboardingActivity.ShowError(ftmre.Source, ftmre.Message); } catch (FirebaseAuthInvalidUserException fiue) { OnboardingActivity.DismissLoader(); OnboardingActivity.ShowError(fiue.Source, fiue.Message); } catch (FirebaseNetworkException) { OnboardingActivity.DismissLoader(); OnboardingActivity.ShowNoNetDialog(false); } catch (Exception e) { OnboardingActivity.DismissLoader(); OnboardingActivity.ShowError(e.Source, e.Message); } })); }
public override void OnReceive(Context context, Intent intent) { try { if (IsOnline(context)) { OnboardingActivity.ShowNoNetDialog(true); } else { OnboardingActivity.ShowNoNetDialog(false); } } catch (NullPointerException e) { Log.Error("labs", e.Message); } }
public override void OnReceive(Context context, Intent intent) { if (intent == null || intent.Extras == null) { return; } var connManager = context.GetSystemService(Context.ConnectivityService) as ConnectivityManager; connManager.RegisterDefaultNetworkCallback(new DefaultNetCallback( (net, capa) => { var connected = capa.HasCapability(NetCapability.Internet); OnboardingActivity.ShowNoNetDialog(connected); }, (net) => { OnboardingActivity.ShowNoNetDialog(false); })); }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); SubmitBtn = view.FindViewById <MaterialButton>(Resource.Id.drv_signup_sbmtbtn); FnameText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_fname_et); LnameText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_lname_et); EmailText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_email_et); PhoneText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_phone_et); CodeText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_code_et); PassText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signup_pass_et); CityText = view.FindViewById <AppCompatAutoCompleteTextView>(Resource.Id.autocity_et); var regAppBar = view.FindViewById <AppBarLayout>(Resource.Id.signup_appbar); var toolbar = regAppBar.FindViewById <AndroidX.AppCompat.Widget.Toolbar>(Resource.Id.main_toolbar); toolbar.Title = "Register"; toolbar.InflateMenu(Resource.Menu.help_menu); toolbar.MenuItemClick += Toolbar_MenuItemClick; FnameText.EditText.AfterTextChanged += EditText_AfterTextChanged; LnameText.EditText.AfterTextChanged += EditText_AfterTextChanged; PassText.EditText.AfterTextChanged += EditText_AfterTextChanged; EmailText.EditText.AfterTextChanged += EditText_AfterTextChanged; PhoneText.EditText.AfterTextChanged += EditText_AfterTextChanged; var adapter = ArrayAdapterClass.CreateArrayAdapter(Activity, names); CityText.Adapter = adapter; CityText.AfterTextChanged += EditText_AfterTextChanged; SubmitBtn.Click += (s1, e1) => { //open progress OnboardingActivity.ShowProgressDialog(); fname = FnameText.EditText.Text; lname = LnameText.EditText.Text; email = EmailText.EditText.Text; phone = PhoneText.EditText.Text; city = CityText.Text; code = CodeText.EditText.Text; AppDataHelper.GetFirebaseAuth().CreateUserWithEmailAndPassword(email, PassText.EditText.Text) .AddOnCompleteListener(new OnCompleteListener(t => { if (!t.IsSuccessful) { try { OnboardingActivity.CloseProgressDialog(); throw t.Exception; } catch (FirebaseAuthInvalidCredentialsException) { OnboardingActivity.ShowErrorDialog("The email or password is not correct"); } catch (FirebaseAuthUserCollisionException) { ShowEmailExistsDialog(); } catch (FirebaseAuthInvalidUserException) { OnboardingActivity.ShowErrorDialog("User invalid"); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (Exception) { OnboardingActivity.ShowErrorDialog("Your request could not be completed at this time"); } } else { SaveDriverToDb(); } })); }; }
public override void OnViewCreated(View view, Bundle savedInstanceState) { base.OnViewCreated(view, savedInstanceState); var emailText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signin_email_et); var passText = view.FindViewById <TextInputLayout>(Resource.Id.drv_signin_pass_et); var forgotPassBtn = view.FindViewById <MaterialButton>(Resource.Id.btn_forgot_pass); forgotPassBtn.Click += (s1, e1) => { ForgotPassFragment passFragment = new ForgotPassFragment(); AndroidX.Fragment.App.FragmentTransaction ft = ChildFragmentManager.BeginTransaction(); ft.Add(passFragment, "forgot_pass_fragment"); ft.CommitAllowingStateLoss(); }; var continueFab = view.FindViewById <FloatingActionButton>(Resource.Id.fab1); continueFab.Click += (s2, e2) => { bool enabled = !(!Patterns.EmailAddress.Matcher(emailText.EditText.Text).Matches() || passText.EditText.Text.Length < 8); switch (enabled) { case false: Toast.MakeText(Activity, "A valid email and password is required", ToastLength.Short).Show(); break; default: { //showProgress OnboardingActivity.ShowProgressDialog(); AppDataHelper.GetFirebaseAuth().SignInWithEmailAndPassword(emailText.EditText.Text, passText.EditText.Text) .AddOnCompleteListener(new OnCompleteListener(t => { if (t.IsSuccessful) { var dataRef = AppDataHelper.GetDatabase().GetReference("Drivers/" + AppDataHelper.GetCurrentUser().Uid); dataRef.AddValueEventListener(new SingleValueListener(d => { if (!d.Exists()) { return; } var stage = (d.Child(StringConstants.StageofRegistration) != null) ? d.Child(StringConstants.StageofRegistration).Value.ToString() : ""; if (stage != $"{RegistrationStage.RegistrationDone}") { editor = preferences.Edit(); editor.PutString("firstRun", "reg"); editor.Commit(); OnboardingActivity.CloseProgressDialog(); onRegUncompleteListener?.Invoke(this, new RegUncompleteArgs { StageReached = stage }); } else { editor = preferences.Edit(); editor.PutString("firstRun", "regd"); editor.Commit(); var intent = new Intent(Context, typeof(MainActivity)); intent.SetFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask); StartActivity(intent); } }, e => { try { OnboardingActivity.CloseProgressDialog(); throw t.Exception; } catch (DatabaseException) { OnboardingActivity.ShowErrorDialog("Database exeption"); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (Exception) { OnboardingActivity.ShowErrorDialog("Something went wrong, please retry"); } })); } else { try { OnboardingActivity.CloseProgressDialog(); throw t.Exception; } catch (FirebaseAuthInvalidCredentialsException) { OnboardingActivity.ShowErrorDialog("Your email or password is incorrect. Please try again."); } catch (FirebaseAuthInvalidUserException) { OnboardingActivity.ShowErrorDialog("We can't find an account with this email address. Please try again or create a new account."); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (Exception) { OnboardingActivity.ShowErrorDialog("We couldn't sign you in at this time. Please retry"); } } })); break; } } }; }
private async void SaveToDb() { try { var profileRef = SessionManager.GetFireDB().GetReference($"users/{SessionManager.UserId}/profile"); var userMap = new HashMap(); var stream = new System.IO.MemoryStream(); var bitmap = MediaStore.Images.Media.GetBitmap(Context.ContentResolver, img_uri); await bitmap.CompressAsync(Bitmap.CompressFormat.Webp, 90, stream); var imgArray = stream.ToArray(); var imageRef = FirebaseStorage.Instance.GetReference($"profileImages/{SessionManager.UserId}"); imageRef.PutBytes(imgArray).ContinueWithTask(new ContinuationTask( then: t => { if (!t.IsSuccessful) { throw t.Exception; } })).AddOnCompleteListener(new OncompleteListener( onComplete: t => { if (!t.IsSuccessful) { throw t.Exception; } userMap.Put(Constants.SNAPSHOT_FNAME, fullnameEt.EditText.Text); userMap.Put(Constants.SNAPSHOT_EMAIL, emailEt.EditText.Text); userMap.Put(Constants.SNAPSHOT_GENDER, (int)userGender); userMap.Put(Constants.SNAPSHOT_PHONE, SessionManager.GetFirebaseAuth().CurrentUser.PhoneNumber); userMap.Put(Constants.SNAPSHOT_PHOTO_URL, t.Result.ToString()); profileRef.SetValue(userMap).AddOnCompleteListener(new OncompleteListener( onComplete: task => { try { if (!task.IsSuccessful) { throw task.Exception; } GetSmsFragment.SetStatus("set_partner"); ParentFragmentManager.BeginTransaction() .Replace(Resource.Id.frag_container, new PartnerFragment()) .CommitAllowingStateLoss(); } catch (DatabaseException de) { OnboardingActivity.ShowError("Database Exception", de.Message); } })); profileRef.KeepSynced(true); })); } catch (DatabaseException fde) { OnboardingActivity.ShowError("Database Exception", fde.Message); } catch (FirebaseNetworkException) { OnboardingActivity.ShowNoNetDialog(false); } catch (StorageException se) { OnboardingActivity.ShowError("Storage Exception", se.Message); } catch (Exception ex) { OnboardingActivity.ShowError("Exception", ex.Message); } }