summaryrefslogtreecommitdiff
path: root/Juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2012-03-13 02:47:51 +0400
committerGravatar Vitaly Takmazov2012-03-13 02:47:51 +0400
commitea1bc13e7a6bbef3d16fb630ed7cd348d8a9e67c (patch)
tree04362f97bac727c5d35053be0d1db9c0fcad30f1 /Juick
parentadfdd7c1afd794fab5013fdad95aad8654326d3f (diff)
add push notifications stub
fix refreshing fix images fix orientation
Diffstat (limited to 'Juick')
-rw-r--r--Juick/App.xaml.cs2
-rw-r--r--Juick/Images/appbar.attach.pngbin0 -> 780 bytes
-rw-r--r--Juick/Images/appbar.send.pngbin0 -> 694 bytes
-rw-r--r--Juick/Juick.csproj2
-rw-r--r--Juick/MainPage.xaml.cs91
-rw-r--r--Juick/NewPostView.xaml18
-rw-r--r--Juick/NewPostView.xaml.cs28
-rw-r--r--Juick/ViewModels/MessageListViewModelBase.cs4
-rw-r--r--Juick/ViewModels/ThreadViewModel.cs2
9 files changed, 119 insertions, 28 deletions
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
--- /dev/null
+++ b/Juick/Images/appbar.attach.png
Binary files differ
diff --git a/Juick/Images/appbar.send.png b/Juick/Images/appbar.send.png
new file mode 100644
index 0000000..456c91f
--- /dev/null
+++ b/Juick/Images/appbar.send.png
Binary files 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 @@
<Resource Include="Images\appbar.favs.addto.rest.png" />
<Resource Include="Images\appbar.favs.rest.png" />
<Resource Include="Images\appbar.feature.camera.rest.png" />
+ <Content Include="Images\appbar.attach.png" />
<Content Include="Images\appbar.feature.email.rest.png" />
<Resource Include="Images\appbar.feature.search.rest.png" />
<Resource Include="Images\appbar.feature.settings.rest.png" />
@@ -167,6 +168,7 @@
<Resource Include="Images\appbar.transport.play.rest.png" />
<Resource Include="Images\appbar.transport.rew.rest.png" />
<Resource Include="Images\appbar.upload.rest.png" />
+ <Content Include="Images\appbar.send.png" />
<Content Include="SplashScreenImage.jpg" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\Silverlight for Phone\$(TargetFrameworkVersion)\Microsoft.Silverlight.$(TargetFrameworkProfile).Overrides.targets" />
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<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
+ pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
+
+ // Register for this notification only if you need to receive the notifications while your application is running.
+ pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(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<NotificationChannelUriEventArgs>(PushChannel_ChannelUriUpdated);
+ pushChannel.ErrorOccurred += new EventHandler<NotificationChannelErrorEventArgs>(PushChannel_ErrorOccurred);
+
+ // Register for this notification only if you need to receive the notifications while your application is running.
+ pushChannel.ShellToastNotificationReceived += new EventHandler<NotificationEventArgs>(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">
<!--LayoutRoot is the root grid where all page content is placed-->
@@ -30,22 +30,20 @@
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<TextBlock Height="30" HorizontalAlignment="Left" Margin="12,34,0,0" Name="textBlock1" Text="Write a message" VerticalAlignment="Top" />
<TextBox Height="333" HorizontalAlignment="Left" Margin="0,70,0,0" Name="textBox1" Text="" VerticalAlignment="Top" Width="450" TextWrapping="Wrap" MaxWidth="Infinity" />
- <Button Content="Publish" Height="72" HorizontalAlignment="Left" Margin="290,409,0,0" Name="button1" VerticalAlignment="Top" Width="160" Click="button1_Click" />
- <Button Content="Attach" Height="72" HorizontalAlignment="Left" Margin="0,409,0,0" Name="button2" VerticalAlignment="Top" Width="143" Click="button2_Click" />
<Image Height="150" HorizontalAlignment="Left" Margin="12,504,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="425" />
</Grid>
</Grid>
<!--Sample code showing usage of ApplicationBar-->
- <!--<phone:PhoneApplicationPage.ApplicationBar>
+ <phone:PhoneApplicationPage.ApplicationBar>
<shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
- <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
- <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2"/>
+ <shell:ApplicationBarIconButton x:Name="PostButton" IconUri="/Images/appbar.send.png" Text="Send" Click="Publish"/>
+ <shell:ApplicationBarIconButton IconUri="/Images/appbar.attach.png" Text="Attach" Click="AttachFile"/>
<shell:ApplicationBar.MenuItems>
- <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
- <shell:ApplicationBarMenuItem Text="MenuItem 2"/>
+ <shell:ApplicationBarMenuItem x:Name="PostMenuItem" Text="Send" Click="Publish"/>
+ <shell:ApplicationBarMenuItem Text="Attach" Click="AttachFile"/>
</shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>
- </phone:PhoneApplicationPage.ApplicationBar>-->
+ </phone:PhoneApplicationPage.ApplicationBar>
</phone:PhoneApplicationPage>
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<List<Message>>(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);
}
}
}