summaryrefslogtreecommitdiff
path: root/Juick/NewPostView.xaml.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/NewPostView.xaml.cs')
-rw-r--r--Juick/NewPostView.xaml.cs42
1 files changed, 30 insertions, 12 deletions
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<string, string> 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)