From ee46fb9228fd6e70893270703d814a400bb8ca22 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 26 Apr 2013 22:04:18 +0400
Subject: Fixed crash when network is unavailable, added warning message
---
Juick/Classes/BooleanToVisibiltyConverter.cs | 24 +++++++++++++
Juick/Juick.csproj | 1 +
Juick/MainPage.xaml | 10 ++++--
Juick/ViewModels/AppViewModel.cs | 52 ++++++++++++++++++++--------
Juick/ViewModels/PageViewModel.cs | 2 ++
5 files changed, 71 insertions(+), 18 deletions(-)
create mode 100644 Juick/Classes/BooleanToVisibiltyConverter.cs
diff --git a/Juick/Classes/BooleanToVisibiltyConverter.cs b/Juick/Classes/BooleanToVisibiltyConverter.cs
new file mode 100644
index 0000000..679cc3f
--- /dev/null
+++ b/Juick/Classes/BooleanToVisibiltyConverter.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+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();
+ }
+ }
+}
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index 33fbd5c..26371f0 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -80,6 +80,7 @@
App.xaml
+
diff --git a/Juick/MainPage.xaml b/Juick/MainPage.xaml
index 45e1ff9..7c38b7b 100644
--- a/Juick/MainPage.xaml
+++ b/Juick/MainPage.xaml
@@ -7,22 +7,26 @@
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">
+
+
+
+
-
-
+
+
diff --git a/Juick/ViewModels/AppViewModel.cs b/Juick/ViewModels/AppViewModel.cs
index 7d5006c..07ba7cf 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,29 +15,37 @@ namespace Juick.ViewModels
{
public class AppViewModel : ViewModelBase
{
- readonly HttpNotificationChannel pushChannel;
+ static readonly string IsNetworkAvailablePropertyName = ExpressionHelper.GetPropertyName(x => x.NetworkUnavailable);
+ readonly HttpNotificationChannel _pushChannel;
// The name of our push channel.
- string channelName = "JuickChannel";
+ private const string channelName = "JuickChannel";
+
+ public void UpdateNetworkStatus()
+ {
+ NetworkUnavailable = !DeviceNetworkInformation.IsNetworkAvailable;
+ }
public AppViewModel()
{
- pushChannel = HttpNotificationChannel.Find(channelName);
+ 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.
- if (pushChannel == null)
+ if (_pushChannel == null)
{
- pushChannel = new HttpNotificationChannel(channelName);
+ _pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
- pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(e.ChannelUri.ToString());
- pushChannel.ErrorOccurred += (sender, e) => DisableNotifications();
+ _pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(e.ChannelUri.ToString());
+ _pushChannel.ErrorOccurred += (sender, e) => DisableNotifications();
// Register for this notification only if you need to receive the notifications while your application is running.
// Register for this notification only if you need to receive the notifications while your application is running.
- pushChannel.ShellToastNotificationReceived += (sender, e) =>
+ _pushChannel.ShellToastNotificationReceived += (sender, e) =>
{
- StringBuilder message = new StringBuilder();
+ var message = new StringBuilder();
string relativeUri = string.Empty;
message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());
@@ -57,20 +67,20 @@ namespace Juick.ViewModels
Debug.WriteLine("Received: " + message.ToString());
};
- pushChannel.Open();
+ _pushChannel.Open();
// Bind this new channel for toast events.
- pushChannel.BindToShellToast();
+ _pushChannel.BindToShellToast();
}
else
{
// The channel was already open, so just register for all the events.
- pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(e.ChannelUri.ToString());
- pushChannel.ErrorOccurred += (sender, e) => DisableNotifications();
+ _pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(e.ChannelUri.ToString());
+ _pushChannel.ErrorOccurred += (sender, e) => DisableNotifications();
// Register for this notification only if you need to receive the notifications while your application is running.
- pushChannel.ShellToastNotificationReceived += (sender, e) =>
+ _pushChannel.ShellToastNotificationReceived += (sender, e) =>
{
StringBuilder message = new StringBuilder();
string relativeUri = string.Empty;
@@ -94,7 +104,7 @@ namespace Juick.ViewModels
Debug.WriteLine("Received: " + message.ToString());
};
- EnableNotifications(pushChannel.ChannelUri.ToString());
+ EnableNotifications(_pushChannel.ChannelUri.ToString());
}
}
private ObservableCollection _pages;
@@ -120,6 +130,18 @@ namespace Juick.ViewModels
}
}
+ private bool _isNetworkUnavailable;
+ public bool NetworkUnavailable
+ {
+ get { return _isNetworkUnavailable; }
+ set
+ {
+ _isNetworkUnavailable = value;
+ NotifyPropertyChanged(IsNetworkAvailablePropertyName);
+ }
+ }
+
+
private AccountManager _acc;
public AccountManager Account
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;
--
cgit v1.2.3
From 7b1c7831a51fde41f42732a6da6431197a8f4e4b Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 26 Apr 2013 22:05:20 +0400
Subject: 1.1.0.1
---
Juick/Properties/AssemblyInfo.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Juick/Properties/AssemblyInfo.cs b/Juick/Properties/AssemblyInfo.cs
index 9a99ba0..add9f2e 100644
--- a/Juick/Properties/AssemblyInfo.cs
+++ b/Juick/Properties/AssemblyInfo.cs
@@ -32,6 +32,6 @@ using System.Resources;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.9.10")]
-[assembly: AssemblyFileVersion("1.0.9.10")]
+[assembly: AssemblyVersion("1.1.0.1")]
+[assembly: AssemblyFileVersion("1.1.0.1")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
--
cgit v1.2.3
From acb14d7db321ba26c085872a96c48e7434332154 Mon Sep 17 00:00:00 2001
From: Konstantin
Date: Thu, 25 Apr 2013 23:35:23 +0400
Subject: merge again
---
Juick/ThreadView.xaml | 2 +
Juick/ThreadView.xaml.cs | 199 +++++++++++++++++++++++++----------------------
2 files changed, 109 insertions(+), 92 deletions(-)
diff --git a/Juick/ThreadView.xaml b/Juick/ThreadView.xaml
index 14a6f75..2778e2f 100644
--- a/Juick/ThreadView.xaml
+++ b/Juick/ThreadView.xaml
@@ -83,6 +83,8 @@
+
+
diff --git a/Juick/ThreadView.xaml.cs b/Juick/ThreadView.xaml.cs
index 4e1da97..354a3cd 100644
--- a/Juick/ThreadView.xaml.cs
+++ b/Juick/ThreadView.xaml.cs
@@ -1,93 +1,108 @@
-using System;
-using System.Linq;
-using System.Windows.Controls;
-using System.Windows.Navigation;
-using Juick.ViewModels;
-using Microsoft.Phone.Controls;
-using Microsoft.Phone.Shell;
-using System.Windows.Data;
-using System.Windows;
-using RestSharp;
-using System.Net;
-
-namespace Juick
-{
- public partial class ThreadView : PhoneApplicationPage
- {
- public ThreadView()
- {
- InitializeComponent();
- Model = new ThreadViewModel(App.AppContext);
- DataContext = Model;
- Loaded += (o, args) =>
- {
- var progressIndicator = SystemTray.ProgressIndicator;
-
- if (progressIndicator != null)
- {
- return;
- }
- progressIndicator = new ProgressIndicator();
-
- SystemTray.SetProgressIndicator(this, progressIndicator);
-
- Binding binding = new Binding("IsDataLoading") { Source = App.AppContext };
-
- BindingOperations.SetBinding(
- progressIndicator, ProgressIndicator.IsVisibleProperty, binding);
-
- binding = new Binding("IsDataLoading") { Source = App.AppContext };
-
- BindingOperations.SetBinding(
- progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding);
- };
- }
-
- public ThreadViewModel Model;
-
- // When page is navigated to set data context to selected item in list
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- if (Model.Items.Count > 0)
- return;
- string _mid = "";
- if (NavigationContext.QueryString.TryGetValue("mid", out _mid))
- {
- Model.Mid = int.Parse(_mid);
- }
- Model.RefreshData();
- }
-
- private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- // If selected index is -1 (no selection) do nothing
- if (((ListBox)sender).SelectedIndex == -1)
- return;
-
- // Navigate to the new page
- var item = Model.Items[((ListBox)sender).SelectedIndex];
- var destUri = string.Format("/NewPostView.xaml?mid={0}", item.MID);
- if (item.RID > 0)
- destUri += string.Format("&rid={0}", item.RID);
- NavigationService.Navigate(new Uri(destUri, UriKind.Relative));
-
- // Reset selected index to -1 (no selection)
- ((ListBox)sender).SelectedIndex = -1;
- }
-
- void RecommendBarMenuItem_Click(object sender, EventArgs e)
- {
- var request = new RestRequest("/post", Method.POST);
- request.AddParameter("body", "! #" + Model.Mid);
- App.AppContext.Client.ExecuteAsync(request, response =>
- {
- App.AppContext.IsDataLoading = false;
- if (response.StatusCode != HttpStatusCode.OK && !string.IsNullOrEmpty(response.Content))
- {
- MessageBox.Show(string.Concat(response.StatusCode, ": ", response.Content));
- }
- });
- App.AppContext.IsDataLoading = true;
- }
- }
+using System;
+using System.Linq;
+using System.Windows.Controls;
+using System.Windows.Navigation;
+using Juick.ViewModels;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+using System.Windows.Data;
+using System.Windows;
+using RestSharp;
+using System.Net;
+
+namespace Juick
+{
+ public partial class ThreadView : PhoneApplicationPage
+ {
+ public ThreadView()
+ {
+ InitializeComponent();
+ Model = new ThreadViewModel(App.AppContext);
+ DataContext = Model;
+ Loaded += (o, args) =>
+ {
+ var progressIndicator = SystemTray.ProgressIndicator;
+
+ if (progressIndicator != null)
+ {
+ return;
+ }
+ progressIndicator = new ProgressIndicator();
+
+ SystemTray.SetProgressIndicator(this, progressIndicator);
+
+ Binding binding = new Binding("IsDataLoading") { Source = App.AppContext };
+
+ BindingOperations.SetBinding(
+ progressIndicator, ProgressIndicator.IsVisibleProperty, binding);
+
+ binding = new Binding("IsDataLoading") { Source = App.AppContext };
+
+ BindingOperations.SetBinding(
+ progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding);
+ };
+ }
+
+ public ThreadViewModel Model;
+
+ // When page is navigated to set data context to selected item in list
+ protected override void OnNavigatedTo(NavigationEventArgs e)
+ {
+ if (Model.Items.Count > 0)
+ return;
+ string _mid = "";
+ if (NavigationContext.QueryString.TryGetValue("mid", out _mid))
+ {
+ Model.Mid = int.Parse(_mid);
+ }
+ Model.RefreshData();
+ }
+
+ private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
+ {
+ // If selected index is -1 (no selection) do nothing
+ if (((ListBox)sender).SelectedIndex == -1)
+ return;
+
+ // Navigate to the new page
+ var item = Model.Items[((ListBox)sender).SelectedIndex];
+ var destUri = string.Format("/NewPostView.xaml?mid={0}", item.MID);
+ if (item.RID > 0)
+ destUri += string.Format("&rid={0}", item.RID);
+ NavigationService.Navigate(new Uri(destUri, UriKind.Relative));
+
+ // Reset selected index to -1 (no selection)
+ ((ListBox)sender).SelectedIndex = -1;
+ }
+
+ void RecommendBarMenuItem_Click(object sender, EventArgs e)
+ {
+ ExecuteJuickAction("!");
+ }
+
+ void SubscribeBarMenuItem_Click(object sender, EventArgs e)
+ {
+ ExecuteJuickAction("S");
+ }
+
+ void UnsubscribeBarMenuItem_Click(object sender, EventArgs e)
+ {
+ ExecuteJuickAction("U");
+ }
+
+ void ExecuteJuickAction(string action)
+ {
+ var request = new RestRequest("/post", Method.POST);
+ request.AddParameter("body", string.Concat(action, " #", Model.Mid));
+ App.AppContext.Client.ExecuteAsync(request, response =>
+ {
+ App.AppContext.IsDataLoading = false;
+ if(response.StatusCode != HttpStatusCode.OK || !string.IsNullOrEmpty(response.Content))
+ {
+ MessageBox.Show(string.Concat(response.StatusCode, ": ", response.Content));
+ }
+ });
+ App.AppContext.IsDataLoading = true;
+ }
+ }
}
\ No newline at end of file
--
cgit v1.2.3
From 648d914c8d5cf6fe2b3f8271839ec30143172376 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Fri, 26 Apr 2013 22:35:07 +0400
Subject: 1.1.0.2
---
Juick/Properties/AssemblyInfo.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Juick/Properties/AssemblyInfo.cs b/Juick/Properties/AssemblyInfo.cs
index add9f2e..d97b9eb 100644
--- a/Juick/Properties/AssemblyInfo.cs
+++ b/Juick/Properties/AssemblyInfo.cs
@@ -32,6 +32,6 @@ using System.Resources;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.1.0.1")]
-[assembly: AssemblyFileVersion("1.1.0.1")]
+[assembly: AssemblyVersion("1.1.0.2")]
+[assembly: AssemblyFileVersion("1.1.0.2")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
--
cgit v1.2.3