public void buildDayView() { buildAllDayView(); scrollView.Frame = parentScrollView.Bounds; scrollView.ContentSize = new SizeF (CurrentWidth, consts.TIMELINE_HEIGHT); // Remove all previous view event foreach (UIView view in scrollView.Subviews) { if (view is TimeLineView) { timelineView.Frame = new RectangleF (Bounds.X, Bounds.Y, CurrentWidth, consts.TIMELINE_HEIGHT); timelineView.CurrentWidth = CurrentWidth; } else { view.RemoveFromSuperview (); } } // Ask the delgate about the events that correspond // the the currently displayed day view var dailyEvents = monthEvents.Where (x => (x.startDate.Date == currentDate || x.endDate.Date == currentDate) && !x.AllDay).ToList (); if (dailyEvents.Count > 0) { // _events = events.Where(x => x.startDate.Date == currentDate.Date || x.endDate.Date == currentDate.Date).OrderBy(x => x.startDate).ThenByDescending(x => x.endDate).ToList(); var blocks = new List<Block> (); var lastBlock = new Block (); // Removed the thenByDecending. Caused a crash on the device. This is needed for 2 events with the same start time though.... // foreach (CalendarDayEventView e in events.Where(x => x.startDate.Date == currentDate.Date || x.endDate.Date == currentDate.Date).OrderBy(x => x.startDate))//.ThenByDescending(x => x.endDate).ToList()) //.ThenByDescending(x => x.endDate).ToList()) foreach (CalendarDayEventView e in dailyEvents.OrderBy (x => x.startDate)) { // if there is no block, create the first one if (blocks.Count == 0) { lastBlock = new Block (); blocks.Add (lastBlock); // or if the event doesn't overlap with the last block, create a new block } else if (!lastBlock.OverlapsWith (e)) { lastBlock = new Block (); blocks.Add (lastBlock); } // any case, add it to some block lastBlock.Add (e); } foreach (Block theBlock in blocks) { //theBlock.ArrangeColumns(); foreach (CalendarDayEventView theEvent in theBlock.events) { theEvent.ParentView = this; // Get the hour start position Int32 hourStart = theEvent.startDate.Hour; //Util.WriteLine ("Start time: " + hourStart); var hourStartPosition = (float)Math.Round ((hourStart * consts.VERTICAL_DIFF) + consts.VERTICAL_OFFSET + ((consts.FONT_SIZE + 4.0f) / 2.0f)); //Util.WriteLine ("Hour float: " + hourStartPosition); // Get the minute start position Int32 minuteStart = theEvent.startDate.Minute; var minuteStartPosition = (float)((Convert.ToDouble (minuteStart) / 60) * consts.VERTICAL_DIFF); // Get the hour end position Int32 hourEnd = theEvent.endDate.Hour; if (theEvent.startDate.Date != theEvent.endDate.Date) { hourEnd = 23; } var hourEndPosition = (float)Math.Round ((hourEnd * consts.VERTICAL_DIFF) + consts.VERTICAL_OFFSET + ((consts.FONT_SIZE + 4.0f) / 2.0f)); // Get the minute end position // Round minute to each 5 Int32 minuteEnd = theEvent.endDate.Minute; if (theEvent.startDate.Date != theEvent.endDate.Date) { minuteEnd = 55; } // minuteEnd = Convert.ToInt32(Math.Round(minuteEnd/5.0)*5); // float minuteEndPosition = (float) Math.Round((minuteEnd < 30) ? 0 : VERTICAL_DIFF/2.0f); var minuteEndPosition = (float)((Convert.ToDouble (minuteEnd) / 60) * consts.VERTICAL_DIFF); float eventHeight = 0.0f; // Calculate the event Height. eventHeight = (hourEndPosition + minuteEndPosition) - hourStartPosition - minuteStartPosition; // Set the min Height to 30 min /* if (eventHeight < (VERTICAL_DIFF/2) - (2*EVENT_VERTICAL_DIFF)) { eventHeight = (VERTICAL_DIFF/2) - (2*EVENT_VERTICAL_DIFF); } */ float availableWidth = CurrentWidth - (consts.HORIZONTAL_OFFSET + consts.TIME_WIDTH + consts.PERIOD_WIDTH + consts.HORIZONTAL_LINE_DIFF) - consts.HORIZONTAL_LINE_DIFF - consts.EVENT_HORIZONTAL_DIFF; float currentWidth = availableWidth / theBlock.Columns.Count; int currentInt = theEvent.Column.Number; float x = consts.HORIZONTAL_OFFSET + consts.TIME_WIDTH + consts.PERIOD_WIDTH + consts.HORIZONTAL_LINE_DIFF + consts.EVENT_HORIZONTAL_DIFF + (currentWidth * currentInt); float y = hourStartPosition + minuteStartPosition + consts.EVENT_VERTICAL_DIFF; var eventFrame = new RectangleF (x, y, currentWidth, eventHeight); theEvent.Frame = eventFrame; //event.delegate = self; theEvent.SetNeedsDisplay (); timelineView.AddSubview (theEvent); // Log the extracted date values //Util.Log ("hourStart: {0} minuteStart: {1}", hourStart, minuteStart); } } } scrollView.ScrollRectToVisible (new RectangleF (curScrollW, curScrollH, scrollView.Frame.Width, scrollView.Frame.Height), false); //disable scroll to time, keep current scroll; }
public void reloadDay() { if (isVisible) { // If no current day was given // Make it today if (CurrentDate <= Util.DateTimeMin) { // Dont' want to inform the observer CurrentDate = DateTime.Today; } if (UseCalendar) { if (EventsNeedRefresh) { events = new List<CalendarDayEventView> (); DateTime endDate = FirstDayOfWeek.AddDays (6).AddSeconds (86400); foreach (EKEvent theEvent in Util.FetchEvents (FirstDayOfWeek, endDate)) { events.Add (new CalendarDayEventView (theEvent)); } if (events != null) { // _events = events.Where(x => x.startDate.Date == currentDate.Date || x.endDate.Date == currentDate.Date).OrderBy(x => x.startDate).ThenByDescending(x => x.endDate).ToList(); blocks = new List<Block> (); var lastBlock = new Block (); // Removed the thenByDecending. Caused a crash on the device. This is needed for 2 events with the same start time though.... // foreach (CalendarDayEventView e in events.Where(x => x.startDate.Date == currentDate.Date || x.endDate.Date == currentDate.Date).OrderBy(x => x.startDate))//.ThenByDescending(x => x.endDate).ToList()) //.ThenByDescending(x => x.endDate).ToList()) foreach (CalendarDayEventView e in events.Where(x=> !x.AllDay).OrderBy (x => x.startDate)) { // if there is no block, create the first one if (blocks.Count == 0) { lastBlock = new Block (); blocks.Add (lastBlock); // or if the event doesn't overlap with the last block, create a new block } else if (!lastBlock.OverlapsWith (e)) { lastBlock = new Block (); blocks.Add (lastBlock); } // any case, add it to some block lastBlock.Add (e); } } EventsNeedRefresh = false; } // Ask the delgate about the events that correspond // the the currently displayed day view reloadAllDay(); SetupWindow (); foreach (Block theBlock in blocks) { int dayColumn = (theBlock.BoxStart - FirstDayOfWeek).Days; //theBlock.ArrangeColumns(); foreach (CalendarDayEventView theEvent in theBlock.events) { theEvent.ParentView = this; DateTime startDate = theEvent.startDate; // Making sure delgate sending date that match current day // Get the hour start position Int32 hourStart = theEvent.startDate.Hour; var hourStartPosition = (float)Math.Round ((hourStart * consts.VERTICAL_DIFF) + consts.VERTICAL_OFFSET + ((consts.FONT_SIZE + 4.0f) / 2.0f)); // Get the minute start position Int32 minuteStart = theEvent.startDate.Minute; var minuteStartPosition = (float)((Convert.ToDouble (minuteStart) / 60) * consts.VERTICAL_DIFF); // Get the hour end position Int32 hourEnd = theEvent.endDate.Hour; if (theEvent.startDate.Date != theEvent.endDate.Date) { hourEnd = 23; } var hourEndPosition = (float)Math.Round ((hourEnd * consts.VERTICAL_DIFF) + consts.VERTICAL_OFFSET + ((consts.FONT_SIZE + 4.0f) / 2.0f)); // Get the minute end position // Round minute to each 5 Int32 minuteEnd = theEvent.endDate.Minute; if (theEvent.startDate.Date != theEvent.endDate.Date) { minuteEnd = 55; } // minuteEnd = Convert.ToInt32(Math.Round(minuteEnd/5.0)*5); // float minuteEndPosition = (float) Math.Round((minuteEnd < 30) ? 0 : VERTICAL_DIFF/2.0f); var minuteEndPosition = (float)((Convert.ToDouble (minuteEnd) / 60) * consts.VERTICAL_DIFF); float eventHeight = 0.0f; // Calculate the event Height. eventHeight = (hourEndPosition + minuteEndPosition) - hourStartPosition - minuteStartPosition; float availableWidth = DayWidth - 2; float currentWidth = availableWidth / theBlock.Columns.Count; int currentInt = theEvent.Column.Number; float x = ((currentWidth) * currentInt) + 2 + ((availableWidth + 2) * dayColumn); float y = hourStartPosition + minuteStartPosition; var eventFrame = new RectangleF (x, y, currentWidth, eventHeight); theEvent.Frame = eventFrame; theEvent.OnEventClicked += theDate => { eventWasClicked (theDate); }; //event.delegate = self; //theEvent.SetNeedsDisplay(); gridView.AddSubview (theEvent); // Log the extracted date values //Util.Log ("hourStart: {0} minuteStart: {1}", hourStart, minuteStart); } } } if (curRect.Height < 0) curRect.Height = myScrollView.ContentSize.Height; if (curRect.Width < 0) curRect.Width = myScrollView.ContentSize.Width; myScrollView.ZoomScale = curZoom; myScrollView.VisbleContentRect = curRect; } }