summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2013-03-29 14:01:06 +0400
committerGravatar Vitaly Takmazov2013-03-29 14:01:06 +0400
commitb5acc276a59879b5b5a14a1e9efb38b633e53a68 (patch)
treefa12a862fc668329737fbf5e28b21d86c18d9ffa
parent3be6eccab55ca90a060cb56882c5675a7ad875ce (diff)
PostItem refactoring
-rw-r--r--Juick/Converters/MidToUriConverter.cs29
-rw-r--r--Juick/Juick.csproj1
-rw-r--r--Juick/MainPage.xaml14
-rw-r--r--Juick/ViewModels/PostItem.cs20
-rw-r--r--Juick/ViewModels/ViewModelBase.cs17
5 files changed, 52 insertions, 29 deletions
diff --git a/Juick/Converters/MidToUriConverter.cs b/Juick/Converters/MidToUriConverter.cs
new file mode 100644
index 0000000..645b860
--- /dev/null
+++ b/Juick/Converters/MidToUriConverter.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.Windows.Data;
+using System.Globalization;
+
+namespace Juick.Converters
+{
+ public class MidToUriConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ int MID = (int)value;
+ return string.Format("/ThreadView.xaml?mid={0}", MID);
+ }
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ return null;
+ }
+ }
+}
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index b049ea1..9dd60ae 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -84,6 +84,7 @@
<Compile Include="Classes\ScrollViewerMonitor.cs" />
<Compile Include="Classes\TileHelper.cs" />
<Compile Include="Controls\HyperLinkRichTextBox.cs" />
+ <Compile Include="Converters\MidToUriConverter.cs" />
<Compile Include="LoginView.xaml.cs">
<DependentUpon>LoginView.xaml</DependentUpon>
</Compile>
diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml
index 013fc34..9df6925 100644
--- a/Juick/MainPage.xaml
+++ b/Juick/MainPage.xaml
@@ -7,16 +7,20 @@
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:converters="clr-namespace:Juick.Converters"
xmlns:bindings="clr-namespace:Juick.Classes" xmlns:controls1="clr-namespace:Juick.Controls"
- mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="728"
+ mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
phoneshell:SystemTray.IsVisible="True">
-
- <!--LayoutRoot is the root grid where all page content is placed-->
+ <phone:PhoneApplicationPage.Resources>
+ <converters:MidToUriConverter x:Key="uriConverter" />
+ </phone:PhoneApplicationPage.Resources>
+
+ <!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
@@ -52,7 +56,7 @@
bindings:ScrollViewerMonitor.AtEndCommand="{Binding LoadMessagesPageCommand}">
<ItemsControl.ItemTemplate>
<DataTemplate>
- <HyperlinkButton NavigateUri="{Binding MessageUri}">
+ <HyperlinkButton NavigateUri="{Binding MID, Converter={StaticResource uriConverter}}">
<HyperlinkButton.Template>
<ControlTemplate>
<Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="0 0 0 1">
@@ -107,7 +111,7 @@
bindings:ScrollViewerMonitor.AtEndCommand="{Binding LoadMessagesPageCommand}">
<ItemsControl.ItemTemplate>
<DataTemplate>
- <HyperlinkButton NavigateUri="{Binding MessageUri}">
+ <HyperlinkButton NavigateUri="{Binding MID, Converter={StaticResource uriConverter}}">
<HyperlinkButton.Template>
<ControlTemplate>
<Border BorderBrush="{StaticResource PhoneForegroundBrush}" BorderThickness="0 0 0 1">
diff --git a/Juick/ViewModels/PostItem.cs b/Juick/ViewModels/PostItem.cs
index 7e30a43..2072cf5 100644
--- a/Juick/ViewModels/PostItem.cs
+++ b/Juick/ViewModels/PostItem.cs
@@ -8,23 +8,24 @@ namespace Juick.ViewModels
{
public class PostItem
{
- public PostItem()
- {
-
- }
-
public PostItem(Message message)
{
MID = message.Mid;
- MessageUri = string.Format("/ThreadView.xaml?mid={0}", MID);
RID = message.Rid;
Username = message.User.UName;
+ Status = string.Format("Posted on: {0}, replies: {1}", message.Timestamp, message.Replies);
+
MessageText = HttpUtility.HtmlDecode(message.Body);
if (message.Tags != null)
{
MessageText = string.Join(", ", message.Tags) + Environment.NewLine + MessageText;
}
+ AvatarUri = new Uri(string.Format("http://i.juick.com/as/{0}.png", message.User.Uid), UriKind.Absolute);
+ if (message.Photo != null)
+ {
+ Attachment = new Uri(message.Photo.Small, UriKind.Absolute);
+ }
}
public int MID {get;set;}
@@ -36,11 +37,10 @@ namespace Juick.ViewModels
public Uri AvatarUri {get;set;}
public Uri Attachment {get;set;}
-
- public string MessageText {get;set;}
+
public string Status {get;set;}
-
- public string MessageUri {get;set;}
+
+ public string MessageText { get; set; }
}
} \ No newline at end of file
diff --git a/Juick/ViewModels/ViewModelBase.cs b/Juick/ViewModels/ViewModelBase.cs
index e86ff4a..2427a80 100644
--- a/Juick/ViewModels/ViewModelBase.cs
+++ b/Juick/ViewModels/ViewModelBase.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
@@ -88,20 +89,8 @@ namespace Juick.ViewModels
}
//Items.Clear();
- foreach (var post in response.Data)
- {
- var status = string.Format("Posted on: {0}, replies: {1}", post.Timestamp, post.Replies);
- var item = new PostItem(post)
- {
- Status = status,
- AvatarUri = new Uri(string.Format("http://i.juick.com/as/{0}.png", post.User.Uid), UriKind.Absolute)
- };
- if (post.Photo != null)
- {
- item.Attachment = new Uri(post.Photo.Small, UriKind.Absolute) ;
- }
- Items.Add(item);
- }
+ response.Data.Select(x => new PostItem(x)).ToList().ForEach(i => Items.Add(i));
+
}