summaryrefslogtreecommitdiff
path: root/Juick/ViewModels
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2012-02-12 01:53:36 +0400
committerGravatar Vitaly Takmazov2012-02-12 01:53:36 +0400
commit6a92a6a4d27dc07f8b32bd7d57ffbcbe15630ab9 (patch)
treecf62fc48a13eb5b8744b361acf47bdcd820751a1 /Juick/ViewModels
parent49eb44f852ab21e72c17bbc436ffa79525a1aba3 (diff)
Avatars support + broken clickable urls
Diffstat (limited to 'Juick/ViewModels')
-rw-r--r--Juick/ViewModels/MainViewModel.cs76
-rw-r--r--Juick/ViewModels/MessageViewModel.cs8
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs19
3 files changed, 82 insertions, 21 deletions
diff --git a/Juick/ViewModels/MainViewModel.cs b/Juick/ViewModels/MainViewModel.cs
index a504658..23ff020 100644
--- a/Juick/ViewModels/MainViewModel.cs
+++ b/Juick/ViewModels/MainViewModel.cs
@@ -2,10 +2,13 @@
using System.ComponentModel;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Net;
using System.Runtime.Serialization.Json;
using System.Collections.ObjectModel;
using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media.Imaging;
using Juick.Api;
using RestSharp;
@@ -52,16 +55,36 @@ namespace Juick.ViewModels
var ser = new DataContractJsonSerializer(typeof (List<Message>));
var messages =
- (List<Message>)ser.ReadObject(new MemoryStream(response.RawBytes));
+ ser.ReadObject(new MemoryStream(response.RawBytes)) as List<Message>;
MyFeed.Clear();
- messages.ForEach(post => MyFeed.Add(new MessageViewModel(post)
- {
- Status =
- string.Format(
- "Posted on: {0}, replies: {1}",
- post.timestamp,
- post.replies)
- }));
+ messages.ForEach(post =>
+ {
+ var item = new MessageViewModel(post)
+ {
+ Status =
+ string.Format(
+ "Posted on: {0}, replies: {1}",
+ post.
+ timestamp,
+ post.
+ replies)
+ };
+ MyFeed.Add(item);
+ var imageRequest =
+ new RestRequest(
+ string.Format("/as/{0}.png",
+ post.user.uid));
+ App.AvatarClient.ExecuteAsync(
+ imageRequest, restResponse =>
+ {
+ item.UserAvatar = new BitmapImage
+ ();
+ item.UserAvatar.SetSource(new MemoryStream(restResponse.RawBytes));
+ item.
+ NotifyPropertyChanged
+ ("UserAvatar");
+ });
+ });
NotifyPropertyChanged("MyFeed");
});
@@ -75,13 +98,34 @@ namespace Juick.ViewModels
(List<Message>)ser.ReadObject(ms);
if (messages == null) return;
Last.Clear();
- messages.ForEach(post => Last.Add(new MessageViewModel(post)
+ messages.ForEach(post =>
{
- Status = string.Format(
- "Posted on: {0}, replies: {1}",
- post.timestamp, post.replies
- )
- }));
+ var item = new MessageViewModel(post)
+ {
+ Status =
+ string.Format(
+ "Posted on: {0}, replies: {1}",
+ post.
+ timestamp,
+ post.
+ replies)
+ };
+ Last.Add(item);
+ var imageRequest =
+ new RestRequest(
+ string.Format("/as/{0}.png",
+ post.user.uid));
+ App.AvatarClient.ExecuteAsync(
+ imageRequest, restResponse =>
+ {
+ item.UserAvatar = new BitmapImage
+ ();
+ item.UserAvatar.SetSource(new MemoryStream(restResponse.RawBytes));
+ item.
+ NotifyPropertyChanged
+ ("UserAvatar");
+ });
+ });
NotifyPropertyChanged("Last");
}
});
@@ -89,7 +133,7 @@ namespace Juick.ViewModels
public event PropertyChangedEventHandler PropertyChanged;
- private void NotifyPropertyChanged(String propertyName)
+ public void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
diff --git a/Juick/ViewModels/MessageViewModel.cs b/Juick/ViewModels/MessageViewModel.cs
index 32da0aa..8620ab3 100644
--- a/Juick/ViewModels/MessageViewModel.cs
+++ b/Juick/ViewModels/MessageViewModel.cs
@@ -9,6 +9,7 @@ using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
+using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Juick.Api;
@@ -90,8 +91,8 @@ namespace Juick
}
}
- private Image _avatar;
- public Image UserAvatar
+ private BitmapImage _avatar;
+ public BitmapImage UserAvatar
{
get { return _avatar; }
set
@@ -147,7 +148,8 @@ namespace Juick
}
public event PropertyChangedEventHandler PropertyChanged;
- private void NotifyPropertyChanged(String propertyName)
+
+ public void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
index 48ebe65..bff72b7 100644
--- a/Juick/ViewModels/ThreadViewModel.cs
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -6,6 +6,7 @@ using System.IO;
using System.Net;
using System.Net.Browser;
using System.Runtime.Serialization.Json;
+using System.Windows.Media.Imaging;
using Juick.Api;
using RestSharp;
@@ -48,8 +49,22 @@ namespace Juick.ViewModels
Items.Clear();
messages.ForEach(post =>
{
- this.Items.Add(
- new MessageViewModel(post));
+ var item = new MessageViewModel(post);
+ Items.Add(item);
+ var imageRequest =
+ new RestRequest(
+ string.Format("/as/{0}.png",
+ post.user.uid));
+ App.AvatarClient.ExecuteAsync(
+ imageRequest, restResponse =>
+ {
+ item.UserAvatar = new BitmapImage
+ ();
+ item.UserAvatar.SetSource(new MemoryStream(restResponse.RawBytes));
+ item.
+ NotifyPropertyChanged
+ ("UserAvatar");
+ });
});
IsDataLoaded = true;
NotifyPropertyChanged("Items");