summaryrefslogtreecommitdiff
path: root/Juick/ViewModels/ThreadViewModel.cs
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2012-02-11 22:22:50 +0400
committerGravatar Vitaly Takmazov2012-02-11 22:22:50 +0400
commit49eb44f852ab21e72c17bbc436ffa79525a1aba3 (patch)
tree249cd1d69dc8078104dc2bc35cfcbbce98cd85f4 /Juick/ViewModels/ThreadViewModel.cs
v 0.999 :)
Diffstat (limited to 'Juick/ViewModels/ThreadViewModel.cs')
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs70
1 files changed, 70 insertions, 0 deletions
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
new file mode 100644
index 0000000..48ebe65
--- /dev/null
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.IO;
+using System.Net;
+using System.Net.Browser;
+using System.Runtime.Serialization.Json;
+using Juick.Api;
+using RestSharp;
+
+namespace Juick.ViewModels
+{
+ public class ThreadViewModel : INotifyPropertyChanged
+ {
+ public ThreadViewModel()
+ {
+ this.Items = new ObservableCollection<MessageViewModel>();
+ }
+
+ /// <summary>
+ /// A collection for MessageViewModel objects.
+ /// </summary>
+ public ObservableCollection<MessageViewModel> Items { get; private set; }
+
+ public bool IsDataLoaded
+ {
+ get;
+ private set;
+ }
+
+ public MessageViewModel Root { get; set; }
+
+ /// <summary>
+ /// Creates and adds a few MessageViewModel objects into the MyFeed collection.
+ /// </summary>
+ public void LoadData()
+ {
+ 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 =>
+ {
+ using (var responseStream = new MemoryStream(response.RawBytes))
+ {
+ var ser = new DataContractJsonSerializer(typeof (List<Message>));
+ var messages = (List<Message>) ser.ReadObject(responseStream);
+ Items.Clear();
+ messages.ForEach(post =>
+ {
+ this.Items.Add(
+ new MessageViewModel(post));
+ });
+ IsDataLoaded = true;
+ NotifyPropertyChanged("Items");
+ }
+ });
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ private void NotifyPropertyChanged(String propertyName)
+ {
+ PropertyChangedEventHandler handler = PropertyChanged;
+ if (null != handler)
+ {
+ handler(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+ }
+}