From ea1bc13e7a6bbef3d16fb630ed7cd348d8a9e67c Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Tue, 13 Mar 2012 02:47:51 +0400 Subject: add push notifications stub fix refreshing fix images fix orientation --- .gitignore | 3 +- Juick/App.xaml.cs | 2 +- Juick/Images/appbar.attach.png | Bin 0 -> 780 bytes Juick/Images/appbar.send.png | Bin 0 -> 694 bytes Juick/Juick.csproj | 2 + Juick/MainPage.xaml.cs | 91 +++++++++++++++++++++++++++ Juick/NewPostView.xaml | 18 +++--- Juick/NewPostView.xaml.cs | 28 ++++----- Juick/ViewModels/MessageListViewModelBase.cs | 4 +- Juick/ViewModels/ThreadViewModel.cs | 2 +- 10 files changed, 121 insertions(+), 29 deletions(-) create mode 100644 Juick/Images/appbar.attach.png create mode 100644 Juick/Images/appbar.send.png diff --git a/.gitignore b/.gitignore index 48e3cb9..851c1c1 100644 --- a/.gitignore +++ b/.gitignore @@ -25,4 +25,5 @@ Thumbs.db obj/ [Rr]elease*/ _ReSharper*/ -[Tt]est[Rr]esult* \ No newline at end of file +[Tt]est[Rr]esult* +*SubmissionInfo/ \ No newline at end of file diff --git a/Juick/App.xaml.cs b/Juick/App.xaml.cs index 4057483..1102a91 100644 --- a/Juick/App.xaml.cs +++ b/Juick/App.xaml.cs @@ -33,7 +33,7 @@ namespace Juick get { return _last ?? - (_last = new MessageListViewModelBase {RestUri = "/messages?1=1&rnd=" + Environment.TickCount}); + (_last = new MessageListViewModelBase {RestUri = "/messages?1=1"}); } } diff --git a/Juick/Images/appbar.attach.png b/Juick/Images/appbar.attach.png new file mode 100644 index 0000000..fe9cb53 Binary files /dev/null and b/Juick/Images/appbar.attach.png differ diff --git a/Juick/Images/appbar.send.png b/Juick/Images/appbar.send.png new file mode 100644 index 0000000..456c91f Binary files /dev/null and b/Juick/Images/appbar.send.png differ diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj index 08ee273..fb30ee5 100644 --- a/Juick/Juick.csproj +++ b/Juick/Juick.csproj @@ -147,6 +147,7 @@ + @@ -167,6 +168,7 @@ + diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs index a7ba541..a279a83 100644 --- a/Juick/MainPage.xaml.cs +++ b/Juick/MainPage.xaml.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; +using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; @@ -11,6 +12,7 @@ using System.Windows.Media.Animation; using System.Windows.Shapes; using Juick.Classes; using Microsoft.Phone.Controls; +using Microsoft.Phone.Notification; namespace Juick { @@ -19,8 +21,51 @@ namespace Juick // Constructor public MainPage() { + // Holds the push channel that is created or found. + HttpNotificationChannel pushChannel; + + // The name of our push channel. + string channelName = "JuickChannel"; + InitializeComponent(); + /* // Try to find the push channel. + pushChannel = HttpNotificationChannel.Find(channelName); + + // If the channel was not found, then create a new connection to the push service. + if (pushChannel == null) + { + pushChannel = new HttpNotificationChannel(channelName); + + // Register for all the events before attempting to open the channel. + pushChannel.ChannelUriUpdated += new EventHandler(PushChannel_ChannelUriUpdated); + pushChannel.ErrorOccurred += new EventHandler(PushChannel_ErrorOccurred); + + // Register for this notification only if you need to receive the notifications while your application is running. + pushChannel.ShellToastNotificationReceived += new EventHandler(PushChannel_ShellToastNotificationReceived); + + pushChannel.Open(); + + // Bind this new channel for toast events. + pushChannel.BindToShellToast(); + + } + else + { + // The channel was already open, so just register for all the events. + pushChannel.ChannelUriUpdated += new EventHandler(PushChannel_ChannelUriUpdated); + pushChannel.ErrorOccurred += new EventHandler(PushChannel_ErrorOccurred); + + // Register for this notification only if you need to receive the notifications while your application is running. + pushChannel.ShellToastNotificationReceived += new EventHandler(PushChannel_ShellToastNotificationReceived); + + // Display the URI for testing purposes. Normally, the URI would be passed back to your web service at this point. + System.Diagnostics.Debug.WriteLine(pushChannel.ChannelUri.ToString()); + MessageBox.Show(String.Format("Channel Uri is {0}", + pushChannel.ChannelUri.ToString())); + + }*/ + // Set the data context of the listbox control to the sample data Home.DataContext = App.MyFeedView; Last.DataContext = App.LastView; @@ -42,6 +87,52 @@ namespace Juick } } + void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e) + { + + Dispatcher.BeginInvoke(() => + { + // Display the new URI for testing purposes. Normally, the URI would be passed back to your web service at this point. + System.Diagnostics.Debug.WriteLine(e.ChannelUri.ToString()); + MessageBox.Show(String.Format("Channel Uri is {0}", + e.ChannelUri.ToString())); + + }); + } + void PushChannel_ShellToastNotificationReceived(object sender, NotificationEventArgs e) + { + StringBuilder message = new StringBuilder(); + string relativeUri = string.Empty; + + message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString()); + + // Parse out the information that was part of the message. + foreach (string key in e.Collection.Keys) + { + message.AppendFormat("{0}: {1}\n", key, e.Collection[key]); + + if (string.Compare( + key, + "wp:Param", + System.Globalization.CultureInfo.InvariantCulture, + System.Globalization.CompareOptions.IgnoreCase) == 0) + { + relativeUri = e.Collection[key]; + } + } + + // Display a dialog of all the fields in the toast. + Dispatcher.BeginInvoke(() => MessageBox.Show(message.ToString())); + + } + void PushChannel_ErrorOccurred(object sender, NotificationChannelErrorEventArgs e) + { + // Error handling logic for your particular application would be here. + Dispatcher.BeginInvoke(() => + MessageBox.Show(String.Format("A push notification {0} error occurred. {1} ({2}) {3}", + e.ErrorType, e.Message, e.ErrorCode, e.ErrorAdditionalData)) + ); + } private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { diff --git a/Juick/NewPostView.xaml b/Juick/NewPostView.xaml index caa2b4f..9ad33f2 100644 --- a/Juick/NewPostView.xaml +++ b/Juick/NewPostView.xaml @@ -9,8 +9,8 @@ FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" - SupportedOrientations="Portrait" Orientation="Portrait" - mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" + SupportedOrientations="PortraitOrLandscape" Orientation="Portrait" + mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480" shell:SystemTray.IsVisible="True"> @@ -30,22 +30,20 @@ -