summaryrefslogtreecommitdiff
path: root/Juick/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewModels')
-rw-r--r--Juick/ViewModels/AppViewModel.cs22
-rw-r--r--Juick/ViewModels/PageViewModel.cs40
-rw-r--r--Juick/ViewModels/PostItem.cs2
-rw-r--r--Juick/ViewModels/ViewModelBase.cs13
4 files changed, 21 insertions, 56 deletions
diff --git a/Juick/ViewModels/AppViewModel.cs b/Juick/ViewModels/AppViewModel.cs
index 5d22cab..50b95b8 100644
--- a/Juick/ViewModels/AppViewModel.cs
+++ b/Juick/ViewModels/AppViewModel.cs
@@ -1,13 +1,4 @@
using System;
-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.Shapes;
using System.Collections.ObjectModel;
using Juick.Classes;
using RestSharp;
@@ -19,23 +10,18 @@ namespace Juick.ViewModels
private ObservableCollection<PageViewModel> _pages;
public ObservableCollection<PageViewModel> Pages
{
- get
- {
- if (_pages == null)
- _pages = new ObservableCollection<PageViewModel>();
- return _pages;
- }
+ get { return _pages ?? (_pages = new ObservableCollection<PageViewModel>()); }
}
static readonly string IsDataLoadingPropertyName = ExpressionHelper.GetPropertyName<AppViewModel>(x => x.IsDataLoading);
- bool isDataLoading;
+ bool _isDataLoading;
public bool IsDataLoading
{
- get { return isDataLoading; }
+ get { return _isDataLoading; }
set
{
- isDataLoading = value;
+ _isDataLoading = value;
NotifyPropertyChanged(IsDataLoadingPropertyName);
foreach (var page in Pages)
{
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());
diff --git a/Juick/ViewModels/PostItem.cs b/Juick/ViewModels/PostItem.cs
index 2072cf5..97935b3 100644
--- a/Juick/ViewModels/PostItem.cs
+++ b/Juick/ViewModels/PostItem.cs
@@ -1,7 +1,5 @@
using System;
-using System.ComponentModel;
using System.Net;
-using System.Windows.Media.Imaging;
using JuickApi;
namespace Juick.ViewModels
diff --git a/Juick/ViewModels/ViewModelBase.cs b/Juick/ViewModels/ViewModelBase.cs
index 9ac3023..1c864db 100644
--- a/Juick/ViewModels/ViewModelBase.cs
+++ b/Juick/ViewModels/ViewModelBase.cs
@@ -1,15 +1,4 @@
-using System;
-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.Shapes;
-using System.ComponentModel;
-using Juick.Classes;
+using System.ComponentModel;
namespace Juick.ViewModels
{