summaryrefslogtreecommitdiff
path: root/Juick/NewPostView.xaml.cs
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2012-02-11 22:22:50 +0400
committerGravatar Vitaly Takmazov2012-02-11 22:22:50 +0400
commit49eb44f852ab21e72c17bbc436ffa79525a1aba3 (patch)
tree249cd1d69dc8078104dc2bc35cfcbbce98cd85f4 /Juick/NewPostView.xaml.cs
v 0.999 :)
Diffstat (limited to 'Juick/NewPostView.xaml.cs')
-rw-r--r--Juick/NewPostView.xaml.cs95
1 files changed, 95 insertions, 0 deletions
diff --git a/Juick/NewPostView.xaml.cs b/Juick/NewPostView.xaml.cs
new file mode 100644
index 0000000..68b7efb
--- /dev/null
+++ b/Juick/NewPostView.xaml.cs
@@ -0,0 +1,95 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Browser;
+using System.Reflection;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Resources;
+using System.Windows.Shapes;
+using Juick.Classes;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Tasks;
+using Microsoft.Xna.Framework.Media;
+using RestSharp;
+
+namespace Juick
+{
+ public partial class NewPostView : PhoneApplicationPage
+ {
+ private PhotoChooserTask chooser;
+ public NewPostView()
+ {
+ InitializeComponent();
+ }
+
+ // 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))
+ {
+ PageTitle.Text = "reply";
+ button1.Content = "reply";
+ textBox1.Text = "#" + _mid;
+ }
+ if (NavigationContext.QueryString.TryGetValue("rid", out _rid))
+ {
+ textBox1.Text += "/" + _rid;
+ }
+ }
+
+ private void button1_Click(object sender, RoutedEventArgs e)
+ {
+
+ var request = new RestRequest("/post", Method.POST);
+ request.AddParameter("body", textBox1.Text);
+ if (image1.Source != null)
+ {
+ using (var ms = new MemoryStream())
+ {
+ var wb = new WriteableBitmap(image1, null);
+ wb.SaveJpeg(ms, (int) image1.Width, (int) image1.Height, 0, 100);
+ request.AddFile("attach", ms.ToArray(), "file.jpg");
+ }
+ }
+
+ App.Client.ExecuteAsync(request, response =>
+ {
+ if (response.StatusCode != HttpStatusCode.OK)
+ {
+ MessageBox.Show(response.StatusCode.ToString());
+ }
+ });
+
+ NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
+ Dispatcher.BeginInvoke(() => NavigationService.RemoveBackEntry());
+ }
+
+
+ private void button2_Click(object sender, RoutedEventArgs e)
+ {
+ chooser = new PhotoChooserTask {ShowCamera = true};
+ chooser.Completed += (o, result) =>
+ {
+ if (result.TaskResult == TaskResult.OK)
+ {
+
+ BinaryReader reader = new BinaryReader(result.ChosenPhoto);
+ image1.Source = new BitmapImage(new Uri(result.OriginalFileName));
+
+ }
+ };
+ chooser.Show();
+ }
+ }
+} \ No newline at end of file