From babb4092d89cc28054b918813c0e145c9190201a Mon Sep 17 00:00:00 2001 From: Christian Fiedler Date: Mon, 16 Sep 2013 13:59:23 +0200 Subject: [PATCH] dayview pivotitems --- .../Model/TimeTable/AppointmentModel.cs | 34 +++- .../CampusAppWP8/Pages/TimeTable/TimeTable.cs | 10 +- .../Pages/TimeTable/TimeTableDay.xaml | 29 +-- .../Pages/TimeTable/TimeTableDay.xaml.cs | 190 ++++++++++++++---- .../Resources/AppResources.Designer.cs | 9 + .../CampusAppWP8/Resources/AppResources.resx | 4 + .../CampusAppWP8/Resources/Constants.resx | 1 + 7 files changed, 203 insertions(+), 74 deletions(-) diff --git a/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs b/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs index d31733cf..efd3881d 100644 --- a/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs +++ b/CampusAppWP8/CampusAppWP8/Model/TimeTable/AppointmentModel.cs @@ -67,6 +67,36 @@ namespace CampusAppWP8.Model.TimeTable return this.canvas; } + public int IsDate(DateTime date, int daySpan = 0) + { + int retValue = -1; + + ICalObject eventICal = this.GetVEventObj(); + + DTStart startTime = eventICal.GetProperty(ICSTag.DT_START) as DTStart; + + if (startTime != null) + { + int toDaySpan = 0; + + while ((toDaySpan <= daySpan) && (retValue == -1)) + { + DateTime tempDT = date.AddDays(toDaySpan); + + if (startTime.Value.Year.Equals(tempDT.Year) + && startTime.Value.Month.Equals(tempDT.Month) + && startTime.Value.Day.Equals(tempDT.Day)) + { + retValue = toDaySpan; + } + + toDaySpan++; + } + } + + return retValue; + } + private void CalcRect() { this.CalcHeight(); @@ -76,8 +106,8 @@ namespace CampusAppWP8.Model.TimeTable this.rect.MaxHeight = 600; this.rect.Height = this.height; - this.rect.StrokeThickness = 0; - this.rect.Stroke = new SolidColorBrush(Colors.Red); + this.rect.StrokeThickness = 1; + this.rect.Stroke = new SolidColorBrush(Colors.DarkGray); this.rect.Fill = new SolidColorBrush(Colors.Green); this.canvas.Children.Add(this.rect); diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs index da45486f..c5d72364 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTable.cs @@ -24,11 +24,11 @@ namespace CampusAppWP8.Pages.TimeTable { private static AppointmentListModel appList //= null; = new AppointmentListModel(new AppointmentModel[] { - new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ownCloud Calendar 0.6.3\r\nX-WR-CALNAME:Das is der Titel\r\nBEGIN:VEVENT\r\nCREATED;VALUE=DATE-TIME:20130827T113216Z\r\nUID:c9904ea73c\r\nLAST-MODIFIED;VALUE=DATE-TIME:20130827T113216Z\r\nDTSTAMP;VALUE=DATE-TIME:20130827T113216Z\r\nSUMMARY:Das is der Titel\r\nDTSTART;VALUE=DATE-TIME:20130827T113500Z\r\nDTEND;VALUE=DATE-TIME:20130827T152000Z\r\nCLASS:PUBLIC\r\nLOCATION:BTU Campus\r\nDESCRIPTION:For Outlook 2003, the behavior is peculiar. It can save the sa\r\n me calendar entry in both .ics and .vcs format, but it only read & displa\r\n y .vcs file correctly. It can read .ics file but it omits some fields and \r\n does not display it in calendar mode. My guess is that back then Microsoft\r\n wanted to provide .ics to be compatible with Mac's iCal but not quite com\r\n mitted to v2.0 yet.\r\nCATEGORIES:Projekte\r\nEND:VEVENT\r\nEND:VCALENDAR"), - new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:http://www.example.com/calendarapplication/\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nUID:461092315540@example.com\r\nORGANIZER:MAILTO:alice@example.com\r\nLOCATION:Somewhere\r\nSUMMARY:Eine Kurzinfo\r\nDESCRIPTION:Beschreibung des Termines\r\nCLASS:PUBLIC\r\nDTSTART:20060910T110000Z\r\nDTEND:20060910T195900Z\r\nDTSTAMP:20060812T125900Z\r\nEND:VEVENT\r\nEND:VCALENDAR"), - new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\nBEGIN:VEVENT\r\nUID:uid1@example.com\r\nDTSTAMP:19970714T170000Z\r\nORGANIZER;CN=John Doe:MAILTO:john.doe@example.com\r\nDTSTART:19970714T170000Z\r\nDTEND:19970715T035959Z\r\nSUMMARY:Bastille Day Party\r\nEND:VEVENT\r\nEND:VCALENDAR"), - new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:1.0\r\nBEGIN:VEVENT\r\nCATEGORIES:MEETING\r\nSTATUS:TENTATIVE\r\nDTSTART:19960401T033000Z\r\nDTEND:19960401T043000Z\r\nSUMMARY:Your Proposal Review\r\nDESCRIPTION:Steve and John to review newest proposal material bla fsdfasfsdfsdfgsdafg sfdgfdsgf dsfg dsfgds fgds\r\nCLASS:PRIVATE\r\nEND:VEVENT\r\nEND:VCALENDAR"), - new AppointmentModel("BEGIN:VCALENDAR\r\nPRODID:-//bobbin v0.1//NONSGML iCal Writer//EN\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nDTSTART:20100701T080000Z\r\nDTEND:20100701T110000Z\r\nDTSTAMP:20091130T213238Z\r\nUID:1285935469767a7c7c1a9b3f0df8003a@yoursever.com\r\nCREATED:20091130T213238Z\r\nDESCRIPTION:Example event 1\r\nLAST-MODIFIED:20091130T213238Z\r\nSEQUENCE:0\r\nSTATUS:CONFIRMED\r\nSUMMARY:Example event 1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR") + new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:ownCloud Calendar 0.6.3\r\nX-WR-CALNAME:Das is der Titel\r\nBEGIN:VEVENT\r\nCREATED;VALUE=DATE-TIME:20130827T113216Z\r\nUID:c9904ea73c\r\nLAST-MODIFIED;VALUE=DATE-TIME:20130827T113216Z\r\nDTSTAMP;VALUE=DATE-TIME:20130827T113216Z\r\nSUMMARY:Das is der Titel\r\nDTSTART;VALUE=DATE-TIME:20130914T113500Z\r\nDTEND;VALUE=DATE-TIME:20130914T152000Z\r\nCLASS:PUBLIC\r\nLOCATION:BTU Campus\r\nDESCRIPTION:For Outlook 2003, the behavior is peculiar. It can save the sa\r\n me calendar entry in both .ics and .vcs format, but it only read & displa\r\n y .vcs file correctly. It can read .ics file but it omits some fields and \r\n does not display it in calendar mode. My guess is that back then Microsoft\r\n wanted to provide .ics to be compatible with Mac's iCal but not quite com\r\n mitted to v2.0 yet.\r\nCATEGORIES:Projekte\r\nEND:VEVENT\r\nEND:VCALENDAR"), + new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:http://www.example.com/calendarapplication/\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nUID:461092315540@example.com\r\nORGANIZER:MAILTO:alice@example.com\r\nLOCATION:Somewhere\r\nSUMMARY:Eine Kurzinfo\r\nDESCRIPTION:Beschreibung des Termines\r\nCLASS:PUBLIC\r\nDTSTART:20130916T110000Z\r\nDTEND:20130916T195900Z\r\nDTSTAMP:20130916T125900Z\r\nEND:VEVENT\r\nEND:VCALENDAR"), + new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//hacksw/handcal//NONSGML v1.0//EN\r\nBEGIN:VEVENT\r\nUID:uid1@example.com\r\nDTSTAMP:19970714T170000Z\r\nORGANIZER;CN=John Doe:MAILTO:john.doe@example.com\r\nDTSTART:20130914T170000Z\r\nDTEND:20130915T035959Z\r\nSUMMARY:Bastille Day Party\r\nEND:VEVENT\r\nEND:VCALENDAR"), + new AppointmentModel("BEGIN:VCALENDAR\r\nVERSION:1.0\r\nBEGIN:VEVENT\r\nCATEGORIES:MEETING\r\nSTATUS:TENTATIVE\r\nDTSTART:20130917T033000Z\r\nDTEND:20130917T043000Z\r\nSUMMARY:Your Proposal Review\r\nDESCRIPTION:Steve and John to review newest proposal material bla fsdfasfsdfsdfgsdafg sfdgfdsgf dsfg dsfgds fgds\r\nCLASS:PRIVATE\r\nEND:VEVENT\r\nEND:VCALENDAR"), + new AppointmentModel("BEGIN:VCALENDAR\r\nPRODID:-//bobbin v0.1//NONSGML iCal Writer//EN\r\nVERSION:2.0\r\nCALSCALE:GREGORIAN\r\nMETHOD:PUBLISH\r\nBEGIN:VEVENT\r\nDTSTART:20130918T080000Z\r\nDTEND:20130918T110000Z\r\nDTSTAMP:20091130T213238Z\r\nUID:1285935469767a7c7c1a9b3f0df8003a@yoursever.com\r\nCREATED:20091130T213238Z\r\nDESCRIPTION:Example event 1\r\nLAST-MODIFIED:20091130T213238Z\r\nSEQUENCE:0\r\nSTATUS:CONFIRMED\r\nSUMMARY:Example event 1\r\nTRANSP:OPAQUE\r\nEND:VEVENT\r\nEND:VCALENDAR") }); public TimeTable() diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml index 53e083e6..486811db 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml @@ -15,31 +15,12 @@ - - - - - - - + + + + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs index f3a653ba..8156cc2d 100644 --- a/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs +++ b/CampusAppWP8/CampusAppWP8/Pages/TimeTable/TimeTableDay.xaml.cs @@ -1,20 +1,21 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Media; -using System.Windows.Navigation; -using System.Windows.Shapes; -using Microsoft.Phone.Controls; -using Microsoft.Phone.Shell; -using CampusAppWP8.Model.TimeTable; -using CampusAppWP8.Utility; -using CampusAppWP8.Resources; - + namespace CampusAppWP8.Pages.TimeTable { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Net; + using System.Windows; + using System.Windows.Controls; + using System.Windows.Media; + using System.Windows.Navigation; + using System.Windows.Shapes; + using Microsoft.Phone.Controls; + using Microsoft.Phone.Shell; + using CampusAppWP8.Model.TimeTable; + using CampusAppWP8.Utility; + using CampusAppWP8.Resources; + public partial class TimeTableDay : PhoneApplicationPage { private readonly double DAY_TABLE_HEAD_WIDTH = 48; @@ -23,13 +24,39 @@ namespace CampusAppWP8.Pages.TimeTable private readonly double DAY_TABLE_HEAD_THICKNESS = 2; private readonly double DAY_TABLE_INNER_THICKNESS = 1; + private static readonly int PIVOT_ITEM_PAGES = 5; + private static readonly int PIVOT_ITEM_PAGES_HALF_UP = 3; + private static readonly int PIVOT_ITEM_PAGES_HALF_DOWN = 2; + private bool DayLayoutDone = false; + private PivotItem[] itemPages = new PivotItem[PIVOT_ITEM_PAGES]; + private DateTime[] itemDate = new DateTime[PIVOT_ITEM_PAGES]; + private DateTime itemPage_0_Day = DateTime.Now.AddDays(PIVOT_ITEM_PAGES_HALF_DOWN * -1); + + private int lastSelectedIndex = 0; + public TimeTableDay() { - InitializeComponent(); - - this.DayScroll.LayoutUpdated += new EventHandler(this.AutoScrollToDay); + this.InitializeComponent(); + + for (int i = 0; i < PIVOT_ITEM_PAGES; i++) + { + this.itemPages[i] = new PivotItem(); + this.itemDate[i] = itemPage_0_Day.AddDays(i); + this.SetupItemPageBackground(this.itemPages[i], this.itemDate[i]); + this.ThePivot.Items.Add(this.itemPages[i]); + } + + this.ThePivot.SelectedIndex = PIVOT_ITEM_PAGES_HALF_DOWN; + this.lastSelectedIndex = this.ThePivot.SelectedIndex; + this.ThePivot.SelectionChanged += new SelectionChangedEventHandler(this.EventPivotSelectionChanged); + + ApplicationBarIconButton editBtn = new ApplicationBarIconButton(); + editBtn.IconUri = new Uri(Icons.Link, UriKind.Relative); + editBtn.Text = AppResources.ToDay; + editBtn.Click += new EventHandler(this.OnClickToDay); + ApplicationBar.Buttons.Add(editBtn); } protected override void OnNavigatedTo(NavigationEventArgs e) @@ -38,31 +65,57 @@ namespace CampusAppWP8.Pages.TimeTable if (e.NavigationMode != NavigationMode.Back) { - this.DrawDayViewBackground(); - double maxW = Application.Current.Host.Content.ActualWidth; maxW -= (DAY_TABLE_HEAD_WIDTH + 6.0); - List tempList = TimeTable.AppointmentsModel.Appointments.ToList(); - - for (int i = 0; i < tempList.Count(); i++) + for(int i = 0; i < PIVOT_ITEM_PAGES; i++) { - tempList[i].OnClick += new AppointmentModel.OnAppointmentClick(this.EventOnAppointmentClick); - Canvas temp = tempList[i].GetCanvas(); - temp.Margin = new Thickness(DAY_TABLE_HEAD_WIDTH + 2, tempList[i].GetYOffset, 0, 0); - this.DayView.Children.Add(temp); - - /* - temp = this.testMod2.GetCanvas(); - temp.Margin = new Thickness(DAY_TABLE_HEAD_WIDTH + 2 + 2 + (maxW / 2), this.testMod2.GetYOffset, 0, 0); - this.DayView.Children.Add(temp); - */ + this.SetupItemPage(i, this.itemDate[i]); } } this.DayLayoutDone = true; } + private void EventPivotSelectionChanged(object sender, SelectionChangedEventArgs e) + { + int[] indexToChange = new int[2]; + + /* + 0: 2,3 + 1: 3,4 + 2: 4,0 + 3: 0,1 + 4: 1,2 + */ + + int delta = this.ThePivot.SelectedIndex - this.lastSelectedIndex; + + if (Math.Abs(delta) > 1) + { + delta = (delta < 0) ? -1 : 1; + } + + indexToChange[0] = (this.ThePivot.SelectedIndex + PIVOT_ITEM_PAGES_HALF_DOWN) % PIVOT_ITEM_PAGES; + indexToChange[1] = (indexToChange[0] + 1) % PIVOT_ITEM_PAGES; + + for (int i = 0; i < indexToChange.Count(); i++) + { + if (delta < 0) + { + this.itemDate[indexToChange[1 - i]] = this.itemDate[this.ThePivot.SelectedIndex].AddDays(delta * (PIVOT_ITEM_PAGES_HALF_DOWN + i)); + this.SetupItemPage(indexToChange[1 - i], this.itemDate[indexToChange[1 - i]]); + } + else + { + this.itemDate[indexToChange[i]] = this.itemDate[this.ThePivot.SelectedIndex].AddDays(delta * (PIVOT_ITEM_PAGES_HALF_DOWN + i)); + this.SetupItemPage(indexToChange[i], this.itemDate[indexToChange[i]]); + } + } + + this.lastSelectedIndex = this.ThePivot.SelectedIndex; + } + private void EventOnAppointmentClick(AppointmentModel sender) { int index = TimeTable.AppointmentsModel.Appointments.IndexOf(sender); @@ -77,21 +130,72 @@ namespace CampusAppWP8.Pages.TimeTable } } + private void OnClickToDay(object sender, EventArgs e) + { + this.itemPage_0_Day = DateTime.Now.AddDays(PIVOT_ITEM_PAGES_HALF_DOWN * -1); + this.ThePivot.SelectedIndex = PIVOT_ITEM_PAGES_HALF_DOWN; + + for (int i = 0; i < PIVOT_ITEM_PAGES; i++) + { + this.itemDate[i] = this.itemPage_0_Day.AddDays(i); + this.SetupItemPage(i, this.itemDate[i]); + } + } + private void AutoScrollToDay(object sender, EventArgs e) { if (this.DayLayoutDone == true) { - this.DayScroll.ScrollToVerticalOffset(DAY_TABLE_CELL_HEIGHT * 7); + for (int i = 0; i < PIVOT_ITEM_PAGES; i++) + { + (this.itemPages[i].Content as ScrollViewer).ScrollToVerticalOffset(DAY_TABLE_CELL_HEIGHT * 7); + } this.DayLayoutDone = false; - this.DayScroll.LayoutUpdated -= this.AutoScrollToDay; + //this.DayScroll.LayoutUpdated -= this.AutoScrollToDay; } } - private void DrawDayViewBackground() + private void SetupItemPage(int index, DateTime date) { - this.DayView.Height = DAY_TABLE_CELL_HEIGHT * 24; - + this.itemPages[index].Header = string.Format("{0:ddd dd.MM.yy}", date); + ((this.itemPages[index].Content as ScrollViewer).Content as Canvas).Children.Clear(); + + for (int i = 0; i < TimeTable.AppointmentsModel.Appointments.Count(); i++) + { + int appointmentIndex = -1; + + if ((appointmentIndex = TimeTable.AppointmentsModel.Appointments[i].IsDate(date)) > -1) + { + TimeTable.AppointmentsModel.Appointments[i].OnClick += new AppointmentModel.OnAppointmentClick(this.EventOnAppointmentClick); + Canvas temp = TimeTable.AppointmentsModel.Appointments[i].GetCanvas(); + temp.Margin = new Thickness(DAY_TABLE_HEAD_WIDTH + 2, TimeTable.AppointmentsModel.Appointments[i].GetYOffset, 0, 0); +// ((this.itemPages[index].Content as ScrollViewer).Content as Canvas).Children.Add(temp); + + /* + temp = this.testMod2.GetCanvas(); + temp.Margin = new Thickness(DAY_TABLE_HEAD_WIDTH + 2 + 2 + (maxW / 2), this.testMod2.GetYOffset, 0, 0); + this.DayView.Children.Add(temp); + */ + } + } + } + + private void SetupItemPageBackground(PivotItem item, DateTime date) + { + ScrollViewer sv = new ScrollViewer(); + Canvas ca = new Canvas(); + this.DrawDayViewBackground(ca); + + sv.Content = ca; + sv.LayoutUpdated += new EventHandler(this.AutoScrollToDay); + item.Content = sv; + } + + private void DrawDayViewBackground(Canvas dayView) + { + dayView.Height = DAY_TABLE_CELL_HEIGHT * 24; + Line vertLine = new Line(); vertLine.X1 = 0; vertLine.Y1 = 0; @@ -142,12 +246,12 @@ namespace CampusAppWP8.Pages.TimeTable hLineInn.StrokeDashArray.Add(4); hLineInn.StrokeThickness = DAY_TABLE_INNER_THICKNESS; - this.DayView.Children.Add(hLineHead); - this.DayView.Children.Add(hLineInn); + dayView.Children.Add(hLineHead); + dayView.Children.Add(hLineInn); if (i < 24) { - this.DayView.Children.Add(hLineHalf); + dayView.Children.Add(hLineHalf); // text TextBlock timeStamp = new TextBlock(); @@ -155,11 +259,11 @@ namespace CampusAppWP8.Pages.TimeTable timeStamp.Margin = new Thickness(0, (DAY_TABLE_CELL_HEIGHT * i) + 2, 0, 0); timeStamp.FontSize = 16; - this.DayView.Children.Add(timeStamp); + dayView.Children.Add(timeStamp); } } - this.DayView.Children.Add(vertLine); + dayView.Children.Add(vertLine); } } } \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs index 83b8bb35..46c94ba8 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.Designer.cs @@ -1059,6 +1059,15 @@ namespace CampusAppWP8.Resources { } } + /// + /// Sucht eine lokalisierte Zeichenfolge, die Heute ähnelt. + /// + public static string ToDay { + get { + return ResourceManager.GetString("ToDay", resourceCulture); + } + } + /// /// Sucht eine lokalisierte Zeichenfolge, die Aktualisieren ähnelt. /// diff --git a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx index d164954e..ed9a4cbb 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/AppResources.resx @@ -436,6 +436,7 @@ Bearbeiten + Einrichtung @@ -457,4 +458,7 @@ Es gibt keine Ergebnisse zur gestellten Anfrage + + Heute + \ No newline at end of file diff --git a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx index 4d8d7e59..1b9f790b 100644 --- a/CampusAppWP8/CampusAppWP8/Resources/Constants.resx +++ b/CampusAppWP8/CampusAppWP8/Resources/Constants.resx @@ -461,6 +461,7 @@ AppointmentIndex + Uebersicht