void SetupTrip()
        {
            setupHorizontalSlider(TripToShow.Steps.Count);
            List <Step> LegsToShow = TripToShow.Steps;

            List <CLLocationCoordinate2D> points = new List <CLLocationCoordinate2D> ();
            int index = 1;

            foreach (var leg in LegsToShow)
            {
                List <CLLocationCoordinate2D> legpoints = new List <CLLocationCoordinate2D> ();
                foreach (var coord in leg.googlePoints)
                {
                    CLLocationCoordinate2D newCoord = new CLLocationCoordinate2D(coord.Latitude, coord.Longitude);
                    points.Add(newCoord);
                    legpoints.Add(newCoord);
                }
                var legpolyline = MKPolyline.FromCoordinates(legpoints.ToArray());
                polylineDictionary.Add(index, legpolyline);

                From fromPlace = new From();
                fromPlace.name = leg.FromName;
                fromPlace.lat  = leg.googlePoints [0].Latitude;
                fromPlace.lon  = leg.googlePoints [0].Longitude;

                To toPlace = new To();
                toPlace.name = leg.ToName;
                toPlace.lat  = leg.googlePoints [leg.googlePoints.Count - 1].Latitude;
                toPlace.lon  = leg.googlePoints [leg.googlePoints.Count - 1].Longitude;

                fromNameDictionary.Add(index, fromPlace);
                toNameDictionary.Add(index, toPlace);
                modeDictionary.Add(index, ModeType.IdToString(leg.ModeId));
                index++;
            }
            var polyline = MKPolyline.FromCoordinates(points.ToArray());

            polylineDictionary.Add(0, polyline);

            From tripFrom = new From();

            tripFrom.name = TripToShow.Steps[0].FromName;
            tripFrom.lat  = TripToShow.Steps[0].googlePoints [0].Latitude;
            tripFrom.lon  = TripToShow.Steps[0].googlePoints [0].Longitude;

            To tripTo = new To();

            tripTo.name = TripToShow.Steps[TripToShow.Steps.Count - 1].FromName;
            int googlePointsCount = TripToShow.Steps [TripToShow.Steps.Count - 1].googlePoints.Count;

            tripTo.lat = TripToShow.Steps[TripToShow.Steps.Count - 1].googlePoints [googlePointsCount - 1].Latitude;
            tripTo.lon = TripToShow.Steps[TripToShow.Steps.Count - 1].googlePoints [googlePointsCount - 1].Longitude;

            fromNameDictionary.Add(0, tripFrom);
            toNameDictionary.Add(0, tripTo);
            modeDictionary.Add(0, "none");
            updateMapFromDictionary(0);
        }
Beispiel #2
0
        /*public int Id { get; set; }
         * public int TripId { get; set; }
         * public int ModeId { get; set; }
         * public DateTime StartDate { get; set; }
         * public DateTime EndDate { get; set; }
         * public string FromName { get; set; }
         * public string FromStopCode { get; set; }
         * public int? FromProviderId { get; set; }
         * public string ToName { get; set; }
         * public string ToStopCode { get; set; }
         * public int? ToProviderId { get; set; }
         * public decimal Distance { get; set; }
         * public string RouteNumber { get; set; }
         *
         * public int Duration_sec()
         * {
         *      TimeSpan ts = EndDate - StartDate;
         *      int ts_min = (int)Math.Round (ts.TotalSeconds);
         *      return ts_min;
         * }
         *
         * public int Duration_min()
         * {
         *      TimeSpan ts = EndDate - StartDate;
         *      int ts_min = (int)Math.Round (ts.TotalMinutes);-
         *      return ts_min;
         * }*/
        private void UpdateView(Step step, View convertView, int position)
        {
            ImageView    ivIcon                      = convertView.FindViewById <ImageView> (Resource.Id.leg_list_item_iv_icon);
            TextView     tvStopName                  = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_stop_name);
            TextView     tvTime                      = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_time);
            TextView     tvDescription               = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_description);
            TextView     tvDetailsDepart_Time        = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_details_depart_time);
            TextView     tvDetailsDepart_Description = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_details_depart_description);
            TextView     tvDetailsArrive_Time        = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_details_arrive_time);
            TextView     tvDetailsArrive_Description = convertView.FindViewById <TextView> (Resource.Id.leg_list_item_tv_details_arrive_description);
            LinearLayout llDetails                   = convertView.FindViewById <LinearLayout> (Resource.Id.leg_list_item_details);

            if (selectedPosition == position)
            {
                llDetails.Visibility = ViewStates.Visible;
            }
            else
            {
                llDetails.Visibility = ViewStates.Gone;
            }

            string mode           = ModeType.IdToString(step.ModeId);
            string durationString = step.Duration_min().ToString() + " min";
            string stopName       = step.ToName;
            string toProvider     = "";
            int?   toProviderID   = step.ToProviderId;

            if (toProviderID != null)
            {
                toProvider = Providers.IdToString((int)toProviderID);
            }
            string agencyAndRoute  = toProvider + " " + step.RouteNumber;
            string boardingString  = "";
            string departString    = "";
            string startTimeString = "";
            string endTimeString   = "";
            int?   fromProviderID  = step.FromProviderId;
            string fromProvider    = "";

            if (fromProviderID != null)
            {
                fromProvider = Providers.IdToString((int)fromProviderID);
            }

            int modeImage;

            startTimeString = step.StartDate.ToLocalTime().ToString("t");
            endTimeString   = step.EndDate.ToLocalTime().ToString("t");
            if (mode.ToLower().Equals("walk"))
            {
                modeImage      = Resource.Drawable.walking_icon;
                agencyAndRoute = "Walk";
                boardingString = "Walk from " + step.FromName;
                departString   = "to " + step.ToName;
            }
            else if (mode.ToLower().Equals("rail"))
            {
                modeImage      = Resource.Drawable.rail_icon;
                boardingString = "Board " + fromProvider + " " + step.RouteNumber;
                departString   = "Depart at " + step.ToName;
            }
            else
            {
                modeImage      = Resource.Drawable.bus_icon;
                boardingString = "Board " + fromProvider + " " + step.RouteNumber;
                departString   = "Depart at " + step.ToName;
            }

            tvDetailsDepart_Description.Text = boardingString;
            tvDetailsDepart_Time.Text        = startTimeString;

            tvDetailsArrive_Description.Text = departString;
            tvDetailsArrive_Time.Text        = endTimeString;


            tvStopName.Text = stopName;
            ivIcon.SetImageResource(modeImage);
            tvTime.Text        = durationString;
            tvDescription.Text = agencyAndRoute;
        }
        public TripSaveResultViewModel(Trip trip)
        {
            this.TravelerId = trip.TravelerId;

            this.Origination = trip.Origination;

            this.Destination = trip.Destination;

            this.TripStartDate = trip.TripStartDate;

            this.TripEndDate = trip.TripEndDate;

            this.MobilityFlag = trip.MobilityFlag;

            this.BicycleFlag = trip.BicycleFlag;

            this.PriorityCode = trip.PriorityCode;

            this.StartTime         = TimeZoneInfo.ConvertTimeFromUtc(trip.TripStartDate.Value, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
            this.Duration          = trip.Duration_min();
            this.StartFirstNonWalk = string.Empty;
            this.StartFrom         = string.Empty;
            this.EndAt             = string.Empty;

            var steps = trip.Steps.OrderBy(l => l.StartDate);

            // Count how many back-to-back bus legs there are and that is how
            // many transfers there are.
            int  numTransfers = 0;
            bool prevIsBus    = false;

            foreach (var step in steps)
            {
                if (string.Compare("bus", ModeType.IdToString((int)step.ModeId), true) == 0)
                {
                    if (prevIsBus)
                    {
                        numTransfers++;
                    }
                    else
                    {
                        prevIsBus = true;
                    }
                }
                else
                {
                    prevIsBus = false;
                }
            }

            this.Transfers = numTransfers;

            if (steps.Count() > 0)
            {
                this.StartFrom = steps.First().FromName;
                this.EndAt     = steps.Last().ToName;
                foreach (var step in steps)
                {
                    if (string.Compare("walk", ModeType.IdToString((int)step.ModeId), true) != 0)
                    {
                        this.StartFirstNonWalk = step.FromName;
                        break;
                    }
                }
            }
        }