From cc4665499b182c32481d506d2e1e65ba41a6370b Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 3 Apr 2013 00:24:35 +0400 Subject: DelegateCommand and ReSharper refactoring --- Juick.sln | 9 ++++++++- Juick/App.xaml.cs | 4 +--- Juick/Classes/DelegateCommand.cs | 16 ++++++++-------- Juick/MainPage.xaml | 12 ------------ Juick/ThreadView.xaml | 20 ++++++++++---------- Juick/ViewModels/AppViewModel.cs | 22 ++++----------------- Juick/ViewModels/PageViewModel.cs | 40 ++++++++++++++++----------------------- Juick/ViewModels/PostItem.cs | 2 -- Juick/ViewModels/ViewModelBase.cs | 13 +------------ 9 files changed, 48 insertions(+), 90 deletions(-) diff --git a/Juick.sln b/Juick.sln index 83cc7a9..91623ef 100644 --- a/Juick.sln +++ b/Juick.sln @@ -1,8 +1,15 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2010 Express for Windows Phone +# Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Juick", "Juick\Juick.csproj", "{324D7F67-600D-4239-90D9-07C9CA17A4F3}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{6A493B4A-FF0A-420F-A47B-CEB4DB1D2DBA}" + ProjectSection(SolutionItems) = preProject + .nuget\NuGet.Config = .nuget\NuGet.Config + .nuget\NuGet.exe = .nuget\NuGet.exe + .nuget\NuGet.targets = .nuget\NuGet.targets + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/Juick/App.xaml.cs b/Juick/App.xaml.cs index e9fd258..8662972 100644 --- a/Juick/App.xaml.cs +++ b/Juick/App.xaml.cs @@ -5,15 +5,13 @@ using Juick.Classes; using Juick.ViewModels; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; -using RestSharp; namespace Juick { public partial class App : Application { public void NavigateTo(Uri param) { - var current = ((App)App.Current).RootFrame; - current.Navigate(param); + RootFrame.Navigate(param); } private static AppViewModel context = null; diff --git a/Juick/Classes/DelegateCommand.cs b/Juick/Classes/DelegateCommand.cs index 40256e5..b9ee13a 100644 --- a/Juick/Classes/DelegateCommand.cs +++ b/Juick/Classes/DelegateCommand.cs @@ -3,27 +3,27 @@ using System.Windows.Input; namespace Juick.Classes { - public class DelegateCommand : ICommand + public class DelegateCommand : ICommand { - readonly Action action; - readonly Func canExecute; + readonly Action _action; + readonly Func _canExecute; - public DelegateCommand(Action execute, Func canExecute) + public DelegateCommand(Action execute, Func canExecute) { - this.action = execute; - this.canExecute = canExecute; + _action = execute; + _canExecute = canExecute; } public bool CanExecute(object parameter) { - return canExecute(); + return _canExecute(); } public event EventHandler CanExecuteChanged; public void Execute(object parameter) { - action(parameter); + _action((T)parameter); } public void NotifyCanExecuteChanged() diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml index c6d6a3a..2e40d0f 100644 --- a/Juick/MainPage.xaml +++ b/Juick/MainPage.xaml @@ -7,8 +7,6 @@ xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" - xmlns:bindings="clr-namespace:Juick.Classes" xmlns:usercontrols="clr-namespace:Juick.Controls" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696" FontFamily="{StaticResource PhoneFontFamilyNormal}" @@ -23,18 +21,8 @@ - - - - - - - - diff --git a/Juick/ThreadView.xaml b/Juick/ThreadView.xaml index efab81a..0665055 100644 --- a/Juick/ThreadView.xaml +++ b/Juick/ThreadView.xaml @@ -3,7 +3,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" - xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" + xmlns:phoneshell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:controls="clr-namespace:Juick.Controls" xmlns:bindings="clr-namespace:Juick.Classes" @@ -12,7 +12,7 @@ Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" - shell:SystemTray.IsVisible="True"> + phoneshell:SystemTray.IsVisible="True"> @@ -78,14 +78,14 @@ 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 _pages; public ObservableCollection Pages { - get - { - if (_pages == null) - _pages = new ObservableCollection(); - return _pages; - } + get { return _pages ?? (_pages = new ObservableCollection()); } } static readonly string IsDataLoadingPropertyName = ExpressionHelper.GetPropertyName(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(); - LoadMessagesPageCommand = new DelegateCommand(LoadData, () => !context.IsDataLoading); - NavigateNextCommand = new DelegateCommand(NavigateToThread, () => true); + LoadMessagesPageCommand = new DelegateCommand(LoadData, () => !context.IsDataLoading); + NavigateNextCommand = new DelegateCommand(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 /// public ObservableCollection Items { get; private set; } - public DelegateCommand LoadMessagesPageCommand { get; private set; } + public DelegateCommand LoadMessagesPageCommand { get; private set; } - public DelegateCommand NavigateNextCommand { get; private set; } + public DelegateCommand 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 /// /// Creates and adds a few MessageViewModel objects into the Items collection. /// - 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>(request, ProcessResponse); - context.IsDataLoading = true; + _context.Client.Authenticator = new HttpBasicAuthenticator(_context.Account.Credentials.UserName, _context.Account.Credentials.Password); + _context.Client.ExecuteAsync>(request, ProcessResponse); + _context.IsDataLoading = true; } void ProcessResponse(IRestResponse> 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 { -- cgit v1.2.3