Merge branch 'feature/#103' into develop

This commit is contained in:
Christian Fiedler
2013-07-19 17:17:12 +02:00
9 changed files with 253 additions and 104 deletions

View File

@@ -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.
/// </summary>
/// <returns>true, if changes happend since last request, otherwise false</returns>
/// <returns>true, if changes happen since last request, otherwise false</returns>
public bool HasChanged()
{
bool retValue = false;

View File

@@ -221,7 +221,7 @@ namespace CampusAppWP8.Model.Departments
/// <summary>
/// Return true if there were changes in the chair list, otherwise false.
/// </summary>
/// <param name="reset">when true, the hasChanged flag will be reseted</param>
/// <param name="reset">when true, the hasChanged flag will be reset</param>
/// <returns>true, when changed, otherwise false</returns>
public bool HasChanged(bool reset = true)
{

View File

@@ -216,7 +216,6 @@ namespace CampusAppWP8
this.api.HttpGet(this.httpApiUri, this.OnLoadDataComplete);
}
}
/// <summary>

View File

@@ -8,6 +8,7 @@
namespace CampusAppWP8.Model.RSS
{
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Xml.Serialization;
/// <summary>
@@ -26,6 +27,7 @@ namespace CampusAppWP8.Model.RSS
public RSSChannelModel()
{
this.item = new ObservableCollection<RSSModel>();
this.item.CollectionChanged += new NotifyCollectionChangedEventHandler(this.OnListChanged);
}
/// <summary>
@@ -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++;
}
}
}
}
/// <summary>
/// Is called when the item list has changed.
/// Here used for the add event.
/// Set the index of the last list element.
/// </summary>
/// <param name="sender">item list</param>
/// <param name="e">event args</param>
private void OnListChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add)
{
ObservableCollection<RSSModel> list = sender as ObservableCollection<RSSModel>;
list[list.Count - 1].Index = list.Count - 1;
}
}
}
}

View File

@@ -20,7 +20,7 @@
<!-- LayoutRoot -->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!-- Pivotpage -->
<phone:Pivot x:Name="EventPivot" Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}">
<phone:Pivot x:Name="EventPivot" Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" SelectionChanged="OnPivotSelectionChange">
<!-- Pivotitem template -->
<phone:Pivot.HeaderTemplate>
<DataTemplate>
@@ -29,11 +29,10 @@
</phone:Pivot.HeaderTemplate>
<phone:Pivot.ItemTemplate>
<DataTemplate>
<Grid>
<Grid x:Name="EventParentGrid">
<Grid.RowDefinitions>
<!--<RowDefinition Height="100"/>-->
<RowDefinition Height="*"/>
<RowDefinition Height="90"/>
</Grid.RowDefinitions>
<Grid x:Name="EventTextGrid" Grid.Row="0">
@@ -47,14 +46,16 @@
<TextBlock x:Name="EventText" Text="{Binding Path=Text, Mode=OneWay}" Height="Auto" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="24" />
</ScrollViewer>
</Grid>
<phone:WebBrowser x:Name="WebBrowser" Grid.Row="0" IsScriptEnabled="True" Visibility="Collapsed"/>
<Button Name="EventHome" Content="{Binding Path=LocalizedResources.NewsHomeBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Click="EventHome_Click"/>
<Button Name="EventLink" Tag="{Binding Path=Link, Mode=OneWay}" Content="{Binding Path=LocalizedResources.NewsLinkBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="EventLink_Click"/>
<phone:WebBrowser x:Name="EventWebBrowser" Source="{Binding Path=Link, Mode=OneWay}" Grid.Row="0" IsScriptEnabled="True" Visibility="Collapsed"/>
</Grid>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False" Mode="Minimized" Opacity="1.0" >
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>

View File

@@ -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;
/// <summary>
/// EventPage, where every event fees has his own PivotItem.
@@ -20,16 +24,27 @@ namespace CampusAppWP8.Pages.Events
public partial class EventPage : PhoneApplicationPage
{
/// <summary>
/// for checking if the feed source is already set or not.
/// To checking if the feed source is already set or not.
/// </summary>
private bool isSourceSet = false;
/// <summary>
/// To store the last selected pivot index.
/// </summary>
private int lastSelectedIndex = -1;
/// <summary>
/// Initializes a new instance of the <see cref="EventPage" /> class.
/// </summary>
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);
}
/// <summary>
@@ -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<string, string> kvp in NavigationContext.QueryString)
{
o += string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value) + "\n";
}
MessageBox.Show("ERROR: pivotIndex out of range!!! (" + o + ")");
}
}
}
/// <summary>
/// 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.
/// </summary>
/// <param name="sender">clicked button</param>
/// <param name="sender">parent pivot object</param>
/// <param name="e">event args</param>
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;
}
/// <summary>
@@ -87,41 +116,17 @@ namespace CampusAppWP8.Pages.Events
/// </summary>
/// <param name="sender">clicked button</param>
/// <param name="e">event args</param>
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);
}
}
}

View File

@@ -20,7 +20,7 @@
<!-- LayoutRoot -->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!-- Pivotpage -->
<phone:Pivot x:Name="NewsPivot" Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}">
<phone:Pivot x:Name="NewsPivot" Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" SelectionChanged="OnPivotSelectionChange">
<!-- Pivotitem template -->
<phone:Pivot.HeaderTemplate>
<DataTemplate>
@@ -29,10 +29,9 @@
</phone:Pivot.HeaderTemplate>
<phone:Pivot.ItemTemplate>
<DataTemplate>
<Grid>
<Grid x:Name="NewsParentGrid">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="90"/>
</Grid.RowDefinitions>
<Grid x:Name="NewsTextGrid" Grid.Row="0">
@@ -47,13 +46,15 @@
</ScrollViewer>
</Grid>
<phone:WebBrowser x:Name="WebBrowser" Grid.Row="0" IsScriptEnabled="True" Visibility="Collapsed"/>
<Button Name="NewsHome" Content="{Binding Path=LocalizedResources.NewsHomeBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Click="NewsHome_Click"/>
<Button Name="NewsLink" Tag="{Binding Path=Link, Mode=OneWay}" Content="{Binding Path=LocalizedResources.NewsLinkBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Click="NewsLink_Click"/>
<phone:WebBrowser x:Name="NewsWebBrowser" Source="{Binding Path=Link, Mode=OneWay}" Grid.Row="0" IsScriptEnabled="True" Visibility="Collapsed"/>
</Grid>
</DataTemplate>
</phone:Pivot.ItemTemplate>
</phone:Pivot>
</Grid>
<phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="False" Mode="Minimized" Opacity="1.0" >
</shell:ApplicationBar>
</phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>

View File

@@ -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;
/// <summary>
/// EventPage, where every news fees has his own PivotItem.
/// </summary>
@@ -25,12 +28,23 @@ namespace CampusAppWP8.Pages.News
/// </summary>
private bool isSourceSet = false;
/// <summary>
/// To store the index of the last selected PivotItem.
/// </summary>
private int lastSelectedIndex = -1;
/// <summary>
/// Initializes a new instance of the <see cref="NewsPage" /> class.
/// </summary>
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);
}
/// <summary>
@@ -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
}
/// <summary>
/// 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.
/// </summary>
/// <param name="sender">clicked button</param>
/// <param name="sender">parent pivot object</param>
/// <param name="e">event args</param>
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;
}
/// <summary>
@@ -88,41 +109,17 @@ namespace CampusAppWP8.Pages.News
/// </summary>
/// <param name="sender">clicked button</param>
/// <param name="e">event args</param>
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);
}
}
}

View File

@@ -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;
/// <summary>
/// Collection of utility functions.
/// </summary>
public static class Utilities
{
/// <summary>
/// Comparison types.
/// </summary>
public enum DifferenceType
{
/// <summary>
/// Compare Equality.
/// </summary>
Equal,
/// <summary>
/// Compare if less.
/// </summary>
Less,
/// <summary>
/// Compare equality or less.
/// </summary>
LessEqual,
/// <summary>
/// Compare greater.
/// </summary>
Greater,
/// <summary>
/// Compare equality or greater.
/// </summary>
GreaterEqual
};
}
/// <summary>
/// Compares the difference between a specified DateTime and Now
/// and the specified time difference (in Days).
/// <example>
/// 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 .
/// </example>
/// </summary>
/// <param name="type">comparison type</param>
/// <param name="date">date to check</param>
/// <param name="totalDiff">difference to check</param>
/// <returns>true, if the comparison condition do not fail</returns>
public static bool DayDifference(DifferenceType type, DateTime date, double totalDiff)
{
bool retValue = false;
@@ -53,5 +95,95 @@ namespace CampusAppWP8.Utility
return retValue;
}
/// <summary>
/// Return a list of child UIElements of the root object with the specified element name.
/// </summary>
/// <param name="rootObj">root object</param>
/// <param name="elemName">name of the element(s)</param>
/// <returns>list of elements</returns>
public static List<DependencyObject> GetChild(DependencyObject rootObj, string elemName)
{
List<DependencyObject> retValue = new List<DependencyObject>();
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<DependencyObject>(GetChild(child as DependencyObject, elemName));
retValue = ret.ToList<DependencyObject>();
}
return retValue;
}
/// <summary>
/// Search for a UIElement with the specified name in the parent Grid and set its visibility.
/// </summary>
/// <param name="rootObj">root object</param>
/// <param name="parentGridName">name of the parent grid</param>
/// <param name="elemName">name of the UIElement</param>
/// <param name="vis">new visibility property state</param>
/// <param name="index">index of the element in the parent child list</param>
public static void SetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, Visibility vis, int index = 0)
{
List<DependencyObject> 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;
}
}
/// <summary>
/// Return the visibility property of a UIElement which is a child object of the specified parent grid element.
/// </summary>
/// <param name="rootObj">root object</param>
/// <param name="parentGridName">name of the parent grid</param>
/// <param name="elemName">name of the element</param>
/// <param name="index">index of the element in the child list of the parent</param>
/// <returns>visibility state</returns>
public static Visibility GetElementVisibility(DependencyObject rootObj, string parentGridName, string elemName, int index = 0)
{
Visibility retValue;
List<DependencyObject> 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;
}
}
}