summaryrefslogtreecommitdiff
path: root/Juick/ViewModels
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2012-03-10 20:43:42 +0400
committerGravatar Vitaly Takmazov2012-03-10 20:43:42 +0400
commitdebc2482e4899804a87cffd8ec79b98c230106bd (patch)
tree8e76faae285878d50f60281c0f53218ab3e81770 /Juick/ViewModels
parent6a92a6a4d27dc07f8b32bd7d57ffbcbe15630ab9 (diff)
Attachments, remove DataContractJsonSerializer
Diffstat (limited to 'Juick/ViewModels')
-rw-r--r--Juick/ViewModels/MainViewModel.cs49
-rw-r--r--Juick/ViewModels/MessageViewModel.cs33
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs11
3 files changed, 46 insertions, 47 deletions
diff --git a/Juick/ViewModels/MainViewModel.cs b/Juick/ViewModels/MainViewModel.cs
index 23ff020..ed244d7 100644
--- a/Juick/ViewModels/MainViewModel.cs
+++ b/Juick/ViewModels/MainViewModel.cs
@@ -45,18 +45,16 @@ namespace Juick.ViewModels
{
var request = new RestRequest("/home?1=1" + "&rnd=" + Environment.TickCount);
App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password);
- App.Client.ExecuteAsync(request, response =>
+ App.Client.ExecuteAsync<List<Message>>(request, response =>
{
if (response.StatusCode != HttpStatusCode.OK)
{
MessageBox.Show(response.StatusCode.ToString());
return;
}
- var ser = new DataContractJsonSerializer(typeof (List<Message>));
-
- var messages =
- ser.ReadObject(new MemoryStream(response.RawBytes)) as List<Message>;
- MyFeed.Clear();
+
+ var messages = response.Data;
+ MyFeed.Clear();
messages.ForEach(post =>
{
var item = new MessageViewModel(post)
@@ -64,16 +62,14 @@ namespace Juick.ViewModels
Status =
string.Format(
"Posted on: {0}, replies: {1}",
- post.
- timestamp,
- post.
- replies)
+ post.Timestamp,
+ post.Replies)
};
MyFeed.Add(item);
var imageRequest =
new RestRequest(
string.Format("/as/{0}.png",
- post.user.uid));
+ post.User.Uid));
App.AvatarClient.ExecuteAsync(
imageRequest, restResponse =>
{
@@ -88,15 +84,12 @@ namespace Juick.ViewModels
NotifyPropertyChanged("MyFeed");
});
- var lastrequest = new RestRequest("/messages?1=1" + "&rnd=" + Environment.TickCount);
- App.Client.ExecuteAsync(lastrequest, response =>
+ var lastrequest = new RestRequest("/messages?1=1&media=all" + "&rnd=" + Environment.TickCount);
+ App.Client.ExecuteAsync<List<Message>>(lastrequest, response =>
{
- var ser = new DataContractJsonSerializer(typeof(List<Message>));
- using (var ms = new MemoryStream(response.RawBytes))
- {
- var messages =
- (List<Message>)ser.ReadObject(ms);
- if (messages == null) return;
+
+ var messages = response.Data;
+ if (messages.Count == 0) return;
Last.Clear();
messages.ForEach(post =>
{
@@ -105,16 +98,14 @@ namespace Juick.ViewModels
Status =
string.Format(
"Posted on: {0}, replies: {1}",
- post.
- timestamp,
- post.
- replies)
+ post.Timestamp,
+ post.Replies)
};
Last.Add(item);
var imageRequest =
new RestRequest(
string.Format("/as/{0}.png",
- post.user.uid));
+ post.User.Uid));
App.AvatarClient.ExecuteAsync(
imageRequest, restResponse =>
{
@@ -124,10 +115,16 @@ namespace Juick.ViewModels
item.
NotifyPropertyChanged
("UserAvatar");
- });
+ });
+ if (post.Photo != null)
+ {
+ item.Attachment = new BitmapImage {UriSource = new Uri(post.Photo.Small, UriKind.Absolute)};
+ item.NotifyPropertyChanged("Attachment");
+ }
+
});
NotifyPropertyChanged("Last");
- }
+
});
}
diff --git a/Juick/ViewModels/MessageViewModel.cs b/Juick/ViewModels/MessageViewModel.cs
index 8620ab3..3a324c4 100644
--- a/Juick/ViewModels/MessageViewModel.cs
+++ b/Juick/ViewModels/MessageViewModel.cs
@@ -1,19 +1,10 @@
using System;
using System.ComponentModel;
-using System.Diagnostics;
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.Media.Imaging;
-using System.Windows.Shapes;
using Juick.Api;
-namespace Juick
+namespace Juick.ViewModels
{
public class MessageViewModel : INotifyPropertyChanged
{
@@ -24,10 +15,10 @@ namespace Juick
public MessageViewModel(Message message)
{
- MID = message.mid;
- RID = message.rid;
- Username = message.user.uname;
- MessageText = HttpUtility.HtmlDecode(message.body);
+ MID = message.Mid;
+ RID = message.Rid;
+ Username = message.User.UName;
+ MessageText = HttpUtility.HtmlDecode(message.Body);
}
private int _mid;
/// <summary>
@@ -105,6 +96,20 @@ namespace Juick
}
}
+ private BitmapImage _attach;
+ public BitmapImage Attachment
+ {
+ get { return _attach; }
+ set
+ {
+ if (value != _attach)
+ {
+ _attach = value;
+ NotifyPropertyChanged("Attachment");
+ }
+ }
+ }
+
private string _messageText;
/// <summary>
/// Sample ViewModel property; this property is used in the view to display its value using a Binding.
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
index bff72b7..80d8b3e 100644
--- a/Juick/ViewModels/ThreadViewModel.cs
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -40,12 +40,9 @@ namespace Juick.ViewModels
var request = new RestRequest("/thread?mid={mid}" + "&rnd=" + Environment.TickCount);
request.AddUrlSegment("mid", string.Format("{0}",Root.MID));
App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password);
- App.Client.ExecuteAsync(request, response =>
+ App.Client.ExecuteAsync<List<Message>>(request, response =>
{
- using (var responseStream = new MemoryStream(response.RawBytes))
- {
- var ser = new DataContractJsonSerializer(typeof (List<Message>));
- var messages = (List<Message>) ser.ReadObject(responseStream);
+ var messages = response.Data;
Items.Clear();
messages.ForEach(post =>
{
@@ -54,7 +51,7 @@ namespace Juick.ViewModels
var imageRequest =
new RestRequest(
string.Format("/as/{0}.png",
- post.user.uid));
+ post.User.Uid));
App.AvatarClient.ExecuteAsync(
imageRequest, restResponse =>
{
@@ -68,7 +65,7 @@ namespace Juick.ViewModels
});
IsDataLoaded = true;
NotifyPropertyChanged("Items");
- }
+
});
}