diff --git a/CampusAppWP8/CampusAppWP8/Model/Departments/DepartmentModel.cs b/CampusAppWP8/CampusAppWP8/Model/Departments/DepartmentModel.cs
index 5b7db58d..c2256507 100644
--- a/CampusAppWP8/CampusAppWP8/Model/Departments/DepartmentModel.cs
+++ b/CampusAppWP8/CampusAppWP8/Model/Departments/DepartmentModel.cs
@@ -72,7 +72,7 @@ namespace CampusAppWP8.Model.Departments
/// Check if the content of the faculty lists hast changed since the
/// last call of this function.
///
- /// true, if changes happend since last request, otherwise false
+ /// true, if changes happen since last request, otherwise false
public bool HasChanged()
{
bool retValue = false;
diff --git a/CampusAppWP8/CampusAppWP8/Model/Departments/FacultyModel.cs b/CampusAppWP8/CampusAppWP8/Model/Departments/FacultyModel.cs
index 1c3419ef..f7b7407c 100644
--- a/CampusAppWP8/CampusAppWP8/Model/Departments/FacultyModel.cs
+++ b/CampusAppWP8/CampusAppWP8/Model/Departments/FacultyModel.cs
@@ -221,7 +221,7 @@ namespace CampusAppWP8.Model.Departments
///
/// Return true if there were changes in the chair list, otherwise false.
///
- /// when true, the hasChanged flag will be reseted
+ /// when true, the hasChanged flag will be reset
/// true, when changed, otherwise false
public bool HasChanged(bool reset = true)
{
diff --git a/CampusAppWP8/CampusAppWP8/Model/MainModel.cs b/CampusAppWP8/CampusAppWP8/Model/MainModel.cs
index d2346440..c37f74cb 100644
--- a/CampusAppWP8/CampusAppWP8/Model/MainModel.cs
+++ b/CampusAppWP8/CampusAppWP8/Model/MainModel.cs
@@ -216,7 +216,6 @@ namespace CampusAppWP8
this.api.HttpGet(this.httpApiUri, this.OnLoadDataComplete);
}
-
}
///
diff --git a/CampusAppWP8/CampusAppWP8/Model/RSS/RSSChannelModel.cs b/CampusAppWP8/CampusAppWP8/Model/RSS/RSSChannelModel.cs
index 52c1d499..fc8a8afe 100644
--- a/CampusAppWP8/CampusAppWP8/Model/RSS/RSSChannelModel.cs
+++ b/CampusAppWP8/CampusAppWP8/Model/RSS/RSSChannelModel.cs
@@ -8,6 +8,7 @@
namespace CampusAppWP8.Model.RSS
{
using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
using System.Xml.Serialization;
///
@@ -26,6 +27,7 @@ namespace CampusAppWP8.Model.RSS
public RSSChannelModel()
{
this.item = new ObservableCollection();
+ this.item.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged);
}
///
@@ -44,13 +46,25 @@ namespace CampusAppWP8.Model.RSS
if (value != this.item)
{
this.item = value;
- int i = 0;
- foreach (RSSModel rssItem in this.item)
- {
- rssItem.Index = i++;
- }
}
}
}
+
+ ///
+ /// Is called when the item list has changed.
+ /// Here used for the add event.
+ /// Set the index of the last list element.
+ ///
+ /// item list
+ /// event args
+ private void OnListChanged(object sender, NotifyCollectionChangedEventArgs e)
+ {
+ if (e.Action == NotifyCollectionChangedAction.Add)
+ {
+ ObservableCollection list = sender as ObservableCollection;
+
+ list[list.Count - 1].Index = list.Count - 1;
+ }
+ }
}
}
diff --git a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml
index 0f72f4bf..3a8919b5 100644
--- a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml
+++ b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml
@@ -20,7 +20,7 @@
-
+
@@ -29,11 +29,10 @@
-
+
-
@@ -47,14 +46,16 @@
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs
index 35882882..983da532 100644
--- a/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs
+++ b/CampusAppWP8/CampusAppWP8/Pages/Events/EventPage.xaml.cs
@@ -8,11 +8,15 @@
namespace CampusAppWP8.Pages.Events
{
using System;
+ using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
+ using CampusAppWP8.Resources;
+ using CampusAppWP8.Utility;
using Microsoft.Phone.Controls;
+ using Microsoft.Phone.Shell;
///
/// EventPage, where every event fees has his own PivotItem.
@@ -20,16 +24,27 @@ namespace CampusAppWP8.Pages.Events
public partial class EventPage : PhoneApplicationPage
{
///
- /// for checking if the feed source is already set or not.
+ /// To checking if the feed source is already set or not.
///
private bool isSourceSet = false;
+ ///
+ /// To store the last selected pivot index.
+ ///
+ private int lastSelectedIndex = -1;
+
///
/// Initializes a new instance of the class.
///
public EventPage()
{
this.InitializeComponent();
+
+ ApplicationBarIconButton linkBtn = new ApplicationBarIconButton();
+ linkBtn.IconUri = new Uri(Icons.Link, UriKind.Relative);
+ linkBtn.Text = AppResources.NewsLinkBtn;
+ linkBtn.Click += new EventHandler(this.EventLink_Click);
+ ApplicationBar.Buttons.Add(linkBtn);
}
///
@@ -52,7 +67,7 @@ namespace CampusAppWP8.Pages.Events
string pivotIndex = string.Empty;
// Navigate to the selected pivotitem
- if (NavigationContext.QueryString.TryGetValue("pivotindex", out pivotIndex))
+ if (NavigationContext.QueryString.TryGetValue(Constants.ParamPivotIndex, out pivotIndex))
{
int pivotIndexInt = int.Parse(pivotIndex);
@@ -63,21 +78,35 @@ namespace CampusAppWP8.Pages.Events
}
else
{
- MessageBox.Show("ERROR: pivotIndex out of range!!!");
+ string o = string.Empty;
+
+ foreach (KeyValuePair kvp in NavigationContext.QueryString)
+ {
+ o += string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value) + "\n";
+ }
+
+ MessageBox.Show("ERROR: pivotIndex out of range!!! (" + o + ")");
}
}
}
///
- /// On clicking the home button (lower left).
- /// Navigate back to the event index page.
+ /// Called when the index of the selected PivotItem is changed.
+ /// Set the text Grid to visible and the WebBrowser to collapsed.
///
- /// clicked button
+ /// parent pivot object
/// event args
- private void EventHome_Click(object sender, RoutedEventArgs e)
+ private void OnPivotSelectionChange(object sender, SelectionChangedEventArgs e)
{
- // Navigate back to the event index page
- NavigationService.GoBack();
+ int selIndex = (sender as Pivot).SelectedIndex;
+
+ if (this.lastSelectedIndex > -1)
+ {
+ Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventWebBrowser", Visibility.Collapsed, this.lastSelectedIndex);
+ Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", Visibility.Visible, this.lastSelectedIndex);
+ }
+
+ this.lastSelectedIndex = selIndex;
}
///
@@ -87,41 +116,17 @@ namespace CampusAppWP8.Pages.Events
///
/// clicked button
/// event args
- private void EventLink_Click(object sender, RoutedEventArgs e)
+ private void EventLink_Click(object sender, EventArgs e)
{
- FrameworkElement fe = sender as FrameworkElement;
-
- // Open the webbrowser
- Grid grfe = fe.Parent as Grid;
- FrameworkElement eventTextGrid = null;
- FrameworkElement eventWeb = null;
-
- foreach (FrameworkElement tempElem in grfe.Children)
+ if (Visibility.Visible == Utilities.GetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", this.EventPivot.SelectedIndex))
{
- if (tempElem.Name == "EventTextGrid")
- {
- eventTextGrid = tempElem;
- }
- else if (tempElem.Name == "WebBrowser")
- {
- eventWeb = tempElem;
- }
+ Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", Visibility.Collapsed, this.EventPivot.SelectedIndex);
+ Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventWebBrowser", Visibility.Visible, this.EventPivot.SelectedIndex);
}
-
- if ((eventTextGrid != null)
- && (eventWeb != null))
+ else
{
- if (eventTextGrid.Visibility == Visibility.Visible)
- {
- eventTextGrid.Visibility = Visibility.Collapsed;
- eventWeb.Visibility = Visibility.Visible;
- (eventWeb as WebBrowser).Navigate(new Uri(fe.Tag.ToString(), UriKind.Absolute));
- }
- else
- {
- eventWeb.Visibility = Visibility.Collapsed;
- eventTextGrid.Visibility = Visibility.Visible;
- }
+ Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventWebBrowser", Visibility.Collapsed, this.EventPivot.SelectedIndex);
+ Utilities.SetElementVisibility(this.EventPivot, "EventParentGrid", "EventTextGrid", Visibility.Visible, this.EventPivot.SelectedIndex);
}
}
}
diff --git a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml
index 887d4de0..9a86fb16 100644
--- a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml
+++ b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml
@@ -20,7 +20,7 @@
-
+
@@ -29,10 +29,9 @@
-
+
-
@@ -47,13 +46,15 @@
-
-
-
-
+
+
+
+
+
+
diff --git a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs
index 9454bc7e..7bcd863e 100644
--- a/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs
+++ b/CampusAppWP8/CampusAppWP8/Pages/News/NewsPage.xaml.cs
@@ -13,8 +13,11 @@ namespace CampusAppWP8.Pages.News
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
+ using CampusAppWP8.Resources;
+ using CampusAppWP8.Utility;
using Microsoft.Phone.Controls;
-
+ using Microsoft.Phone.Shell;
+
///
/// EventPage, where every news fees has his own PivotItem.
///
@@ -25,12 +28,23 @@ namespace CampusAppWP8.Pages.News
///
private bool isSourceSet = false;
+ ///
+ /// To store the index of the last selected PivotItem.
+ ///
+ private int lastSelectedIndex = -1;
+
///
/// Initializes a new instance of the class.
///
public NewsPage()
{
this.InitializeComponent();
+
+ ApplicationBarIconButton linkBtn = new ApplicationBarIconButton();
+ linkBtn.IconUri = new Uri(Icons.Link, UriKind.Relative);
+ linkBtn.Text = AppResources.NewsLinkBtn;
+ linkBtn.Click += new EventHandler(this.NewsLink_Click);
+ ApplicationBar.Buttons.Add(linkBtn);
}
///
@@ -53,7 +67,7 @@ namespace CampusAppWP8.Pages.News
string pivotIndex = string.Empty;
// Navigate to the selected pivotitem
- if (NavigationContext.QueryString.TryGetValue("pivotindex", out pivotIndex))
+ if (NavigationContext.QueryString.TryGetValue(Constants.ParamPivotIndex, out pivotIndex))
{
int pivotIndexInt = int.Parse(pivotIndex);
@@ -70,15 +84,22 @@ namespace CampusAppWP8.Pages.News
}
///
- /// On clicking the home button (lower left).
- /// Navigate back to the news index page.
+ /// Called when the index of the selected PivotItem is changed.
+ /// Set the text Grid to visible and the WebBrowser to collapsed.
///
- /// clicked button
+ /// parent pivot object
/// event args
- private void NewsHome_Click(object sender, RoutedEventArgs e)
+ private void OnPivotSelectionChange(object sender, SelectionChangedEventArgs e)
{
- // Navigate back to the news index page
- NavigationService.GoBack();
+ int selIndex = (sender as Pivot).SelectedIndex;
+
+ if (this.lastSelectedIndex > -1)
+ {
+ Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsWebBrowser", Visibility.Collapsed, this.lastSelectedIndex);
+ Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", Visibility.Visible, this.lastSelectedIndex);
+ }
+
+ this.lastSelectedIndex = selIndex;
}
///
@@ -88,41 +109,17 @@ namespace CampusAppWP8.Pages.News
///
/// clicked button
/// event args
- private void NewsLink_Click(object sender, RoutedEventArgs e)
+ private void NewsLink_Click(object sender, EventArgs e)
{
- FrameworkElement fe = sender as FrameworkElement;
-
- // Open the webbrowser
- Grid grfe = fe.Parent as Grid;
- FrameworkElement newsTextGrid = null;
- FrameworkElement newsWeb = null;
-
- foreach (FrameworkElement tempElem in grfe.Children)
+ if (Visibility.Visible == Utilities.GetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", this.NewsPivot.SelectedIndex))
{
- if (tempElem.Name == "NewsTextGrid")
- {
- newsTextGrid = tempElem;
- }
- else if (tempElem.Name == "WebBrowser")
- {
- newsWeb = tempElem;
- }
+ Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", Visibility.Collapsed, this.NewsPivot.SelectedIndex);
+ Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsWebBrowser", Visibility.Visible, this.NewsPivot.SelectedIndex);
}
-
- if ((newsTextGrid != null)
- && (newsWeb != null))
+ else
{
- if (newsTextGrid.Visibility == Visibility.Visible)
- {
- newsTextGrid.Visibility = Visibility.Collapsed;
- newsWeb.Visibility = Visibility.Visible;
- (newsWeb as WebBrowser).Navigate(new Uri(fe.Tag.ToString(), UriKind.Absolute));
- }
- else
- {
- newsWeb.Visibility = Visibility.Collapsed;
- newsTextGrid.Visibility = Visibility.Visible;
- }
+ Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsWebBrowser", Visibility.Collapsed, this.NewsPivot.SelectedIndex);
+ Utilities.SetElementVisibility(this.NewsPivot, "NewsParentGrid", "NewsTextGrid", Visibility.Visible, this.NewsPivot.SelectedIndex);
}
}
}
diff --git a/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs b/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs
index 2c700413..f324d9da 100644
--- a/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs
+++ b/CampusAppWP8/CampusAppWP8/Utility/Utilities.cs
@@ -8,19 +8,61 @@
namespace CampusAppWP8.Utility
{
using System;
-
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Windows;
+ using System.Windows.Controls;
+ using System.Windows.Media;
+
+ ///
+ /// Collection of utility functions.
+ ///
public static class Utilities
{
+ ///
+ /// Comparison types.
+ ///
public enum DifferenceType
{
+ ///
+ /// Compare Equality.
+ ///
Equal,
+
+ ///
+ /// Compare if less.
+ ///
Less,
+
+ ///
+ /// Compare equality or less.
+ ///
LessEqual,
+
+ ///
+ /// Compare greater.
+ ///
Greater,
+
+ ///
+ /// Compare equality or greater.
+ ///
GreaterEqual
- };
-
+ }
+ ///
+ /// Compares the difference between a specified DateTime and Now
+ /// and the specified time difference (in Days).
+ ///
+ /// When type is DifferenceType.Less, the timespan between Now and date
+ /// is 5.0 (days) and totalDiff is 7.0, the function will return true,
+ /// because the timespan is Less then 7.0 .
+ ///
+ ///
+ /// comparison type
+ /// date to check
+ /// difference to check
+ /// true, if the comparison condition do not fail
public static bool DayDifference(DifferenceType type, DateTime date, double totalDiff)
{
bool retValue = false;
@@ -53,5 +95,95 @@ namespace CampusAppWP8.Utility
return retValue;
}
+
+ ///
+ /// Return a list of child UIElements of the root object with the specified element name.
+ ///
+ /// root object
+ /// name of the element(s)
+ /// list of elements
+ public static List GetChild(DependencyObject rootObj, string elemName)
+ {
+ List retValue = new List();
+
+ for (int k = 0; k < VisualTreeHelper.GetChildrenCount(rootObj); k++)
+ {
+ var child = VisualTreeHelper.GetChild(rootObj, k);
+
+ if ((child as FrameworkElement).Name.Equals(elemName))
+ {
+ retValue.Add(child);
+ }
+
+ var ret = retValue.Concat(GetChild(child as DependencyObject, elemName));
+ retValue = ret.ToList();
+ }
+
+ return retValue;
+ }
+
+ ///
+ /// Search for a UIElement with the specified name in the parent Grid and set its visibility.
+ ///
+ /// root object
+ /// name of the parent grid
+ /// name of the UIElement
+ /// new visibility property state
+ /// index of the element in the parent child list
+ public static void SetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, Visibility vis, int index = 0)
+ {
+ List l = Utilities.GetChild(rootObj, parentGridName);
+ Grid parentGrid = l[index] as Grid;
+ FrameworkElement elem = null;
+
+ foreach (FrameworkElement tempElem in parentGrid.Children)
+ {
+ if (tempElem.Name == elemName)
+ {
+ elem = tempElem;
+ }
+ }
+
+ if (elem != null)
+ {
+ elem.Visibility = vis;
+ }
+ }
+
+ ///
+ /// Return the visibility property of a UIElement which is a child object of the specified parent grid element.
+ ///
+ /// root object
+ /// name of the parent grid
+ /// name of the element
+ /// index of the element in the child list of the parent
+ /// visibility state
+ public static Visibility GetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, int index = 0)
+ {
+ Visibility retValue;
+
+ List l = Utilities.GetChild(rootObj, parentGridName);
+ Grid parentGrid = l[index] as Grid;
+ FrameworkElement elem = null;
+
+ foreach (FrameworkElement tempElem in parentGrid.Children)
+ {
+ if (tempElem.Name == elemName)
+ {
+ elem = tempElem;
+ }
+ }
+
+ if (elem != null)
+ {
+ retValue = elem.Visibility;
+ }
+ else
+ {
+ throw new NotImplementedException("Could not find a UIElement with name (" + elemName + ")");
+ }
+
+ return retValue;
+ }
}
}
\ No newline at end of file