Beispiel #1
0
        protected override async void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _session = Resolver.Instance.Get <ISalesAppSession>();
            _logger.Initialize(this.GetType().FullName);
            SetContentView(Resource.Layout.layout_welcome);

            this.AddToolbar(Resource.String.app_name, true);

            UiPermissionsController.SetViewsVisibilty();

            _sharedPrefService = Resolver.Instance.Get <ISharedPrefService>();

            _welcomeView = new WelcomeView(FindViewById <ViewGroup>(Resource.Id.welcomeRoot), this);
            _welcomeView.SetUser(_session.FirstName, _session.LastName);

            _welcomeView.RegisterProspectTouched += welcomeView_registerProspectTouched;

            _welcomeView.SwapComponentsTouched += (sender, e) => StartActivity(new Intent(this, typeof(SwapComponentsActivity)));

            FindViewById <RelativeLayout>(Resource.Id.btnRaiseIssue)
            .Click += (sender, e) =>
            {
                new IntentStartPointTracker()
                .StartIntentWithTracker
                (
                    this
                    , IntentStartPointTracker.IntentStartPoint.WelcomeScreen
                    , typeof(TicketStartActivity)
                );
            };
            _welcomeView.RegisterCustomerTouched += welcomeView_registerCustomerTouched;

            // check Location setting status from OTA
            // If its true then we check whether location settings on the device are on
            if (Settings.Instance.EnableLocationInfo)
            {
                if (!_locationListener.IsLocationOn())
                {
                    string acceptLocationTracking = _sharedPrefService.Get("accept_location_tracking");
                    if (acceptLocationTracking == null || !acceptLocationTracking.Equals("NO"))
                    {
                        CheckLocationStatus();
                    }
                }
            }

            // set app Google analytics
            GoogleAnalyticService.Instance.Initialize(this);

            Logger.Verbose("Creating new instance of CustomerPhotoUploaderReceiver");
            _customerPhotoUploaderReceiver = new CustomerPhotoUploaderReceiver();

            _photoUploadServiceIntent = new Intent(this, typeof(CustomerPhotoUploadService));

            // start the customer photo upload service
            StartService(_photoUploadServiceIntent);
        }
Beispiel #2
0
        /// <summary>
        /// If <paramref name="withRetry"/> is true, this method will try online login three times and if they all fail, the next time it is called with
        /// <paramref name="withRetry"/> as true, it will automatically try offline login.
        /// If however <paramref name="withRetry"/> is false the method will only try online login once and wont revert to offline if it fails.
        /// </summary>
        /// <param name="withRetry">A boolean indicating whether or not to try 3 times</param>
        /// <returns>An empty task</returns>
        protected async Task LoginOnline(bool withRetry = false)
        {
            this.HideLoginResultMessage();

            // change the login text and disable the button
            this.DisableLoginButton();

            var           loginApis = new LoginApis();
            LoginResponse loginResponse;

            if (withRetry)
            {
                // the previous 3 online login tries failed, so we automatically switch to online
                if (this._onlineLoginFailed && this._canLoginOffline)
                {
                    this.LoginOffline();
                    this.EnableLoginButton();
                    return;
                }

                loginResponse = await loginApis.Login(Settings.Instance.DsrPhone, this.EnteredPin, ErrorFilterFlags.DisableErrorHandling);
            }
            else
            {
                loginResponse = await loginApis.Login(Settings.Instance.DsrPhone, this.EnteredPin, true, ErrorFilterFlags.DisableErrorHandling);
            }

            bool loginSuccess = false;

            switch (loginResponse.Code)
            {
            case LoginResponseCode.HttpError:
            case LoginResponseCode.Unknown:
                if (withRetry && this._canLoginOffline)
                {
                    this.ShowLoginResultMessage(Resource.String.online_login_failed);
                    this._onlineLoginFailed = true;
                }
                else
                {
                    this.ShowLoginResultMessage(Resource.String.something_wrong_try_again_login);
                }
                break;

            case LoginResponseCode.Unauthorized:
                this.ShowLoginResultMessage(Resource.String.wrong_pin);
                break;

            case LoginResponseCode.WrongParameters:
                this.ShowLoginResultMessage(Resource.String.something_wrong_try_again);
                break;

            case LoginResponseCode.Success:
                loginSuccess = true;
                break;
            }

            // grab profile from response, we're still good
            if (loginSuccess)
            {
                ISharedPrefService sharedPreferences = Resolver.Instance.Get <ISharedPrefService>();
                sharedPreferences.Save(LoginService.IsFirstLogin, false);

                // check whether the app is up to date
                switch (loginResponse.AppCompatibility)
                {
                case AppCompatibility.UpdateAvailable:
                    this.ShowDialog(this.GetString(Resource.String.update_preferred), this.GetString(Resource.String.update), this.GetString(Resource.String.not_now),
                                    (sender, args) =>
                    {
                        this.GoToPlayStore();
                    },
                                    (sender, args) =>
                    {
                        Task.Run(async() =>
                        {
                            try
                            {
                                await this.ProceedWithLogin(loginResponse);
                            }
                            catch (Exception exception)
                            {
                                Logger.Debug(exception);
                                throw;
                            }
                        });
                    });
                    break;

                case AppCompatibility.UpdateRequired:
                    this.ShowDialog(this.GetString(Resource.String.update_required), this.GetString(Resource.String.update),
                                    (sender, args) =>
                    {
                        this.GoToPlayStore();
                    });
                    break;

                case AppCompatibility.UpToDate:
                    await this.ProceedWithLogin(loginResponse);

                    break;

                case AppCompatibility.Unknown:
                    await this.ProceedWithLogin(loginResponse);

                    break;
                }
            }

            this.EnableLoginButton();
        }