Exemplo n.º 1
0
 private void SaveCarDetailsToDb(HashMap carMap)
 {
     if (AppDataHelper.GetCurrentUser() != null)
     {
         var vehicleRef = AppDataHelper.GetDatabase().GetReference($"Drivers/{AppDataHelper.GetCurrentUser().Uid}/MyCars");
         vehicleRef.SetValue(carMap)
         .AddOnSuccessListener(new OnSuccessListener(result =>
         {
             var driverRef = AppDataHelper.GetDatabase().GetReference($"Drivers/{AppDataHelper.GetCurrentUser().Uid}/{StringConstants.StageofRegistration}");
             driverRef.SetValue($"{RegistrationStage.Agreement}")
             .AddOnSuccessListener(new OnSuccessListener(result2 =>
             {
                 CarRegComplete.Invoke(this, new EventArgs());
                 OnboardingActivity.CloseProgressDialog();
             })).AddOnFailureListener(new OnFailureListener(e2 =>
             {
                 OnboardingActivity.CloseProgressDialog();
                 Toast.MakeText(Activity, e2.Message, ToastLength.Short).Show();
             }));
         }))
         .AddOnFailureListener(new OnFailureListener(e1 =>
         {
             OnboardingActivity.CloseProgressDialog();
             Toast.MakeText(Activity, e1.Message, ToastLength.Short).Show();
         }));
     }
     else
     {
         return;
     }
 }
        private void SaveImage()
        {
            picDisplayFragment.DismissAllowingStateLoss();
            var storeRef = FirebaseStorage.Instance.GetReferenceFromUrl("gs://taxiproject-185a4.appspot.com");

            if (AppDataHelper.GetCurrentUser() != null)
            {
                var stream = new MemoryStream();
                bitmap.Compress(Bitmap.CompressFormat.Webp, 80, stream);
                byte[] bitmapArray = stream.ToArray();

                imageRef = storeRef.Child("driverProfilePics/" + AppDataHelper.GetCurrentUser().Uid);
                imageRef.PutBytes(bitmapArray).ContinueWithTask(new ContinuationTask(t =>
                {
                    if (!t.IsSuccessful)
                    {
                        OnboardingActivity.CloseProgressDialog();
                        Toast.MakeText(Activity, t.Exception.Message, ToastLength.Long).Show();
                    }
                })).AddOnCompleteListener(new OnCompleteListener(t =>
                {
                    if (t.IsSuccessful)
                    {
                        var driverRef = AppDataHelper.GetDatabase().GetReference($"Drivers/{AppDataHelper.GetCurrentUser().Uid}");
                        driverRef.Child("profile_img_url").SetValue(t.Result.ToString()).AddOnCompleteListener(new OnCompleteListener(t3 =>
                        {
                            if (!t3.IsSuccessful)
                            {
                                Toast.MakeText(Activity, t3.Exception.Message, ToastLength.Long).Show();
                            }
                            OnboardingActivity.CloseProgressDialog();

                            driverRef.Child(StringConstants.StageofRegistration).SetValue($"{RegistrationStage.CarRegistering}")
                            .AddOnSuccessListener(new OnSuccessListener(r2 =>
                            {
                                ProfileCaptured.Invoke(this, new EventArgs());
                                UpdateUiOnCpture(CaptureType.ProfilePic);
                                OnboardingActivity.CloseProgressDialog();
                            })).AddOnFailureListener(new OnFailureListener(e2 =>
                            {
                                OnboardingActivity.CloseProgressDialog();
                                OnboardingActivity.ShowErrorDialog("Something went wrong, please retry");
                            }));
                        }));
                    }
                    else
                    {
                        OnboardingActivity.CloseProgressDialog();
                        OnboardingActivity.ShowErrorDialog("Something went wrong, please retry");
                    }
                }));
            }
            else
            {
                return;
            }
        }
Exemplo n.º 3
0
        public override void OnViewCreated(View view, Bundle savedInstanceState)
        {
            base.OnViewCreated(view, savedInstanceState);
            var AccountTypeTGroup = view.FindViewById <MaterialButtonToggleGroup>(Resource.Id.drv_part_tggl_grp);
            var InfoImgSwitcher   = view.FindViewById <ImageSwitcher>(Resource.Id.drv_part_img_swtchr1);
            var InfoTSwitcher     = view.FindViewById <TextSwitcher>(Resource.Id.drv_part_txt_swtchr1);
            var ContinueBtn       = view.FindViewById <MaterialButton>(Resource.Id.drv_part_cnt_btn);

            InitSwitchers(InfoImgSwitcher, InfoTSwitcher);

            AccountTypeTGroup.AddOnButtonCheckedListener(new OnButtonChecked(id =>
            {
                switch (id)
                {
                case Resource.Id.drv_tggl_partner_btn:
                    partner = true;
                    InfoTSwitcher.SetText(GetString(Resource.String.partner_desc_txt));
                    InfoImgSwitcher.SetImageResource(Resource.Drawable.driver_pablo);
                    break;

                case Resource.Id.drv_tggl_driver_btn:
                    partner = false;
                    InfoTSwitcher.SetText(GetString(Resource.String.driving_desc_txt));
                    InfoImgSwitcher.SetImageResource(Resource.Drawable.driver_pablo);
                    break;
                }
            }));


            ContinueBtn.Click += (s1, e1) =>
            {
                if (AppDataHelper.GetCurrentUser() != null)
                {
                    OnboardingActivity.ShowProgressDialog();
                    var driverRef = AppDataHelper.GetDatabase().GetReference($"Drivers/{AppDataHelper.GetCurrentUser().Uid}");
                    driverRef.Child("isPartner").SetValue(partner.ToString())
                    .AddOnSuccessListener(new OnSuccessListener(r1 =>
                    {
                        driverRef.Child(StringConstants.StageofRegistration).SetValue(RegistrationStage.Capturing.ToString())
                        .AddOnSuccessListener(new OnSuccessListener(r2 =>
                        {
                            PartnerTypeComplete.Invoke(this, new PartnerEventArgs {
                                IsPartnerComplete = true
                            });
                            OnboardingActivity.CloseProgressDialog();
                        }))
                        .AddOnFailureListener(new OnFailureListener(e1 => { OnboardingActivity.CloseProgressDialog(); }));
                    }))
                    .AddOnFailureListener(new OnFailureListener(e1 => { OnboardingActivity.CloseProgressDialog(); }));
                }
                else
                {
                    Toast.MakeText(Activity, "Something aint right", ToastLength.Short).Show();
                }
            };
        }
        private void SaveDriverToDb()
        {
            var DriverRef = AppDataHelper.GetDatabase().GetReference($"Drivers/{ AppDataHelper.GetCurrentUser().Uid}");

            HashMap compliments = new HashMap();

            compliments.Put("cool_car", "0");
            compliments.Put("neat_and_tidy", "0");
            compliments.Put("expert_navigation", "0");
            compliments.Put("awesome_music", "0");
            compliments.Put("made_me_laugh", "0");

            HashMap driverMap = new HashMap();

            driverMap.Put("fname", fname);
            driverMap.Put("lname", lname);
            driverMap.Put("email", email);
            driverMap.Put("phone", phone);
            driverMap.Put("city", city);
            driverMap.Put("invitecode", code);
            driverMap.Put("ratings", "0");
            driverMap.Put("compliments", compliments);
            driverMap.Put("created_at", DateTime.UtcNow.ToString());



            DriverRef.SetValue(driverMap)
            .AddOnSuccessListener(new OnSuccessListener(r =>
            {
                DriverRef.Child(StringConstants.StageofRegistration).SetValue(RegistrationStage.Partnering.ToString())
                .AddOnSuccessListener(new OnSuccessListener(r2 =>
                {
                    OnboardingActivity.CloseProgressDialog();
                    SignUpSuccess.Invoke(this, new SignUpSuccessArgs {
                        IsCompleted = true
                    });
                }))
                .AddOnFailureListener(new OnFailureListener(e1 =>
                {
                    OnboardingActivity.CloseProgressDialog();
                    Toast.MakeText(Activity, e1.Message, ToastLength.Short).Show();
                }));
            }))
            .AddOnFailureListener(new OnFailureListener(e =>
            {
                OnboardingActivity.ShowErrorDialog("Something went wrong, please retry");
            }));
        }
 private void DetectedResponse(Bitmap bitmap, SparseArray faces)
 {
     if (faces.Size() < 1)
     {
         OnboardingActivity.CloseProgressDialog();
         OnboardingActivity.ShowErrorDialog("No face in photo");
     }
     else if (faces.Size() == 1)
     {
         SaveImage();
     }
     else if (faces.Size() > 1)
     {
         OnboardingActivity.CloseProgressDialog();
         OnboardingActivity.ShowErrorDialog("More than one face detected");
     }
 }
Exemplo n.º 6
0
        private void InitControls(View view)
        {
            var visit_btn = view.FindViewById <MaterialButton>(Resource.Id.visit_site_btn);
            var skip_btn  = view.FindViewById <MaterialButton>(Resource.Id.skip_btn);

            skip_btn.Click += (s1, e1) =>
            {
                if (AppDataHelper.GetCurrentUser().Uid == null)
                {
                    return;
                }
                else
                {
                    OnboardingActivity.ShowProgressDialog();
                    var dataRef = AppDataHelper.GetDatabase().GetReference($"Drivers/{AppDataHelper.GetCurrentUser().Uid}/{StringConstants.StageofRegistration}");
                    dataRef.SetValue(RegistrationStage.RegistrationDone.ToString())
                    .AddOnSuccessListener(new OnSuccessListener(r =>
                    {
                        editor = preferences.Edit();
                        editor.PutString("firstRun", "regd");
                        editor.Commit();

                        OnboardingActivity.CloseProgressDialog();
                        var intent = new Intent(Context, typeof(MainActivity));
                        intent.SetFlags(ActivityFlags.ClearTask | ActivityFlags.ClearTop | ActivityFlags.NewTask);
                        StartActivity(intent);
                    })).AddOnFailureListener(new OnFailureListener(e =>
                    {
                        OnboardingActivity.CloseProgressDialog();
                        OnboardingActivity.ShowErrorDialog(e.Message);
                    }));
                }
            };

            visit_btn.Click += (s2, e2) =>
            {
                string url = "https://www.google.com";
                Intent i   = new Intent(Intent.ActionView);
                i.SetData(Android.Net.Uri.Parse(url));
                StartActivity(i);
            };
        }
        private void UpdateUiOnCpture(CaptureType captureType)
        {
            switch (captureType)
            {
            case CaptureType.ProfilePic:
                Card1.CardBackgroundColor = ColorStateList.ValueOf(Color.LightSkyBlue);
                NxtImg1.ImageTintList     = ColorStateList.ValueOf(Color.Blue);
                break;

            case CaptureType.FrontOfLicense:
                Card2.CardBackgroundColor = ColorStateList.ValueOf(Color.LightSkyBlue);
                NxtImg2.ImageTintList     = ColorStateList.ValueOf(Color.Blue);
                break;

            case CaptureType.BackOfLicense:
                Card3.CardBackgroundColor = ColorStateList.ValueOf(Color.LightSkyBlue);
                NxtImg3.ImageTintList     = ColorStateList.ValueOf(Color.Blue);
                break;
            }

            OnboardingActivity.CloseProgressDialog();
        }
        private void DetectFace()
        {
            OnboardingActivity.ShowProgressDialog();
            try
            {
                FaceDetector detector = new FaceDetector.Builder(Context)
                                        .SetMode(FaceDetectionMode.Accurate)
                                        .SetClassificationType(ClassificationType.All)
                                        .SetLandmarkType(LandmarkDetectionType.All)
                                        .SetProminentFaceOnly(true)
                                        .SetTrackingEnabled(false)
                                        .Build();

                if (!detector.IsOperational)
                {
                    //Handle contingency
                }
                else
                {
                    Frame frame = new Frame.Builder()
                                  .SetBitmap(bitmap)
                                  .Build();

                    var faces = detector.Detect(frame);
                    detector.Release();
                    DetectedResponse(bitmap, faces);
                }


                SaveImage();
            }
            catch (Exception e)
            {
                OnboardingActivity.CloseProgressDialog();
                OnboardingActivity.ShowErrorDialog(e.Message);
            }
        }
        private void UpdateUiOnError(CaptureType captureType)
        {
            switch (captureType)
            {
            case CaptureType.ProfilePic:
                Card1.CardBackgroundColor = ColorStateList.ValueOf(Color.PapayaWhip);
                NxtImg1.SetImageResource(Resource.Drawable.ic_error);
                HeaderTxt1.SetText(Resource.String.string_attention_seekr);
                break;

            case CaptureType.FrontOfLicense:
                Card2.CardBackgroundColor = ColorStateList.ValueOf(Color.PapayaWhip);
                NxtImg2.SetImageResource(Resource.Drawable.ic_error);
                HeaderTxt2.SetText(Resource.String.string_attention_seekr);
                break;

            case CaptureType.BackOfLicense:
                Card3.CardBackgroundColor = ColorStateList.ValueOf(Color.PapayaWhip);
                NxtImg3.SetImageResource(Resource.Drawable.ic_error);
                HeaderTxt3.SetText(Resource.String.string_attention_seekr);
                break;
            }
            OnboardingActivity.CloseProgressDialog();
        }
 private void CameraActivity_onImageCaptured(object sender, CameraActivity.ImageCapturedEventArgs e)
 {
     OnboardingActivity.CloseProgressDialog();
     bitmap = e.ProfilePic;
     DisplayPic(e.RotationDegrees);
 }
        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;
                }
                }
            };
        }