Example #1
0
        public SampleDataSource()
        {
            _calendarYearData = new Dictionary <int, YearlyPanchangData>();
            var group = new SampleDataGroup("Group-1",
                                            "Group Title: 1",
                                            "Group Subtitle: 1",
                                            "Assets/DarkGray.png",
                                            "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");

            group.PanchangDataForYear = _calendarYearData;
            group.Year = _year;

            group.city = GetCityInformation(_cityToken);;
            // get two years worth of entries
            for (int year = _startYear; year <= (_startYear + 1); year++)
            {
                for (int month = 0; month < 12; month++)
                {
                    var item = new SampleDataItem(_monthStrings[month] + year,
                                                  _monthStrings[month],
                                                  _monthStrings[month],
                                                  "Assets/DarkGray.png",
                                                  "Group Description: {0} " + _monthStrings[month],
                                                  (month + 1).ToString(),
                                                  group);
                    group.Items.Add(item);
                    item.Year = year;
                }
            }
            this.ItemGroups.Add(group);
            _group = group;
        }
 public SampleDataSource()
 {
     _calendarYearData = new Dictionary<int, YearlyPanchangData>();
     var group = new SampleDataGroup("Group-1",
             "Group Title: 1",
             "Group Subtitle: 1",
             "Assets/DarkGray.png",
             "Group Description: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus tempor scelerisque lorem in vehicula. Aliquam tincidunt, lacus ut sagittis tristique, turpis massa volutpat augue, eu rutrum ligula ante a ante");
     group.PanchangDataForYear = _calendarYearData;
     group.Year = _year;
     
     group.city = GetCityInformation(_cityToken); ;
     // get two years worth of entries
     for (int year = _startYear; year <= (_startYear+1); year++)
     {
         for (int month = 0; month < 12; month++)
         {
             var item = new SampleDataItem(_monthStrings[month] + year,
                 _monthStrings[month],
                 _monthStrings[month],
                 "Assets/DarkGray.png",
                 "Group Description: {0} " + _monthStrings[month],
                 (month + 1).ToString(),
                 group);
             group.Items.Add(item);
             item.Year = year;
         }
     }
     this.ItemGroups.Add(group);
     _group = group;
 }
        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            // Allow saved page state to override the initial item to display
            if (pageState != null && pageState.ContainsKey("SelectedItem"))
            {
                navigationParameter = pageState["SelectedItem"];
            }

            var pData = (DayViewParameters)navigationParameter;
            _currentMonth = pData._month;
            _sampleItemDataForMonth = pData._item;
            this.DefaultViewModel["Group"] = _monthDataSource.ItemGroups[0];
            this.DefaultViewModel["Items"] = _monthDataSource.ItemGroups[0].Items;
            this.pageTitle.Text = _monthStrings[_currentMonth - 1] + " " + pData._day + " " + _sampleItemDataForMonth.Year + " For " + _sampleItemDataForMonth.Group.city._Name;
            this.flipView.SelectedItem = _monthDataSource.ItemGroups[0].Items[pData._day - 1];
        }
 public DayViewParameters(int month, int day, SampleDataItem item)
 {
     _month = month;
     _day = day;
     _item = item;
 }
 private void DisplayFeed(int day, SampleDataItem item, FlipViewItem selectedFlipViewItem)
 {
     TextBlock t;
     PanchangData pdata = item.GetPanchangData(_currentMonth, day);
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "SunriseTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Sunrise];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "SunsetTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Sunset];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "MoonRiseTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Moonrise];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "TamilYearTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.TamilYear];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "NorthYearTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.NorthYear];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "GujaratYearTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.GujaratYear];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "AyanaTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Ayana];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "RituTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Ritu];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "VedicRituTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.VedicRitu];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "TamilMonthTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.TamilMonth];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "SanskritMonthTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.SanskritMonth];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "PakshaTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Paksha];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "TithiTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Tithi];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "NakshatraTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Nakshatra];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "YogaTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Yoga];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "KaranaTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Karana];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "SunRasiTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.SunRasi];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "MoonRasiTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.MoonRasi];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "RahuKalamTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.RahuKalam];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "YamaKandamTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.YamaGandam];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "GulikaiTextBlock");
     t.Text = pdata._fieldValues[(int)FieldType.Gulikai];
     t = (TextBlock)FindNamedElement(selectedFlipViewItem, "FestivalTextBlock");
     String festival = pdata._fieldValues[(int)FieldType.Festival];
     if (String.IsNullOrEmpty(festival))
     {
         festival = "No festival";
     }
     t.Text = festival;
 }
        public void ScheduleTiles(SampleDataItem currentItem)
        {
            var notifier = Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication();
            var scheduled = notifier.GetScheduledTileNotifications();

            if (scheduled.Count > 0)
            {
                for (int i = 0; i < scheduled.Count; i++)
                {
                    Debug.WriteLine("Notification due time {0} delivery time {1}", scheduled[i].DeliveryTime, scheduled[i].ExpirationTime);
                }
                return;
            }

            notifier.Clear();
            notifier.EnableNotificationQueue(true); 
            // Schedule for the rest of the year
            DateTime today = DateTime.Today;
            int currentYear = currentItem.Year;
            for (int i = 0; i < 365; i++)
            {
                if (i == 0)
                {
                    // to get an immediate update add a tile 3 minutes from now
                    UpdateTile(currentItem, DateTime.Now.AddMinutes(1), DateTime.Today.AddDays(1));
                }
                else
                {
                    DateTime dueDate = today.AddDays(i);
                    if (dueDate.Year == currentYear)
                    {
                        UpdateTile(currentItem, DateTime.Today.AddDays(i), DateTime.Today.AddDays(i+1));
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Debug.WriteLine("Count of scheduled notifications {0}", notifier.GetScheduledTileNotifications().Count);
        }
 public void ShowDetail(int currentMonth, int day, SampleDataItem item)
 {
     PanchangData pdata = item.GetPanchangData(currentMonth, day);
     DateTime dateTime = new DateTime(item.Year, currentMonth, day);
     DateTextBlock.Text = dateTime.ToString("d");
     SunriseTextBlock.Text= pdata._fieldValues[(int)FieldType.Sunrise];
     SunsetTextBlock.Text = pdata._fieldValues[(int)FieldType.Sunset];
     MoonRiseTextBlock.Text = pdata._fieldValues[(int)FieldType.Moonrise];
     TamilYearTextBlock.Text = (pdata._fieldValues[(int)FieldType.TamilYear] == null) ? "None" : pdata._fieldValues[(int)FieldType.TamilYear];
     NorthYearTextBlock.Text = pdata._fieldValues[(int)FieldType.NorthYear];
     GujaratYearTextBlock.Text = pdata._fieldValues[(int)FieldType.GujaratYear];
     AyanaTextBlock.Text = pdata._fieldValues[(int)FieldType.Ayana];
     RituTextBlock.Text = pdata._fieldValues[(int)FieldType.Ritu];
     VedicRituTextBlock.Text = pdata._fieldValues[(int)FieldType.VedicRitu];
     TamilMonthTextBlock.Text = pdata._fieldValues[(int)FieldType.TamilMonth];
     // there is a whitespace in front of this string
     SanskritMonthTextBlock.Text = (pdata._fieldValues[(int)FieldType.SanskritMonth]).Trim();
     PakshaTextBlock.Text = (pdata._fieldValues[(int)FieldType.Paksha]).Trim();
     TithiTextBlock.Text = pdata._fieldValues[(int)FieldType.Tithi];
     NakshatraTextBlock.Text = pdata._fieldValues[(int)FieldType.Nakshatra];
     YogaTextBlock.Text = pdata._fieldValues[(int)FieldType.Yoga];
     KaranaTextBlock.Text = pdata._fieldValues[(int)FieldType.Karana];
     SunRasiTextBlock.Text = pdata._fieldValues[(int)FieldType.SunRasi];
     MoonRasiTextBlock.Text = pdata._fieldValues[(int)FieldType.MoonRasi];
     RahuKalamTextBlock.Text = pdata._fieldValues[(int)FieldType.RahuKalam];
     YamaKandamTextBlock.Text = pdata._fieldValues[(int)FieldType.YamaGandam];
     GulikaiTextBlock.Text = pdata._fieldValues[(int)FieldType.Gulikai];
     String festival = item.GetFestival(currentMonth, day);
     if (String.IsNullOrEmpty(festival))
     {
         festival = "No data";
     }
     FestivalTextBlock.Text = festival;
     PersonalEventListScroller.Visibility = Visibility.Collapsed;
     Separator.BorderThickness = new Thickness(0, 0, 0, 0);
     PersonalEventList.Items.Clear();
     if (_privateEvents != null)
     {
         List<PrivateEvent> privateEventList = _privateEvents.GetEventsForDate(dateTime);
         foreach (PrivateEvent evt in privateEventList)
         {
             AddPrivateEvent(dateTime, evt._eventText, false, evt);
         }
     }
 }
        // Update tile for today
        private void UpdateTile( SampleDataItem item, DateTime dueTime, DateTime expiryTime)
        {
            DateTime date = dueTime;
            int month = date.Month;
            int day = date.Day;
            String festival;
            var notifier = TileUpdateManager.CreateTileUpdaterForApplication();

            Debug.WriteLine("Update tile {0} {1}", dueTime, expiryTime);
            festival = item.GetFestival(month, day);
            PanchangData pdata = item.GetPanchangData(month, day);
            // create the wide template
            ITileWideText01 tileContent = TileContentFactory.CreateTileWideText01();
            tileContent.TextHeading.Text = date.ToString("d");
            tileContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.SanskritMonth];
            tileContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.TamilMonth];
            tileContent.TextBody3.Text = festival;

            // create the square template and attach it to the wide template
            ITileSquareText01 squareContent = TileContentFactory.CreateTileSquareText01();
            squareContent.TextHeading.Text = date.ToString("d");
            squareContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.SanskritMonth];
            squareContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.TamilMonth];
            squareContent.TextBody3.Text = festival;
            tileContent.SquareContent = squareContent;

            // send the notification
            ScheduledTileNotification futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime);
            futureTile.ExpirationTime = expiryTime;
            notifier.AddToSchedule(futureTile);


            // Send another notification. this gives a nice animation in mogo
            tileContent.TextBody1.Text = pdata._fieldValues[(int)FieldType.Paksha];
            tileContent.TextBody2.Text = pdata._fieldValues[(int)FieldType.Tithi];
            tileContent.TextBody3.Text = pdata._fieldValues[(int)FieldType.Nakshatra];
            futureTile = new ScheduledTileNotification(tileContent.GetXml(), dueTime);
            futureTile.ExpirationTime = expiryTime;
            notifier.AddToSchedule(futureTile);
            Debug.WriteLine("Count of scheduled notifications {0}", notifier.GetScheduledTileNotifications().Count);
        }
        private void BuildCalendar(Grid monthView, int month, SampleDataItem item) 
        {
            int row, col;
            DateItem[,] dateItems;

            if (monthView.Tag == null)
            {
                dateItems = new DateItem[numRows, numCols];

                for (row = 0; row < numRows; row++)
                {
                    for (col = 0; col < numCols; col++)
                    {
                        DateItem dateItem = new DateItem();
                        dateItem.SetValue(Grid.RowProperty, row);
                        dateItem.SetValue(Grid.ColumnProperty, col);
                        monthView.Children.Add(dateItem);
                        dateItems[row, col] = dateItem;
                        if (row == 0)
                        {
                            DayOfWeek day = (DayOfWeek)col;
                            dateItem.SetDay(_dayStrings[(int)day]);
                        }
                        else
                        {
                            dateItem.SetDay(" ");
                            dateItem.PointerReleased += dateItem_PointerReleased;
                        }
                    }
                }
                monthView.Tag = dateItems;
            }

            // collapse them all to be opened later
            dateItems = (DateItem[,])monthView.Tag;
            for (row = 1; row < numRows; row++)
            {
                for (col = 0; col < numCols; col++)
                {
                    dateItems[row, col].Visibility = Visibility.Collapsed;
                }
            }

            String previousTamilMonth, tamilMonth;
            String previousSanskritMonth, sanskritMonth;
            String previousPaksha, paksha;
            bool fullMoonDayFound = false;
            bool newMoonDayFound = false;
            DateItem currentDateItem = null;

            row = 1;
            previousTamilMonth = null;
            previousSanskritMonth = null;

            previousPaksha = "";
            tamilMonthTitle.Text = "";
            sanskritMonthTitle.Text = "";
            for (int day = 1; day <= 31 ; day++)
            {
                DateTime dateTime;
                try
                {
                    dateTime = new DateTime(item.Year, month, day);
                    col = (int)dateTime.DayOfWeek;
                    
                    String festival, nakshatra;
                    bool isNewMoonDay, isFullMoonDay;
                    bool highlight;

                    item.GetDateData(month, day, out isNewMoonDay, out isFullMoonDay, out festival, out paksha, out nakshatra, out tamilMonth);
                    PanchangData pdata = item.GetPanchangData(month, day);
                    sanskritMonth = pdata._fieldValues[(int)FieldType.SanskritMonth];

                    if (isNewMoonDay)
                    {
                        newMoonDayFound = true;
                    }

                    if (isFullMoonDay)
                    {
                        fullMoonDayFound = true;
                    }

                    // Sometimes the tithi changes in the middle of the day and is not captured. Lets fix it here
                    if ((previousPaksha.Contains("Shukla") == true) && (paksha.Contains("Krishna") == true) && (fullMoonDayFound == false))
                    {
                        // Set the previous item to full moon day
                        currentDateItem.SetDay(currentDateItem.GetDay(), false, true, null, null, "KeepExisting");
                    }

                    // Sometimes the tithi changes in the middle of the day and is not captured. Lets fix it here
                    if ((previousPaksha.Contains("Krishna") == true) && (paksha.Contains("Shukla") == true) && (newMoonDayFound == false))
                    {
                        // Set the previous item to new moon day
                        currentDateItem.SetDay(currentDateItem.GetDay(), true, false, null, null, "KeepExisting");
                    }

                    previousPaksha = paksha;

                    currentDateItem = dateItems[row, col];
                    PrivateEvent evt = null;
                    if (_privateEvents != null)
                    {
                        evt = _privateEvents.GetFirstEventForDate(dateTime);
                    }

                    if (evt != null)
                    {
                        currentDateItem.SetDay(day,
                            isNewMoonDay, isFullMoonDay, evt._eventText, null, nakshatra);
                    }
                    else
                    {
                        currentDateItem.SetDay(day,
                            isNewMoonDay, isFullMoonDay, festival, null, nakshatra);
                    }
                        
                    currentDateItem.Visibility = Visibility.Visible;
                    if (String.Equals(previousTamilMonth, tamilMonth, StringComparison.OrdinalIgnoreCase) == false)
                    {
                        tamilMonthTitle.Text += (previousTamilMonth == null) ? tamilMonth : ("-" + tamilMonth);
                        previousTamilMonth = tamilMonth;
                    }

                    if (String.Equals(previousSanskritMonth, sanskritMonth, StringComparison.OrdinalIgnoreCase) == false)
                    {
                        sanskritMonthTitle.Text += ((previousSanskritMonth == null) ? sanskritMonth : ("-" + sanskritMonth.Trim()));
                        previousSanskritMonth = sanskritMonth;
                    }

                    highlight = false;
                    // If its the curent month then highlight the current day
                    if (month == DateTime.Today.Month) 
                    {
                        if (day == DateTime.Today.Day)
                        {
                            // Highlight today
                            highlight = true;
                        }
                    }
                    else if (day == 1)
                    {
                        // Highlight the first day of some other month
                            highlight = true;
                    }

                    if (highlight)
                    { 
                        currentDateItem.HighlightBorder(true);
                        ShowDetail(month, day, item);
                        _currentHighlightedDateItem = currentDateItem;
                    }

                    if (col == (numCols-1))
                    {
                        row++;
                        if (row == numRows)
                        {
                            row = 1; // Reset it back to the first row. Provides a foldable calender
                        }
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                }
            }
        }