From f2a831eb785ca81a069406f7df0f3890ac2be90a Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Fri, 26 Apr 2013 23:44:07 +0400 Subject: redo old commit --- Juick/Classes/BooleanToVisibilityConverter.cs | 21 +++++++++++ Juick/Juick.csproj | 1 + Juick/MainPage.xaml | 16 ++++++--- Juick/ViewModels/AppViewModel.cs | 20 +++++++++++ Juick/ViewModels/PageViewModel.cs | 2 ++ Juick/ViewModels/Validation/DataViewModelBase.cs | 44 ------------------------ 6 files changed, 55 insertions(+), 49 deletions(-) create mode 100644 Juick/Classes/BooleanToVisibilityConverter.cs delete mode 100644 Juick/ViewModels/Validation/DataViewModelBase.cs (limited to 'Juick') diff --git a/Juick/Classes/BooleanToVisibilityConverter.cs b/Juick/Classes/BooleanToVisibilityConverter.cs new file mode 100644 index 0000000..cd7e000 --- /dev/null +++ b/Juick/Classes/BooleanToVisibilityConverter.cs @@ -0,0 +1,21 @@ +using System; +using System.Globalization; +using System.Windows; +using System.Windows.Data; + +namespace Juick.Classes +{ + public class BooleanToVisibiltyConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + var visible = (bool)value; + return visible ? Visibility.Visible : Visibility.Collapsed; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj index c3fe200..c89c775 100644 --- a/Juick/Juick.csproj +++ b/Juick/Juick.csproj @@ -82,6 +82,7 @@ App.xaml + diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml index 306555c..d2c99df 100644 --- a/Juick/MainPage.xaml +++ b/Juick/MainPage.xaml @@ -7,22 +7,28 @@ 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:usercontrols="clr-namespace:Juick.Controls" + xmlns:usercontrols="clr-namespace:Juick.Controls" xmlns:classes="clr-namespace:Juick.Classes" mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" phoneshell:SystemTray.IsVisible="True" CacheMode="BitmapCache"> - - + + + + + + + + - - + + diff --git a/Juick/ViewModels/AppViewModel.cs b/Juick/ViewModels/AppViewModel.cs index ab00cb0..e3a58bb 100644 --- a/Juick/ViewModels/AppViewModel.cs +++ b/Juick/ViewModels/AppViewModel.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; +using System.Net.NetworkInformation; using Juick.Classes; using JuickApi; +using Microsoft.Phone.Net.NetworkInformation; using RestSharp; using Microsoft.Phone.Notification; using System.Diagnostics; @@ -13,13 +15,21 @@ namespace Juick.ViewModels { public class AppViewModel : ViewModelBase { + static readonly string IsNetworkAvailablePropertyName = ExpressionHelper.GetPropertyName(x => x.NetworkUnavailable); readonly HttpNotificationChannel pushChannel; // The name of our push channel. string channelName = "JuickChannel"; + public void UpdateNetworkStatus() + { + NetworkUnavailable = !DeviceNetworkInformation.IsNetworkAvailable; + } + public AppViewModel() { + UpdateNetworkStatus(); + NetworkChange.NetworkAddressChanged += (sender, args) => UpdateNetworkStatus(); pushChannel = HttpNotificationChannel.Find(channelName); // If the channel was not found, then create a new connection to the push service. @@ -120,6 +130,16 @@ namespace Juick.ViewModels } } } + private bool _isNetworkUnavailable; + public bool NetworkUnavailable + { + get { return _isNetworkUnavailable; } + set + { + _isNetworkUnavailable = value; + NotifyPropertyChanged(IsNetworkAvailablePropertyName); + } + } private AccountManager _acc; diff --git a/Juick/ViewModels/PageViewModel.cs b/Juick/ViewModels/PageViewModel.cs index e398caf..ce48449 100644 --- a/Juick/ViewModels/PageViewModel.cs +++ b/Juick/ViewModels/PageViewModel.cs @@ -72,6 +72,8 @@ namespace Juick.ViewModels _context.Client.ExecuteAsync>(request, response => { _context.IsDataLoading = false; + if (response.Data == null) + return; response.Data.Select(x => new PostItem(x)).ToList().ForEach(i => Items.Add(i)); }); _context.IsDataLoading = true; diff --git a/Juick/ViewModels/Validation/DataViewModelBase.cs b/Juick/ViewModels/Validation/DataViewModelBase.cs deleted file mode 100644 index dcbf34b..0000000 --- a/Juick/ViewModels/Validation/DataViewModelBase.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; - -namespace Juick.ViewModels.Validation -{ - public class DataViewModelBase : ViewModelBase, IDataErrorInfo - { - - private readonly Dictionary> _errors = - new Dictionary>(); - - // Adds the specified error to the errors collection if it is not already - // present, inserting it in the first position if isWarning is false. - public void AddError(string propertyName, string error, bool isWarning) - { - if (!_errors.ContainsKey(propertyName)) - _errors[propertyName] = new List(); - - if (_errors[propertyName].Contains(error)) return; - if (isWarning) _errors[propertyName].Add(error); - else _errors[propertyName].Insert(0, error); - } - - // Removes the specified error from the errors collection if it is present. - public void RemoveError(string propertyName, string error) - { - if (!_errors.ContainsKey(propertyName) || !_errors[propertyName].Contains(error)) return; - _errors[propertyName].Remove(error); - if (_errors[propertyName].Count == 0) _errors.Remove(propertyName); - } - - public string Error { get { throw new NotImplementedException(); } } - - public string this[string columnName] - { - get - { - return (!_errors.ContainsKey(columnName) ? null : - String.Join(Environment.NewLine, _errors[columnName])); - } - } - } -} -- cgit v1.2.3