From 2b387fb5626a57e3a6473eed66816df80152cd49 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Sat, 10 Mar 2012 22:14:25 +0400 Subject: refactoring, tags --- Juick/ViewModels/ThreadViewModel.cs | 72 +++++-------------------------------- 1 file changed, 8 insertions(+), 64 deletions(-) (limited to 'Juick/ViewModels/ThreadViewModel.cs') diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs index a929700..e1f8152 100644 --- a/Juick/ViewModels/ThreadViewModel.cs +++ b/Juick/ViewModels/ThreadViewModel.cs @@ -1,73 +1,17 @@ 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 System.Windows.Media.Imaging; -using Juick.Api; -using RestSharp; namespace Juick.ViewModels { - public class ThreadViewModel : INotifyPropertyChanged + public class ThreadViewModel : MessageListViewModelBase { - public ThreadViewModel() + private int _mid; + public int Mid { - this.Items = new ObservableCollection(); - } - - /// - /// A collection for MessageViewModel objects. - /// - public ObservableCollection Items { get; private set; } - - public bool IsDataLoaded - { - get; - private set; - } - - public MessageViewModel Root { get; set; } - - /// - /// Creates and adds a few MessageViewModel objects into the MyFeed collection. - /// - 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 => - { - var messages = response.Data; - Items.Clear(); - messages.ForEach(post => - { - var item = new MessageViewModel(post); - Items.Add(item); - var imageUri = new Uri(string.Format("http://i.juick.com/as/{0}.png", post.User.Uid), UriKind.Absolute); - item.UserAvatar = new BitmapImage - { - UriSource = imageUri - }; - item.NotifyPropertyChanged("UserAvatar"); - }); - IsDataLoaded = true; - NotifyPropertyChanged("Items"); - - }); - } - - public event PropertyChangedEventHandler PropertyChanged; - private void NotifyPropertyChanged(String propertyName) - { - PropertyChangedEventHandler handler = PropertyChanged; - if (null != handler) - { - handler(this, new PropertyChangedEventArgs(propertyName)); + get { return _mid; } + set + { + _mid = value; + RestUri = string.Format("/thread?mid={0}", _mid) + "&rnd=" + Environment.TickCount; } } } -- cgit v1.2.3