Ejemplo n.º 1
0
        public void OnClick(View view)
        {
            RouteSegmentsViewHolder viewHolder = viewHolders.First(vh => vh.ItemView == view);

            RouteSegment[] segments = routeSegments[viewHolder.AdapterPosition];

            Intent intent = new Intent(view.Context, typeof(RouteActivity));

            List <string> routeSegmentsData = new List <string>();

            foreach (RouteSegment segment in segments)
            {
                JObject segmentObject = new JObject()
                {
                    ["Line"]       = segment.Line.Id,
                    ["From.Route"] = segment.From.Route.Id,
                    ["From.Stop"]  = segment.From.Stop.Id,
                    ["From.Date"]  = segment.DateFrom,
                    ["To.Route"]   = segment.To.Route.Id,
                    ["To.Stop"]    = segment.To.Stop.Id,
                    ["To.Date"]    = segment.DateTo,
                    ["TimeSteps"]  = new JArray(segment.TimeSteps.Select(s => new JObject()
                    {
                        ["Date"] = s.Date, ["Route"] = s.Step.Route.Id, ["Stop"] = s.Step.Stop.Id
                    }).ToArray())
                };

                routeSegmentsData.Add(segmentObject.ToString());
            }

            intent.PutExtra("RouteSegments", routeSegmentsData.ToArray());

            view.Context.StartActivity(intent);
        }
Ejemplo n.º 2
0
        public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int position)
        {
            RouteSegmentsViewHolder viewHolder = holder as RouteSegmentsViewHolder;

            RouteSegment[] segments = routeSegments[position];

            viewHolder.From.Text     = segments.First().DateFrom.ToString("HH:mm");
            viewHolder.To.Text       = segments.Last().DateTo.ToString("HH:mm");
            viewHolder.Duration.Text = Math.Ceiling((segments.Last().DateTo - segments.First().DateFrom).TotalMinutes) + " min";

            double left = Math.Ceiling((segments.First().DateFrom - DateTime.Now).TotalMinutes);

            viewHolder.Left.Text = left < 0 ? "Parti" : (left + Environment.NewLine + "min");

            Context context = viewHolder.ItemView.Context;
            float   density = context.Resources.DisplayMetrics.Density;

            DateTime begin = segments.First().DateFrom;
            DateTime end   = segments.Last().DateTo;
            TimeSpan total = end - begin;

            viewHolder.Preview.RemoveAllViews();

            PercentRelativeLayout.LayoutParams percentLayoutParams;

            LinearLayout.LayoutParams barBackLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MatchParent, LinearLayout.LayoutParams.MatchParent);
            barBackLayoutParams.SetMargins((int)(4 * density), 0, (int)(4 * density), 0);

            int i = 1;

            foreach (RouteSegment segment in segments)
            {
                Color color = Utils.GetColorForLine(context, segment.Line);

                ImageView image = new ImageView(context);
                image.Id = i;
                image.SetImageResource(Resource.Drawable.circle2);
                image.SetColorFilter(color);

                percentLayoutParams = new PercentRelativeLayout.LayoutParams((int)(14 * density), (int)(14 * density));
                percentLayoutParams.AddRule(LayoutRules.CenterVertical);
                percentLayoutParams.SetMargins((int)(-7 * density), 0, 0, 0);
                percentLayoutParams.PercentLayoutInfo.LeftMarginPercent = (float)(segment.DateFrom - begin).Ticks / total.Ticks;

                viewHolder.Preview.AddView(image, percentLayoutParams);

                LinearLayout bar = new LinearLayout(context);

                View barBack = new View(context);
                barBack.SetBackgroundColor(color);

                bar.AddView(barBack, barBackLayoutParams);

                percentLayoutParams = new PercentRelativeLayout.LayoutParams((int)(28 * density), (int)(4 * density));
                percentLayoutParams.AddRule(LayoutRules.CenterVertical);
                percentLayoutParams.AddRule(LayoutRules.RightOf, i);
                percentLayoutParams.SetMargins((int)(-7 * density), 0, (int)(-7 * density), 0);
                percentLayoutParams.PercentLayoutInfo.WidthPercent = (float)(segment.DateTo - segment.DateFrom).Ticks / total.Ticks;

                viewHolder.Preview.AddView(bar, percentLayoutParams);

                i++;
            }

            if (!viewHolders.Contains(viewHolder))
            {
                viewHolders.Add(viewHolder);
            }
        }