Merge branch 'cf_eventsnews' into cf_departments

This commit is contained in:
Christian Fiedler
2013-06-07 13:32:35 +02:00
8 changed files with 455 additions and 204 deletions

View File

@@ -123,7 +123,7 @@
<Compile Include="pages\news\NewsPage.xaml.cs">
<DependentUpon>NewsPage.xaml</DependentUpon>
</Compile>
<Compile Include="pages\news\RSSItem.cs" />
<Compile Include="pages\RSSItem.cs" />
<Compile Include="pages\news\RSSNewsTemplate.xaml.cs">
<DependentUpon>RSSNewsTemplate.xaml</DependentUpon>
</Compile>

View File

@@ -1,4 +1,5 @@
//------------------------------------------------------------------------------
<<<<<<< HEAD
//------------------------------------------------------------------------------
// <auto-generated>
// Dieser Code wurde von einem Tool generiert.
// Laufzeitversion:4.0.30319.18046
@@ -294,6 +295,15 @@ namespace CampusAppWP8.Resources {
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Link ähnelt.
/// </summary>
public static string NewsLinkBtn {
get {
return ResourceManager.GetString("NewsLinkBtn", resourceCulture);
}
}
/// <summary>
/// Sucht eine lokalisierte Zeichenfolge, die Öffnungszeiten ähnelt.
/// </summary>
@@ -412,3 +422,5 @@ namespace CampusAppWP8.Resources {
}
}
}

View File

@@ -230,10 +230,10 @@
<data name="NewsHomeBtn" xml:space="preserve">
<value>zur Übersicht</value>
</data>
<data name="Faculty" xml:space="preserve">
<value>Fakultät</value>
</data>
<data name="Professorship_chairs" xml:space="preserve">
<value>Lehrstühle</value>
</data>
<data name="Faculty" xml:space="preserve">
<value>Fakultät</value>
</data>
<data name="Professorship_chairs" xml:space="preserve">
<value>Lehrstühle</value>
</data>
</root>

View File

@@ -1,91 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampusAppWP8.pages.news
{
class RSSItem
{
private string title;
private string text;
private DateTime timestamp;
public string Title
{
get { return this.title; }
set { this.title = value; }
}
public string Text
{
get { return this.text; }
set { this.text = HTMLUnicodeToString(value); }
}
public string Timestamp
{
get { return this.timestamp.ToString("R"); }
set { this.timestamp = DateTime.Parse(value); }
}
public string Date
{
get { return String.Format("{0:ddd, dd.MM.yyyy}", this.timestamp); }
}
public string Time
{
get { return String.Format("{0:h:mm} Uhr", this.timestamp); }
}
private string HTMLUnicodeToString(string htmluni)
{
StringBuilder retValue = new StringBuilder();
for(int i = 0; i < htmluni.Length; i++)
{
switch (htmluni[i])
{
case '&':
{
int startOff = i + 2;
int endOff = htmluni.IndexOf(';', startOff);
string sub = htmluni.Substring(startOff, endOff - startOff);
int cVal = int.Parse(sub);
switch (cVal)
{
case 128:
retValue.Append('€');
break;
default:
retValue.Append((char)cVal);
break;
}
i = endOff;
}
break;
case '<':
{
i = htmluni.IndexOf('>', i);
}
break;
case '\t':
break;
default:
{
retValue.Append(htmluni[i]);
}
break;
}
}
return retValue.ToString();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CampusAppWP8.pages.news
{
class RSSItem
{
private string title;
private string text;
private DateTime timestamp;
private string link;
public string Title
{
get { return this.title; }
set { this.title = value; }
}
public string Text
{
get { return this.text; }
set { this.text = HTMLUnicodeToString(value); }
}
public string Timestamp
{
get { return this.timestamp.ToString("R"); }
set { this.timestamp = DateTime.Parse(value); }
}
public DateTime DTTimestamp
{
get { return this.timestamp; }
set { this.timestamp = value; }
}
public string Date
{
get { return String.Format("{0:ddd, dd.MM.yyyy}", this.timestamp); }
}
public string Time
{
get { return String.Format("{0:h:mm} Uhr", this.timestamp); }
}
public string Link
{
get { return this.link; }
set { this.link = value; }
}
private string HTMLUnicodeToString(string htmluni)
{
StringBuilder retValue = new StringBuilder();
for(int i = 0; i < htmluni.Length; i++)
{
switch (htmluni[i])
{
case '&':
{
int startOff = i + 2;
int endOff = htmluni.IndexOf(';', startOff);
string sub = htmluni.Substring(startOff, endOff - startOff);
int cVal = int.Parse(sub);
switch (cVal)
{
case 128:
retValue.Append('€');
break;
default:
retValue.Append((char)cVal);
break;
}
i = endOff;
}
break;
case '<':
{
i = htmluni.IndexOf('>', i);
}
break;
case '\t':
break;
default:
{
retValue.Append(htmluni[i]);
}
break;
}
}
return retValue.ToString();
}
public static int CompareTimeStamp(RSSItem item1, RSSItem item2)
{
if (item1.DTTimestamp > item2.DTTimestamp)
return -1;
else
return 0;
}
}
}

View File

@@ -0,0 +1,27 @@
<phone:PhoneApplicationPage
x:Class="CampusAppWP8.pages.events.EventPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<!--LayoutRoot ist das Stammraster, in dem alle anderen Seiteninhalte platziert werden-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivotsteuerelement-->
<phone:Pivot x:Name="EventPivot" Title="{Binding Path=LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}">
<!--Pivotelement eins-->
<phone:PivotItem Name="EventPivotHome" Header="{Binding Path=LocalizedResources.EventApp_Title, Source={StaticResource LocalizedStrings}}">
<ListBox x:Name="ButtonPanel" Grid.Row="1">
</ListBox>
</phone:PivotItem>
</phone:Pivot>
</Grid>
</phone:PhoneApplicationPage>

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using Microsoft.Phone.Tasks;
// Should be CampusAppWP8.pages (for RSSItem).
using CampusAppWP8.pages.news;
namespace CampusAppWP8.pages.events
{
public partial class EventPage : PhoneApplicationPage
{
List<RSSItem> itemList;
public EventPage()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.itemList = new List<RSSItem>();
this.itemList.Clear();
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(WC_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("http://www.tu-cottbus.de/oracle-gateway/php/rss2feed_veranstaltungen.php"));
}
private void WC_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
int i = 0;
XElement xmlitems = XElement.Parse(e.Result);
List<XElement> elements = xmlitems.Descendants("item").ToList();
foreach (XElement rssItem in elements)
{
if(i < 12)
{
RSSItem rss = new RSSItem();
rss.Title = rssItem.Element("title").Value;
rss.Text = rssItem.Element("description").Value;
rss.Timestamp = rssItem.Element("pubDate").Value;
rss.Link = rssItem.Element("link").Value;
this.itemList.Add(rss);
i++;
}
}
this.itemList.Sort(RSSItem.CompareTimeStamp);
for(i = 0; i < this.itemList.Count(); i++)
{
Button btn = new Button();
btn.Name = "EventRowAppButton" + i;
btn.Content = this.itemList[i].Title;
btn.BorderBrush = null;
btn.Background = null;
btn.VerticalContentAlignment = VerticalAlignment.Stretch;
btn.HorizontalContentAlignment = HorizontalAlignment.Stretch;
btn.BorderThickness = new Thickness(0);
btn.Padding = new Thickness(0);
btn.Click += EventRowAppButton_Click;
btn.Tag = i;
PivotItem newPivItem = new PivotItem();
newPivItem.Name = "EventPivot" + i;
newPivItem.Header = this.itemList[i].Date;
RSSNewsTemplate pvContent = new RSSNewsTemplate();
pvContent.NewsHeadline.Text = this.itemList[i].Title;
pvContent.NewsText.Text = this.itemList[i].Text;
pvContent.NewsHome.Click += EventHome_Click;
pvContent.NewsLink.Click += EventLink_Click;
pvContent.NewsLink.Tag = i;
if (this.itemList[i].Link.Length == 0)
pvContent.NewsLink.Visibility = Visibility.Collapsed;
newPivItem.Content = pvContent;
EventPivot.Items.Add(newPivItem);
ButtonPanel.Items.Add(btn);
}
}
//
private void EventRowAppButton_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
EventPivot.SelectedIndex = (int)btn.Tag + 1;
}
private void EventHome_Click(object sender, RoutedEventArgs e)
{
EventPivot.SelectedIndex = 0;
}
private void EventLink_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(this.itemList[(int)btn.Tag].Link, UriKind.Absolute);
webBrowserTask.Show();
}
}
}

View File

@@ -1,106 +1,137 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml.Linq;
using System.Xml;
using System.IO;
namespace CampusAppWP8.pages.news
{
public partial class NewsPage : PhoneApplicationPage
{
List<RSSItem> itemList;
public NewsPage()
{
InitializeComponent();
}
//
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.itemList = new List<RSSItem>();
this.itemList.Clear();
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(WC_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("http://www.tu-cottbus.de/oracle-gateway/php/rss2feed_aktuelles.php"));
}
private void WC_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
int i = 0;
XElement xmlitems = XElement.Parse(e.Result);
List<XElement> elements = xmlitems.Descendants("item").ToList();
foreach (XElement rssItem in elements)
{
if(i < 12)
{
RSSItem rss = new RSSItem();
rss.Title = rssItem.Element("title").Value;
rss.Text = rssItem.Element("description").Value;
rss.Timestamp = rssItem.Element("pubDate").Value;
this.itemList.Add(rss);
Button btn = new Button();
btn.Name = "NewsRowAppButton" + i;
btn.Content = rss.Title;
btn.BorderBrush = null;
btn.Background = null;
btn.VerticalContentAlignment = VerticalAlignment.Stretch;
btn.HorizontalContentAlignment = HorizontalAlignment.Stretch;
btn.BorderThickness = new Thickness(0);
btn.Padding = new Thickness(0);
btn.Click += NewsRowAppButton_Click;
btn.Tag = i;
PivotItem newPivItem = new PivotItem();
newPivItem.Name = "NewsPivot" + i;
newPivItem.Header = rss.Date;
RSSNewsTemplate pvContent = new RSSNewsTemplate();
pvContent.NewsHeadline.Text = rss.Title;
pvContent.NewsText.Text = rss.Text;
pvContent.NewsHome.Click += NewsHome_Click;
newPivItem.Content = pvContent;
NewsPivot.Items.Add(newPivItem);
ButtonPanel.Items.Add(btn);
i++;
}
}
}
// Button Functions
private void NewsRowAppButton_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
NewsPivot.SelectedIndex = (int)btn.Tag + 1;
}
private void NewsHome_Click(object sender, RoutedEventArgs e)
{
NewsPivot.SelectedIndex = 0;
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using System.Xml.Linq;
using System.Xml;
using System.IO;
using Microsoft.Phone.Tasks;
namespace CampusAppWP8.pages.news
{
public partial class NewsPage : PhoneApplicationPage
{
List<RSSItem> itemList;
public NewsPage()
{
InitializeComponent();
}
//
protected override void OnNavigatedTo(NavigationEventArgs e)
{
this.itemList = new List<RSSItem>();
this.itemList.Clear();
WebClient wc = new WebClient();
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(WC_DownloadStringCompleted);
wc.DownloadStringAsync(new Uri("http://www.tu-cottbus.de/oracle-gateway/php/rss2feed_aktuelles.php"));
}
private void WC_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error != null)
return;
int i = 0;
XElement xmlitems = XElement.Parse(e.Result);
List<XElement> elements = xmlitems.Descendants("item").ToList();
foreach (XElement rssItem in elements)
{
if(i < 12)
{
RSSItem rss = new RSSItem();
rss.Title = rssItem.Element("title").Value;
rss.Text = rssItem.Element("description").Value;
rss.Timestamp = rssItem.Element("pubDate").Value;
this.itemList.Add(rss);
Button btn = new Button();
btn.Name = "NewsRowAppButton" + i;
btn.Content = rss.Title;
btn.BorderBrush = null;
btn.Background = null;
btn.VerticalContentAlignment = VerticalAlignment.Stretch;
btn.HorizontalContentAlignment = HorizontalAlignment.Stretch;
btn.BorderThickness = new Thickness(0);
btn.Padding = new Thickness(0);
btn.Click += NewsRowAppButton_Click;
btn.Tag = i;
PivotItem newPivItem = new PivotItem();
newPivItem.Name = "NewsPivot" + i;
newPivItem.Header = rss.Date;
RSSNewsTemplate pvContent = new RSSNewsTemplate();
pvContent.NewsHeadline.Text = rss.Title;
pvContent.NewsText.Text = rss.Text;
pvContent.NewsHome.Click += NewsHome_Click;
pvContent.NewsLink.Click += NewsLink_Click;
pvContent.NewsLink.Tag = i;
/*
{
double height = pvContent.NewsHeadline.Height * 0.99;
double width = pvContent.NewsHeadline.Width * 0.99;
Font tryFont = pvContent.NewsHeadline.Font;
Size tempSize = TextRenderer.MeasureText(pvContent.NewsHeadline.Text, tryFont);
float heightRatio = height / tempSize.Height;
float widthRatio = width / tempSize.Width;
tryFont = new Font(tryFont.FontFamily, tryFont.Size * Math.Min(widthRatio, heightRatio), tryFont.Style);
pvContent.NewsHeadline.Font = tryFont;
}
*/
if ((rss.Link == null) || (rss.Link.Length == 0))
pvContent.NewsLink.Visibility = Visibility.Collapsed;
newPivItem.Content = pvContent;
NewsPivot.Items.Add(newPivItem);
ButtonPanel.Items.Add(btn);
i++;
}
}
}
// Button Functions
private void NewsRowAppButton_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
NewsPivot.SelectedIndex = (int)btn.Tag + 1;
}
private void NewsHome_Click(object sender, RoutedEventArgs e)
{
NewsPivot.SelectedIndex = 0;
}
private void NewsLink_Click(object sender, RoutedEventArgs e)
{
Button btn = (Button)sender;
WebBrowserTask webBrowserTask = new WebBrowserTask();
webBrowserTask.Uri = new Uri(this.itemList[(int)btn.Tag].Link, UriKind.Absolute);
webBrowserTask.Show();
}
}
}

View File

@@ -1,3 +1,34 @@
<<<<<<< HEAD
<UserControl
x:Class="CampusAppWP8.pages.news.RSSNewsTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
mc:Ignorable="d"
shell:SystemTray.IsVisible="True">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="100"/>
<RowDefinition Height="*"/>
<RowDefinition Height="90"/>
</Grid.RowDefinitions>
<TextBlock x:Name="NewsHeadline" Text="(headline)" Grid.Row="0" Height="Auto" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="42"/>
<ScrollViewer Grid.Row="1">
<TextBlock x:Name="NewsText" Text="(text)" Height="Auto" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="24" />
</ScrollViewer>
<Button Name="NewsHome" Content="{Binding Path=LocalizedResources.NewsHomeBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
<Button Name="NewsLink" Content="{Binding Path=LocalizedResources.NewsLinkBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Right" />
</Grid>
</UserControl>
=======
<UserControl
x:Class="CampusAppWP8.pages.news.RSSNewsTemplate"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -26,3 +57,4 @@
<Button Name="NewsHome" Content="{Binding Path=LocalizedResources.NewsHomeBtn, Source={StaticResource LocalizedStrings}}" Grid.Row="2" VerticalAlignment="Bottom" HorizontalAlignment="Left" />
</Grid>
</UserControl>
>>>>>>> d70e3da558c01e1f589ef06e919074b36a45d32c