コード例 #1
0
        private void Refresh( )
        {
            if (UserInfo.State == StateTypes.ActiveOrder)
            {
                UserInfo.CurrentOrder = Requests.GetActiveOrder(UserInfo.UserId);
            }
            else if (UserInfo.State == StateTypes.PersonInCar)
            {
                UserInfo.CurrentOrder = Requests.GetActiveOrderInCar(UserInfo.UserId);
            }
            else if (UserInfo.State == StateTypes.Arrived)
            {
                UserInfo.CurrentOrder = Requests.GetActiveOrder(UserInfo.UserId);
            }

            RunOnUiThread(() =>
            {
                if (UserInfo.State == StateTypes.Free)
                {
                    AddHomeAction(Finish, Resource.Drawable.Icon);
                }
                else
                {
                    LegacyBar.ClearHomeAction( );
                    LegacyBar.SetHomeLogo(Resource.Drawable.Icon);
                }

                txtFrom.Text  = UserInfo.CurrentOrder.From;
                txtThru.Text  = "";
                txtTo.Text    = UserInfo.CurrentOrder.To;
                txtTime.Text  = UserInfo.CurrentOrder.Time;
                txtPrice.Text = UserInfo.CurrentOrder.Price;

                if (UserInfo.CurrentOrder.Waypoints.Count != 0)
                {
                    foreach (var cWaypoint in UserInfo.CurrentOrder.Waypoints)
                    {
                        txtThru.Text += cWaypoint + "\n";
                    }
                    txtThru.Text = txtThru.Text.Remove(txtThru.Text.Length - 1);
                }
                else
                {
                    txtThru.Visibility = ViewStates.Gone;
                    lblThru.Visibility = ViewStates.Gone;
                }

                btnPhone.Visibility       = ViewStates.Gone;
                btnArrived.Visibility     = ViewStates.Gone;
                btnPersonInCar.Visibility = ViewStates.Gone;
                btnCompleted.Visibility   = ViewStates.Gone;
                btnTake.Visibility        = ViewStates.Gone;

                switch (UserInfo.State)
                {
                case StateTypes.Free:
                    btnTake.Visibility = ViewStates.Visible;
                    break;

                case StateTypes.ActiveOrder:
                    btnPersonInCar.Visibility = ViewStates.Visible;
                    btnArrived.Visibility     = ViewStates.Visible;
                    btnPhone.Visibility       = ViewStates.Visible;
                    break;

                case StateTypes.Arrived:
                    btnPhone.Visibility       = ViewStates.Visible;
                    btnPersonInCar.Visibility = ViewStates.Visible;
                    break;

                case StateTypes.PersonInCar:
                    btnPhone.Visibility     = ViewStates.Visible;
                    btnCompleted.Visibility = ViewStates.Visible;
                    break;
                }

                btnTake.Click        += btnTake_Click;
                btnArrived.Click     += btnArrived_Click;
                btnPersonInCar.Click += btnPersonInCar_Click;
                btnCompleted.Click   += btnCompleted_Click;

                if (UserInfo.CurrentOrder.Accepted == "0")
                {
                    var dialog = new AlertDialog.Builder(this);
                    dialog.SetTitle(Resource.String.AcceptOrder);
                    dialog.SetMessage(String.Format("{0} -> {1}\nКогда: {2}\nЦена: {3}р.", UserInfo.CurrentOrder.From, UserInfo.CurrentOrder.To, UserInfo.CurrentOrder.Time, UserInfo.CurrentOrder.Price));
                    dialog.SetPositiveButton(Resource.String.Accept, (sender, args) => ThreadPool.QueueUserWorkItem(o =>
                    {
                        Requests.AcceptOrder(UserInfo.UserId, UserInfo.CurrentOrder.ID);
                        UserInfo.CurrentOrder.Accepted = "1";
                    }));
                    dialog.SetNegativeButton(Resource.String.Decline, (sender, args) => ThreadPool.QueueUserWorkItem(o =>
                    {
                        Requests.DeclineOrder(UserInfo.UserId, UserInfo.CurrentOrder.ID);
                        StartActivity(typeof(ListActivity));
                    }));
                    dialog.Show( );
                }
            });
        }
コード例 #2
0
ファイル: AuthActivity.cs プロジェクト: romap0/TaxiAuction
        private void Continue(string authResponse)
        {
            ThreadPool.QueueUserWorkItem(o =>
            {
                var state = Requests.GetState(authResponse);

                RunOnUiThread(() =>
                {
                    switch (state)
                    {
                    case "-50":
                        UserInfo.State = StateTypes.Free;
                        StartActivity(typeof(ListActivity));
                        break;

                    case "-51":
                        UserInfo.State  = StateTypes.ActiveOrder;
                        var activeOrder = Requests.GetActiveOrder(UserInfo.UserId);
                        if (activeOrder != null)
                        {
                            UserInfo.CurrentOrder = activeOrder;
                            StartActivity(typeof(OrderActivity));
                        }
                        else
                        {
                            Toast.MakeText(Application.Context, Resource.String.Error, ToastLength.Short).Show( );
                        }
                        break;

                    case "-52":
                        UserInfo.State       = StateTypes.PersonInCar;
                        var activeOrderInCar = Requests.GetActiveOrderInCar(UserInfo.UserId);
                        if (activeOrderInCar != null)
                        {
                            UserInfo.CurrentOrder = activeOrderInCar;
                            StartActivity(typeof(OrderActivity));
                        }
                        else
                        {
                            Toast.MakeText(Application.Context, Resource.String.Error, ToastLength.Short).Show( );
                        }
                        break;

                    case "-53":
                        UserInfo.State         = StateTypes.Arrived;
                        var activeOrderArrived = Requests.GetActiveOrder(UserInfo.UserId);
                        if (activeOrderArrived != null)
                        {
                            UserInfo.CurrentOrder = activeOrderArrived;
                            StartActivity(typeof(OrderActivity));
                        }
                        else
                        {
                            Toast.MakeText(Application.Context, Resource.String.Error, ToastLength.Short).Show( );
                        }
                        break;

                    default:
                        if (!activityIsVisible)
                        {
                            Start( );
                        }
                        Toast.MakeText(Application.Context, Resource.String.Error, ToastLength.Short).Show( );
                        break;
                    }
                });
            });
        }