diff options
Diffstat (limited to 'Juick/ViewModels/PageViewModel.cs')
-rw-r--r-- | Juick/ViewModels/PageViewModel.cs | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/Juick/ViewModels/PageViewModel.cs b/Juick/ViewModels/PageViewModel.cs index 9b9cae5..ff64dac 100644 --- a/Juick/ViewModels/PageViewModel.cs +++ b/Juick/ViewModels/PageViewModel.cs @@ -2,15 +2,11 @@ using System.Linq; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.ComponentModel; using System.Net; using System.Windows; -using System.Windows.Media.Imaging; using Juick.Classes; using JuickApi; using RestSharp; -using System.Diagnostics; -using System.Windows.Navigation; using Microsoft.Phone.Controls; using System.Windows.Controls; @@ -20,13 +16,13 @@ namespace Juick.ViewModels { public PageViewModel(AppViewModel context) { - this.context = context; + _context = context; Items = new ObservableCollection<PostItem>(); - LoadMessagesPageCommand = new DelegateCommand(LoadData, () => !context.IsDataLoading); - NavigateNextCommand = new DelegateCommand(NavigateToThread, () => true); + LoadMessagesPageCommand = new DelegateCommand<LinkUnlinkEventArgs>(LoadData, () => !context.IsDataLoading); + NavigateNextCommand = new DelegateCommand<SelectionChangedEventArgs>(NavigateToThread, () => true); } - private AppViewModel context; + private readonly AppViewModel _context; public string RestUri { get; set; } public virtual string Caption { get { return "juick"; } } @@ -36,16 +32,15 @@ namespace Juick.ViewModels /// </summary> public ObservableCollection<PostItem> Items { get; private set; } - public DelegateCommand LoadMessagesPageCommand { get; private set; } + public DelegateCommand<LinkUnlinkEventArgs> LoadMessagesPageCommand { get; private set; } - public DelegateCommand NavigateNextCommand { get; private set; } + public DelegateCommand<SelectionChangedEventArgs> NavigateNextCommand { get; private set; } - public void NavigateToThread(object param) + public void NavigateToThread(SelectionChangedEventArgs param) { - var selectionChangedEventArgs = param as SelectionChangedEventArgs; if (param != null) { - ((App)App.Current).NavigateTo(new Uri(string.Format("/ThreadView.xaml?mid={0}", ((PostItem)selectionChangedEventArgs.AddedItems[0]).MID), UriKind.Relative)); + ((App)App.Current).NavigateTo(new Uri(string.Format("/ThreadView.xaml?mid={0}", ((PostItem)param.AddedItems[0]).MID), UriKind.Relative)); } } @@ -53,24 +48,21 @@ namespace Juick.ViewModels /// <summary> /// Creates and adds a few MessageViewModel objects into the Items collection. /// </summary> - public void LoadData(object EventArgs) + public void LoadData(LinkUnlinkEventArgs e) { const int offset = 5; - if (context.IsDataLoading) + if (_context.IsDataLoading) { return; } - if (EventArgs != null) + if (e != null) { - var item = (EventArgs as LinkUnlinkEventArgs).ContentPresenter.Content; + var item = e.ContentPresenter.Content; if (!item.Equals(Items[Items.Count - offset])) { return; } } - int count = Items.Count; - - if (string.IsNullOrEmpty(RestUri)) { RestUri = "/home?1=1"; @@ -90,14 +82,14 @@ namespace Juick.ViewModels } var request = new RestRequest(RestUri + "&rnd=" + Environment.TickCount); - context.Client.Authenticator = new HttpBasicAuthenticator(context.Account.Credentials.UserName, context.Account.Credentials.Password); - context.Client.ExecuteAsync<List<Message>>(request, ProcessResponse); - context.IsDataLoading = true; + _context.Client.Authenticator = new HttpBasicAuthenticator(_context.Account.Credentials.UserName, _context.Account.Credentials.Password); + _context.Client.ExecuteAsync<List<Message>>(request, ProcessResponse); + _context.IsDataLoading = true; } void ProcessResponse(IRestResponse<List<Message>> response) { - context.IsDataLoading = false; + _context.IsDataLoading = false; if (response.StatusCode != HttpStatusCode.OK) { MessageBox.Show(response.StatusCode.ToString()); |