From 1ebf0adc26fd3377b50aacaed798f9866a7ea2eb Mon Sep 17 00:00:00 2001 From: vitalyster Date: Mon, 15 Oct 2012 00:58:48 +0400 Subject: Photos_Extra_Share, attach image in original size, reformat code --- Juick/Classes/AccountManager.cs | 15 +++--- Juick/Juick.csproj | 1 + Juick/LoginView.xaml.cs | 12 ++++- Juick/MainPage.xaml.cs | 93 ++++++++++++++++++++++---------------- Juick/NewPostView.xaml | 10 ++-- Juick/NewPostView.xaml.cs | 42 ++++++++++++----- Juick/Properties/WMAppManifest.xml | 5 +- 7 files changed, 114 insertions(+), 64 deletions(-) diff --git a/Juick/Classes/AccountManager.cs b/Juick/Classes/AccountManager.cs index f7fcc75..82fc446 100644 --- a/Juick/Classes/AccountManager.cs +++ b/Juick/Classes/AccountManager.cs @@ -27,7 +27,7 @@ namespace Juick.Classes { return new NetworkCredential { - UserName = IsolatedStorageSettings.ApplicationSettings.Contains("user") ? + UserName = IsolatedStorageSettings.ApplicationSettings.Contains("user") ? IsolatedStorageSettings.ApplicationSettings["user"] as string : null, Password = IsolatedStorageSettings.ApplicationSettings.Contains("password") ? IsolatedStorageSettings.ApplicationSettings["password"] as string : null, @@ -40,26 +40,27 @@ namespace Juick.Classes { IsolatedStorageSettings.ApplicationSettings["user"] = value.UserName; IsolatedStorageSettings.ApplicationSettings["password"] = value.Password; - } else + } + else { IsolatedStorageSettings.ApplicationSettings["user"] = null; IsolatedStorageSettings.ApplicationSettings["password"] = null; - } + } } } - public void SignIn(Page page, string login, string pass) + public void SignIn(Page page, string login, string pass, Uri nextUri) { Credentials = new NetworkCredential(login, pass); - page.NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative)); - page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); + page.NavigationService.Navigate(nextUri); + page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); } public void SignOut(Page page) { Credentials = null; page.NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative)); - page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); + page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); } } } diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj index 5265fce..01b0392 100644 --- a/Juick/Juick.csproj +++ b/Juick/Juick.csproj @@ -51,6 +51,7 @@ + ..\packages\RestSharp.104.1\lib\sl4-wp71\RestSharp.WindowsPhone.dll diff --git a/Juick/LoginView.xaml.cs b/Juick/LoginView.xaml.cs index 43aa8f7..5e86959 100644 --- a/Juick/LoginView.xaml.cs +++ b/Juick/LoginView.xaml.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Windows; using Microsoft.Phone.Controls; +using System; namespace Juick { @@ -12,9 +13,18 @@ namespace Juick DataContext = App.Account.Credentials; } + private Uri nextUri; + + protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) + { + nextUri = NavigationContext.QueryString.ContainsKey("FileId") ? + new Uri(string.Format("/NewPostView.xaml?FileId={0}", NavigationContext.QueryString["FileId"]), UriKind.Relative) + : new Uri("/MainPage.xaml", UriKind.Relative); + } + private void button1_Click(object sender, RoutedEventArgs e) { - App.Account.SignIn(this, textBox1.Text, textBox2.Password); + App.Account.SignIn(this, textBox1.Text, textBox2.Password, nextUri); } private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e) { diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs index 6ea6e04..783265e 100644 --- a/Juick/MainPage.xaml.cs +++ b/Juick/MainPage.xaml.cs @@ -13,6 +13,8 @@ using System.Windows.Shapes; using Juick.Classes; using Microsoft.Phone.Controls; using Microsoft.Phone.Notification; +using Microsoft.Xna.Framework.Media; +using System.Windows.Media.Imaging; namespace Juick { @@ -29,42 +31,42 @@ namespace Juick InitializeComponent(); - /* // Try to find the push channel. - pushChannel = HttpNotificationChannel.Find(channelName); + /* // 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); + // 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 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); + // 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(); + pushChannel.Open(); - // Bind this new channel for toast events. - pushChannel.BindToShellToast(); + // 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); + } + 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); + // 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())); + // 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; @@ -72,22 +74,37 @@ namespace Juick Loaded += MainPage_Loaded; } + protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) + { + var loginUriPart = "/LoginView.xaml"; + var newPostUriPart = "/NewPostView.xaml"; + var navigateUri = string.Empty; + var FileId = string.Empty; + // Get a dictionary of query string keys and values. + IDictionary queryStrings = NavigationContext.QueryString; + + // Ensure that there is at least one key in the query string, and check + // whether the "FileId" key is present. + + navigateUri = string.IsNullOrEmpty(App.Account.Credentials.UserName) ? loginUriPart : newPostUriPart; + if (queryStrings.ContainsKey("FileId")) + { + FileId = queryStrings["FileId"]; + navigateUri = string.Format("{0}?FileId={1}", navigateUri, FileId); + } + if (!string.IsNullOrEmpty(FileId) || navigateUri.StartsWith(loginUriPart)) + { + NavigationService.Navigate(new Uri(navigateUri, UriKind.Relative)); + } + } + // Load data for the _viewModelBase Items private void MainPage_Loaded(object sender, RoutedEventArgs e) { if (!App.MyFeedView.IsDataLoaded) { - if (string.IsNullOrEmpty(App.Account.Credentials.UserName)) - { - NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative)); - } - - else - { - App.MyFeedView.LoadData(); - App.LastView.LoadData(); - } - + App.MyFeedView.LoadData(); + App.LastView.LoadData(); } } void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e) diff --git a/Juick/NewPostView.xaml b/Juick/NewPostView.xaml index 75bfd19..1065488 100644 --- a/Juick/NewPostView.xaml +++ b/Juick/NewPostView.xaml @@ -27,11 +27,11 @@ - - - - - + + + + + diff --git a/Juick/NewPostView.xaml.cs b/Juick/NewPostView.xaml.cs index d50b45a..e883597 100644 --- a/Juick/NewPostView.xaml.cs +++ b/Juick/NewPostView.xaml.cs @@ -20,6 +20,7 @@ using Juick.Classes; using Microsoft.Phone.Controls; using Microsoft.Phone.Tasks; using RestSharp; +using Microsoft.Xna.Framework.Media; namespace Juick { @@ -35,34 +36,51 @@ namespace Juick // When page is navigated to set data context to selected item in list protected override void OnNavigatedTo(NavigationEventArgs e) { - string _rid, _mid; - if (NavigationContext.QueryString.TryGetValue("mid", out _mid)) + // Get a dictionary of query string keys and values. + IDictionary queryStrings = this.NavigationContext.QueryString; + + // Ensure that there is at least one key in the query string, and check + // whether the "FileId" key is present. + if (queryStrings.ContainsKey("FileId")) { - PageTitle.Text = "reply"; - textBox1.Text = "#" + _mid; + App.Client.Authenticator = new HttpBasicAuthenticator(App.Account.Credentials.UserName, App.Account.Credentials.Password); + // Retrieve the picture from the media library using the FileID + // passed to the application. + MediaLibrary library = new MediaLibrary(); + Picture picture = library.GetPictureFromToken(queryStrings["FileId"]); + _attachedPhoto.SetSource(picture.GetImage()); + image1.Source = new WriteableBitmap(_attachedPhoto); } - if (NavigationContext.QueryString.TryGetValue("rid", out _rid)) + else { - textBox1.Text += "/" + _rid; + string _rid, _mid; + if (NavigationContext.QueryString.TryGetValue("mid", out _mid)) + { + PageTitle.Text = "reply"; + textBox1.Text = "#" + _mid; + } + if (NavigationContext.QueryString.TryGetValue("rid", out _rid)) + { + textBox1.Text += "/" + _rid; + } } } private void Publish(object sender, EventArgs e) { - + var request = new RestRequest("/post", Method.POST); request.AddParameter("body", textBox1.Text); - if (_attachedPhoto.PixelHeight > 0) { using (var ms = new MemoryStream()) { var wb = new WriteableBitmap(_attachedPhoto); - wb.SaveJpeg(ms, 1024, 768, 0, 100); + wb.SaveJpeg(ms, _attachedPhoto.PixelWidth, _attachedPhoto.PixelHeight, 0, 100); request.AddFile("attach", ms.ToArray(), "file.jpg"); } - - + + } App.Client.ExecuteAsync(request, response => { @@ -79,7 +97,7 @@ namespace Juick private void AttachFile(object sender, EventArgs e) { - _chooser = new PhotoChooserTask {ShowCamera = true}; + _chooser = new PhotoChooserTask { ShowCamera = true }; _chooser.Completed += (o, result) => { if (result.TaskResult == TaskResult.OK) diff --git a/Juick/Properties/WMAppManifest.xml b/Juick/Properties/WMAppManifest.xml index 33fd6ef..8f7b6da 100644 --- a/Juick/Properties/WMAppManifest.xml +++ b/Juick/Properties/WMAppManifest.xml @@ -19,7 +19,7 @@ - + @@ -30,5 +30,8 @@ + + + \ No newline at end of file -- cgit v1.2.3