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 @@
-
-
-
+
diff --git a/Juick/NewPostView.xaml.cs b/Juick/NewPostView.xaml.cs
index 68b7efb..e044fbe 100644
--- a/Juick/NewPostView.xaml.cs
+++ b/Juick/NewPostView.xaml.cs
@@ -26,7 +26,8 @@ namespace Juick
{
public partial class NewPostView : PhoneApplicationPage
{
- private PhotoChooserTask chooser;
+ private readonly BitmapImage _attachedPhoto = new BitmapImage();
+ private PhotoChooserTask _chooser;
public NewPostView()
{
InitializeComponent();
@@ -39,7 +40,6 @@ namespace Juick
if (NavigationContext.QueryString.TryGetValue("mid", out _mid))
{
PageTitle.Text = "reply";
- button1.Content = "reply";
textBox1.Text = "#" + _mid;
}
if (NavigationContext.QueryString.TryGetValue("rid", out _rid))
@@ -48,21 +48,23 @@ namespace Juick
}
}
- private void button1_Click(object sender, RoutedEventArgs e)
+ private void Publish(object sender, EventArgs e)
{
var request = new RestRequest("/post", Method.POST);
request.AddParameter("body", textBox1.Text);
- if (image1.Source != null)
+
+ if (_attachedPhoto.PixelHeight > 0)
{
using (var ms = new MemoryStream())
{
- var wb = new WriteableBitmap(image1, null);
- wb.SaveJpeg(ms, (int) image1.Width, (int) image1.Height, 0, 100);
+ var wb = new WriteableBitmap(_attachedPhoto);
+ wb.SaveJpeg(ms, 1024, 768, 0, 100);
request.AddFile("attach", ms.ToArray(), "file.jpg");
}
+
+
}
-
App.Client.ExecuteAsync(request, response =>
{
if (response.StatusCode != HttpStatusCode.OK)
@@ -76,20 +78,18 @@ namespace Juick
}
- private void button2_Click(object sender, RoutedEventArgs e)
+ private void AttachFile(object sender, EventArgs e)
{
- chooser = new PhotoChooserTask {ShowCamera = true};
- chooser.Completed += (o, result) =>
+ _chooser = new PhotoChooserTask {ShowCamera = true};
+ _chooser.Completed += (o, result) =>
{
if (result.TaskResult == TaskResult.OK)
{
-
- BinaryReader reader = new BinaryReader(result.ChosenPhoto);
+ _attachedPhoto.SetSource(result.ChosenPhoto);
image1.Source = new BitmapImage(new Uri(result.OriginalFileName));
-
}
};
- chooser.Show();
+ _chooser.Show();
}
}
}
\ No newline at end of file
diff --git a/Juick/ViewModels/MessageListViewModelBase.cs b/Juick/ViewModels/MessageListViewModelBase.cs
index 6bbfd55..2cf5157 100644
--- a/Juick/ViewModels/MessageListViewModelBase.cs
+++ b/Juick/ViewModels/MessageListViewModelBase.cs
@@ -41,9 +41,9 @@ namespace Juick.ViewModels
{
if (string.IsNullOrEmpty(RestUri))
{
- RestUri = "/home?1=1" + "&rnd=" + Environment.TickCount;
+ RestUri = "/home?1=1";
}
- var request = new RestRequest(RestUri);
+ var request = new RestRequest(RestUri +"&rnd=" + Environment.TickCount);
App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password);
App.Client.ExecuteAsync>(request, response =>
{
diff --git a/Juick/ViewModels/ThreadViewModel.cs b/Juick/ViewModels/ThreadViewModel.cs
index e1f8152..4a80f31 100644
--- a/Juick/ViewModels/ThreadViewModel.cs
+++ b/Juick/ViewModels/ThreadViewModel.cs
@@ -11,7 +11,7 @@ namespace Juick.ViewModels
set
{
_mid = value;
- RestUri = string.Format("/thread?mid={0}", _mid) + "&rnd=" + Environment.TickCount;
+ RestUri = string.Format("/thread?mid={0}", _mid);
}
}
}
--
cgit v1.2.3