コード例 #1
0
        private async void IrParaChamada()
        {
            if (!_isPendencia)
            {
                ValidaTempoEspera();
            }
            if (_expirouTempo && !_isPendencia)
            {
                await NavigationService.NavigateAsync("/NavigationPage/Home", useModalNavigation : true);
            }
            else
            {
                if (CrossConnectivity.Current.IsConnected)
                {
                    try
                    {
                        UserDialogs.Instance.ShowLoading("Carregando...");

                        Plugin.Geolocator.Abstractions.Position pos = await GetCurrentPosition();

                        SelecaoChamadaParam param = new SelecaoChamadaParam();
                        param.chamada        = chamada;
                        param.dataDecisao    = DateTime.Now;
                        param.codVeiculo     = CrossSettings.Current.Get <RetornoVeiculosMotorista>("VeiculoSelecionado").codVeiculo;
                        param.latitudeAtual  = pos.Latitude.ToString().Replace(",", ".");
                        param.longitudeAtual = pos.Longitude.ToString().Replace(",", ".");
                        var json    = JsonConvert.SerializeObject(param);
                        var content = new StringContent(json, Encoding.UTF8, "application/json");

                        var response = await IniciarCliente(true).PostAsync("motorista/aceitarChamada", content);


                        if (response.IsSuccessStatusCode)
                        {
                            var respStr = await response.Content.ReadAsStringAsync();

                            chamada            = JsonConvert.DeserializeObject <Chamada>(respStr);
                            chamada.valorFinal = chamada.valorPrevisto.ToString();
                            CrossSettings.Current.Remove("ChamadaAceita");
                            CrossSettings.Current.Set("ChamadaAceita", chamada);
                            CrossSettings.Current.Remove("tempoEsperaAceitacao");
                            CrossSettings.Current.Remove("dataRecebimentoChamada");
                            CrossSettings.Current.Remove("ChamadaParaResposta");
                            // var navParam = new NavigationParameters();
                            // navParam.Add("chamadaAceita", chamada);
                            await NavigationService.NavigateAsync("//NavigationPage/Chamada", null, true);
                        }
                        else
                        {
                            await DialogService.DisplayAlertAsync("Aviso", response.Content.ReadAsStringAsync().Result, "OK");
                        }
                    }
                    catch (AccessViolationException e)
                    {
                        await DialogService.DisplayAlertAsync("Aviso", e.Message, "OK");
                    }
                    catch (Exception e)
                    {
                        Crashes.TrackError(e);
                        await DialogService.DisplayAlertAsync("Aviso", "Falha ao aceitar chamada", "OK");
                    }
                    finally
                    {
                        UserDialogs.Instance.HideLoading();
                    }
                }
                else
                {
                    await DialogService.DisplayAlertAsync("Aviso", " Sem conexão com internet!", "OK");
                }
            }
        }
コード例 #2
0
        private async void IniciarCorrida()
        {
            try
            {
                UserDialogs.Instance.ShowLoading("Carregando...");

                Plugin.Geolocator.Abstractions.Position pos = await GetCurrentPosition();

                Chamada.latitudeInicioCorrida  = pos.Latitude.ToString();
                Chamada.longitudeInicioCorrida = pos.Longitude.ToString();

                SelecaoChamadaParam param = new SelecaoChamadaParam();
                param.chamada       = Chamada;
                param.inicioCorrida = DateTime.Now;

                var json    = JsonConvert.SerializeObject(param);
                var content = new StringContent(json, Encoding.UTF8, "application/json");

                TextoBotaoFinal = "Finalizar";
                ShowBotaoInicio = false;
                //Insiro uma chamada em corrida na memória e retio a chamada aceita
                //CrossSettings.Current.Set("ChamadaEmCorrida", Chamada);
                CrossSettings.Current.Remove("ChamadaAceita");
                CrossSettings.Current.Set("ChamadaEmCorrida", Chamada);
                //MessagingCenter.Subscribe<ViewModelBase, float>(this, "MudancaValor",
                // (sender, arg) =>
                // {
                //     ValorFinalView = arg;
                //     TextoValor = arg.ToString("C2", new CultureInfo("pt-BR"));
                //     TextoValor.Replace(".", ",");
                // });

                LimparRota();
                AjustePosicaoMapa();
                //var response = await ChamarServicoPost(true, "iniciarCorrida", content);
                var response = await IniciarCliente(true).PostAsync("motorista/iniciarCorrida", content);

                if (response != null)
                {
                    if (response.IsSuccessStatusCode)
                    {
                        var respStr = await response.Content.ReadAsStringAsync();

                        Device.OpenUri(new Uri("https://www.waze.com/ul?ll=" + Chamada.latitudeDestino + "," +
                                               Chamada.longitudeDestino + "&navigate=yes&zoom=17"));
                    }
                    else
                    {
                        await DialogService.DisplayAlertAsync("Aviso", response.Content.ReadAsStringAsync().Result, "OK");
                    }
                }
            }
            catch (AccessViolationException e)
            {
                await DialogService.DisplayAlertAsync("Aviso", e.Message, "OK");
            }
            catch (Exception e)
            {
                Crashes.TrackError(e);
                await DialogService.DisplayAlertAsync("Aviso", "Falha ao iniciar corrida", "OK");
            }
            finally
            {
                UserDialogs.Instance.HideLoading();
            }
        }