From b5acc276a59879b5b5a14a1e9efb38b633e53a68 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 29 Mar 2013 14:01:06 +0400 Subject: PostItem refactoring --- Juick/Converters/MidToUriConverter.cs | 29 +++++++++++++++++++++++++++++ Juick/Juick.csproj | 1 + Juick/MainPage.xaml | 14 +++++++++----- Juick/ViewModels/PostItem.cs | 20 ++++++++++---------- Juick/ViewModels/ViewModelBase.cs | 17 +++-------------- 5 files changed, 52 insertions(+), 29 deletions(-) create mode 100644 Juick/Converters/MidToUriConverter.cs 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 @@ + LoginView.xaml 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"> - - + + + + + @@ -52,7 +56,7 @@ bindings:ScrollViewerMonitor.AtEndCommand="{Binding LoadMessagesPageCommand}"> - + @@ -107,7 +111,7 @@ bindings:ScrollViewerMonitor.AtEndCommand="{Binding LoadMessagesPageCommand}"> - + 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)); + } -- cgit v1.2.3