From 83ea4b07788df8d5da9286372ca9bdf76b5513fd Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 23 Apr 2013 12:29:01 +0400
Subject: Move PostItem DataTemplate to Resources, add sample data to
ThreadView, enable bitmap CacheMode, remove incomplete Validation
---
Juick/App.xaml | 19 +++++----
Juick/Controls/MessageList.xaml | 45 ++-------------------
Juick/DataTemplates/PostItemDataTemplate.xaml | 44 ++++++++++++++++++++
Juick/Juick.csproj | 13 +++++-
Juick/LoginView.xaml | 3 +-
Juick/MainPage.xaml | 2 +-
Juick/NewPostView.xaml | 2 +-
Juick/SampleData/ThreadViewModelSampleData.xaml | 16 ++++++++
Juick/ThreadView.xaml | 53 ++++---------------------
Juick/ViewModels/LoginViewModel.cs | 5 +--
Juick/ViewModels/NewPostViewModel.cs | 28 +++++++++++++
11 files changed, 128 insertions(+), 102 deletions(-)
create mode 100644 Juick/DataTemplates/PostItemDataTemplate.xaml
create mode 100644 Juick/SampleData/ThreadViewModelSampleData.xaml
create mode 100644 Juick/ViewModels/NewPostViewModel.cs
diff --git a/Juick/App.xaml b/Juick/App.xaml
index 0c60cc0..1b67f8c 100644
--- a/Juick/App.xaml
+++ b/Juick/App.xaml
@@ -1,20 +1,25 @@
-
+ xmlns:sys="clr-namespace:System;assembly=mscorlib"
+ x:Class="Juick.App"
+ >
-
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/Juick/Controls/MessageList.xaml b/Juick/Controls/MessageList.xaml
index afa6c69..ac6db00 100644
--- a/Juick/Controls/MessageList.xaml
+++ b/Juick/Controls/MessageList.xaml
@@ -12,10 +12,10 @@
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="480" d:DesignWidth="480">
-
+
+ ItemsSource="{Binding Items}" IsFlatList="true" ItemTemplate="{StaticResource PostItemDataTemplate}">
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Juick/DataTemplates/PostItemDataTemplate.xaml b/Juick/DataTemplates/PostItemDataTemplate.xaml
new file mode 100644
index 0000000..285a5dc
--- /dev/null
+++ b/Juick/DataTemplates/PostItemDataTemplate.xaml
@@ -0,0 +1,44 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index 33fbd5c..9d7c770 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -27,6 +27,8 @@
true
..\
true
+ true
+ 4.0.30816.0
true
@@ -107,7 +109,6 @@
-
@@ -119,6 +120,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -190,6 +195,12 @@
+
+
+ MSBuild:MarkupCompilePass1
+
+
+
diff --git a/Juick/NewPostView.xaml b/Juick/NewPostView.xaml
index f3a911b..1ed01b5 100644
--- a/Juick/NewPostView.xaml
+++ b/Juick/NewPostView.xaml
@@ -11,7 +11,7 @@
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
- shell:SystemTray.IsVisible="True">
+ shell:SystemTray.IsVisible="True" CacheMode="BitmapCache">
diff --git a/Juick/SampleData/ThreadViewModelSampleData.xaml b/Juick/SampleData/ThreadViewModelSampleData.xaml
new file mode 100644
index 0000000..784bee3
--- /dev/null
+++ b/Juick/SampleData/ThreadViewModelSampleData.xaml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Juick/ThreadView.xaml b/Juick/ThreadView.xaml
index 14a6f75..d52a343 100644
--- a/Juick/ThreadView.xaml
+++ b/Juick/ThreadView.xaml
@@ -11,67 +11,30 @@
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="PortraitOrLandscape" Orientation="Portrait"
- mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480"
- phoneshell:SystemTray.IsVisible="True">
+ mc:Ignorable="d" d:DesignHeight="696" d:DesignWidth="480"
+ phoneshell:SystemTray.IsVisible="True" CacheMode="BitmapCache">
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/Juick/ViewModels/LoginViewModel.cs b/Juick/ViewModels/LoginViewModel.cs
index 95528fe..2bc5bda 100644
--- a/Juick/ViewModels/LoginViewModel.cs
+++ b/Juick/ViewModels/LoginViewModel.cs
@@ -2,12 +2,11 @@
using System.Net;
using System.Windows;
using Juick.Classes;
-using Juick.ViewModels.Validation;
using RestSharp;
namespace Juick.ViewModels
{
- public class LoginViewModel : DataViewModelBase
+ public class LoginViewModel : ViewModelBase
{
private string _username;
private string _password;
@@ -64,7 +63,7 @@ namespace Juick.ViewModels
}
else
{
- AddError("Username", "Invalid username or password", false);
+ //AddError("Username", "Invalid username or password", false);
}
});
}
diff --git a/Juick/ViewModels/NewPostViewModel.cs b/Juick/ViewModels/NewPostViewModel.cs
new file mode 100644
index 0000000..3c28cc7
--- /dev/null
+++ b/Juick/ViewModels/NewPostViewModel.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+
+namespace Juick.ViewModels
+{
+ public class NewPostViewModel : ViewModelBase
+ {
+ public PostItem ReplyTo { get; set; }
+
+ public PostItem Draft { get; set; }
+
+ public BitmapImage Attachment { get; set; }
+
+ public NewPostViewModel(PostItem replyTo)
+ {
+ ReplyTo = replyTo;
+ }
+ }
+}
--
cgit v1.2.3
From b18cc65cc80d1f21b47f6ad25a673adbaeab6084 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 23 Apr 2013 13:33:55 +0400
Subject: Prettify datetime output
---
Juick/Classes/DateHelper.cs | 67 +++++++++++++++++++++++++++
Juick/DataTemplates/PostItemDataTemplate.xaml | 4 +-
Juick/Juick.csproj | 1 +
Juick/ViewModels/PostItem.cs | 9 +++-
4 files changed, 77 insertions(+), 4 deletions(-)
create mode 100644 Juick/Classes/DateHelper.cs
diff --git a/Juick/Classes/DateHelper.cs b/Juick/Classes/DateHelper.cs
new file mode 100644
index 0000000..072c56a
--- /dev/null
+++ b/Juick/Classes/DateHelper.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Net;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Documents;
+using System.Windows.Ink;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Animation;
+using System.Windows.Shapes;
+using System.Globalization;
+
+namespace Juick.Classes
+{
+ public class DateHelper
+ {
+ public static string PrettyDate(DateTime dateTime)
+ {
+ var timeSpan = DateTime.Now - dateTime;
+
+ // span is less than or equal to 60 seconds, measure in seconds.
+ if (timeSpan <= TimeSpan.FromSeconds(60))
+ {
+ return timeSpan.Seconds > 5
+ ? "about " + timeSpan.Seconds + " seconds ago"
+ : "just now";
+ }
+
+ // span is less than or equal to 60 minutes, measure in minutes.
+ if (timeSpan <= TimeSpan.FromMinutes(60))
+ {
+ return timeSpan.Minutes > 1
+ ? "about " + timeSpan.Minutes + " minutes ago"
+ : "about a minute ago";
+ }
+
+ // span is less than or equal to 24 hours, measure in hours.
+ if (timeSpan <= TimeSpan.FromHours(24))
+ {
+ return timeSpan.Hours > 1
+ ? "about " + timeSpan.Hours + " hours ago"
+ : "about an hour ago";
+ }
+
+ // span is less than or equal to 30 days (1 month), measure in days.
+ if (timeSpan <= TimeSpan.FromDays(30))
+ {
+ return timeSpan.Days > 1
+ ? "about " + timeSpan.Days + " days ago"
+ : "about a day ago";
+ }
+
+ // span is less than or equal to 365 days (1 year), measure in months.
+ if (timeSpan <= TimeSpan.FromDays(365))
+ {
+ return timeSpan.Days > 30
+ ? "about " + timeSpan.Days / 30 + " months ago"
+ : "about a month ago";
+ }
+
+ // span is greater than 365 days (1 year), measure in years.
+ return timeSpan.Days > 365
+ ? "about " + timeSpan.Days / 365 + " years ago"
+ : "about a year ago";
+ }
+ }
+}
diff --git a/Juick/DataTemplates/PostItemDataTemplate.xaml b/Juick/DataTemplates/PostItemDataTemplate.xaml
index 285a5dc..4668a48 100644
--- a/Juick/DataTemplates/PostItemDataTemplate.xaml
+++ b/Juick/DataTemplates/PostItemDataTemplate.xaml
@@ -1,7 +1,7 @@
@@ -36,7 +36,7 @@
Style="{StaticResource PhoneTextAccentStyle}"
FontSize="{StaticResource PhoneFontSizeSmall}"
Margin="5,0,5,5" VerticalAlignment="Top"
- TextWrapping="Wrap" HorizontalAlignment="Left"/>
+ TextWrapping="NoWrap" TextAlignment="Right"/>
diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj
index 9d7c770..c3fe200 100644
--- a/Juick/Juick.csproj
+++ b/Juick/Juick.csproj
@@ -82,6 +82,7 @@
App.xaml
+
diff --git a/Juick/ViewModels/PostItem.cs b/Juick/ViewModels/PostItem.cs
index 97935b3..88f6b86 100644
--- a/Juick/ViewModels/PostItem.cs
+++ b/Juick/ViewModels/PostItem.cs
@@ -1,6 +1,8 @@
using System;
using System.Net;
using JuickApi;
+using Juick.Classes;
+using System.Globalization;
namespace Juick.ViewModels
{
@@ -11,8 +13,11 @@ namespace Juick.ViewModels
MID = message.Mid;
RID = message.Rid;
Username = message.User.UName;
- Status = string.Format("Posted on: {0}, replies: {1}", message.Timestamp, message.Replies);
-
+ // Juick timestamp in utc: 2013-04-22 13:14:30
+ var timestamp = DateTime.ParseExact(message.Timestamp, "yyyy-MM-dd HH:mm:ss", null);
+ Status = string.Format("{0}", DateHelper.PrettyDate(timestamp.ToLocalTime()));
+ if (message.Replies > 0)
+ Status = string.Format("{0}, replies: {1}", Status, message.Replies);
MessageText = HttpUtility.HtmlDecode(message.Body);
if (message.Tags != null)
--
cgit v1.2.3
From f845109f6679e78501c1f3363315a0cf39af29e9 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 23 Apr 2013 16:09:43 +0400
Subject: Fix enable/disable notifications flow
---
Juick/Classes/AccountManager.cs | 40 ++++++++++++++++++------
Juick/MainPage.xaml.cs | 2 +-
Juick/ViewModels/AppViewModel.cs | 63 +++++++++++++++-----------------------
Juick/ViewModels/LoginViewModel.cs | 3 +-
4 files changed, 59 insertions(+), 49 deletions(-)
diff --git a/Juick/Classes/AccountManager.cs b/Juick/Classes/AccountManager.cs
index 1f9ffe5..eb99d92 100644
--- a/Juick/Classes/AccountManager.cs
+++ b/Juick/Classes/AccountManager.cs
@@ -3,6 +3,8 @@ using System.IO.IsolatedStorage;
using System.Net;
using System.Windows;
using System.Windows.Controls;
+using RestSharp;
+using System.Diagnostics;
namespace Juick.Classes
{
@@ -10,14 +12,14 @@ namespace Juick.Classes
{
private string _userName;
private string _password;
-
+
public string UserName
{
get
{
if (_userName == null)
{
- IsolatedStorageSettings.ApplicationSettings.TryGetValue("user", out _userName);
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue("user", out _userName);
}
return _userName;
}
@@ -34,7 +36,7 @@ namespace Juick.Classes
{
if (_password == null)
{
- IsolatedStorageSettings.ApplicationSettings.TryGetValue("password", out _password);
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue("password", out _password);
}
return _password;
}
@@ -47,7 +49,8 @@ namespace Juick.Classes
public bool IsAuthenticated
{
- get {
+ get
+ {
bool authenticated;
IsolatedStorageSettings.ApplicationSettings.TryGetValue("authenticated", out authenticated);
return authenticated;
@@ -55,26 +58,45 @@ namespace Juick.Classes
set { IsolatedStorageSettings.ApplicationSettings["authenticated"] = value; }
}
+
+
public string NotificationUri
{
get
{
- string savedUri;
- IsolatedStorageSettings.ApplicationSettings.TryGetValue("notification_uri", out savedUri);
- return savedUri;
+ string _notificationUri;
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue("notification_uri", out _notificationUri);
+ return _notificationUri;
}
set
{
+ var oldValue = NotificationUri;
+ if (!string.IsNullOrEmpty(oldValue))
+ UnregisterNotificationUrl(oldValue);
IsolatedStorageSettings.ApplicationSettings["notification_uri"] = value;
+ if (!string.IsNullOrEmpty(value))
+ RegisterNotificationUrl(value);
}
}
-
-
+
+
public void SignOut(Page page)
{
IsAuthenticated = false;
+ App.AppContext.DisableNotifications();
page.NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative));
page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry());
}
+
+ void RegisterNotificationUrl(string newUrl)
+ {
+ App.AppContext.Client.ExecuteAsync(new RestRequest("/winphone/register?url=" + newUrl),
+ response => Debug.WriteLine("Registering push url, status {0}: {1}", response.Request.Resource, response.StatusCode));
+ }
+ void UnregisterNotificationUrl(string oldUrl)
+ {
+ App.AppContext.Client.ExecuteAsync(new RestRequest("/winphone/unregister?url=" + oldUrl),
+ response => Debug.WriteLine("Unregistered push url, status {0}: {1}", response.Request.Resource, response.StatusCode));
+ }
}
}
diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs
index 20beef5..7baa6dd 100644
--- a/Juick/MainPage.xaml.cs
+++ b/Juick/MainPage.xaml.cs
@@ -70,7 +70,7 @@ namespace Juick
}
if (!string.IsNullOrEmpty(FileId) || navigateUri.StartsWith(loginUriPart))
{
- NavigationService.Navigate(new Uri(navigateUri, UriKind.Relative));
+ ((App)Application.Current).NavigateTo(new Uri(navigateUri, UriKind.Relative), true);
}
if (queryStrings.ContainsKey("mid"))
{
diff --git a/Juick/ViewModels/AppViewModel.cs b/Juick/ViewModels/AppViewModel.cs
index 7d5006c..ab00cb0 100644
--- a/Juick/ViewModels/AppViewModel.cs
+++ b/Juick/ViewModels/AppViewModel.cs
@@ -28,8 +28,13 @@ namespace Juick.ViewModels
pushChannel = new HttpNotificationChannel(channelName);
// Register for all the events before attempting to open the channel.
- pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(e.ChannelUri.ToString());
- pushChannel.ErrorOccurred += (sender, e) => DisableNotifications();
+ pushChannel.ChannelUriUpdated += (sender, e) => {
+ EnableNotifications();
+ };
+ pushChannel.ErrorOccurred += (sender, e) =>
+ {
+ DisableNotifications();
+ };
// Register for this notification only if you need to receive the notifications while your application is running.
// Register for this notification only if you need to receive the notifications while your application is running.
@@ -56,17 +61,15 @@ namespace Juick.ViewModels
}
Debug.WriteLine("Received: " + message.ToString());
};
-
- pushChannel.Open();
-
- // Bind this new channel for toast events.
- pushChannel.BindToShellToast();
-
+ pushChannel.Open();
}
else
{
// The channel was already open, so just register for all the events.
- pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(e.ChannelUri.ToString());
+ pushChannel.ChannelUriUpdated += (sender, e) =>
+ {
+ EnableNotifications();
+ };
pushChannel.ErrorOccurred += (sender, e) => DisableNotifications();
// Register for this notification only if you need to receive the notifications while your application is running.
@@ -92,10 +95,8 @@ namespace Juick.ViewModels
}
}
Debug.WriteLine("Received: " + message.ToString());
- };
-
- EnableNotifications(pushChannel.ChannelUri.ToString());
- }
+ };
+ }
}
private ObservableCollection _pages;
public ObservableCollection Pages
@@ -139,37 +140,23 @@ namespace Juick.ViewModels
}
}
- public void EnableNotifications(string Url)
+ public void EnableNotifications()
{
if (!Account.IsAuthenticated) return;
- Client.Authenticator = new HttpBasicAuthenticator(Account.UserName, Account.Password);
- Debug.WriteLine(Url.ToString());
- if (string.IsNullOrEmpty(Account.NotificationUri) || Account.NotificationUri == Url)
- {
- Account.NotificationUri = Url;
- RegisterNotificationUrl(Url);
- }
- else
- {
- UnregisterNotificationUrl(Account.NotificationUri);
- Account.NotificationUri = Url;
- RegisterNotificationUrl(Url);
- }
+ var channelUri = pushChannel.ChannelUri.ToString();
+ if (channelUri == Account.NotificationUri)
+ return;
+ Account.NotificationUri = channelUri;
+ if (!pushChannel.IsShellToastBound)
+ // Bind this new channel for toast events.
+ pushChannel.BindToShellToast();
}
public void DisableNotifications()
{
- UnregisterNotificationUrl(Account.NotificationUri);
+ if (pushChannel.IsShellToastBound)
+ pushChannel.UnbindToShellToast();
Account.NotificationUri = string.Empty;
- }
-
- void RegisterNotificationUrl(string newUrl)
- {
- Client.ExecuteAsync(new RestRequest("/winphone/register?url=" + newUrl), response => Debug.WriteLine(response.StatusCode));
- }
- void UnregisterNotificationUrl(string oldUrl)
- {
- Client.ExecuteAsync(new RestRequest("/winphone/unregister?url=" + oldUrl), response => Debug.WriteLine(response.StatusCode));
- }
+ }
}
}
diff --git a/Juick/ViewModels/LoginViewModel.cs b/Juick/ViewModels/LoginViewModel.cs
index 2bc5bda..c0bf1f9 100644
--- a/Juick/ViewModels/LoginViewModel.cs
+++ b/Juick/ViewModels/LoginViewModel.cs
@@ -59,11 +59,12 @@ namespace Juick.ViewModels
App.AppContext.Account.UserName = Username;
App.AppContext.Account.Password = Password;
App.AppContext.Account.IsAuthenticated = true;
+ App.AppContext.EnableNotifications();
((App)Application.Current).NavigateTo(NextUri, true);
}
else
{
- //AddError("Username", "Invalid username or password", false);
+ MessageBox.Show("Invalid username or password", "Error", MessageBoxButton.OK);
}
});
}
--
cgit v1.2.3
From 6fed9b8d6a99060502a2a015e6185d9208c32e62 Mon Sep 17 00:00:00 2001
From: Vitaly Takmazov
Date: Tue, 23 Apr 2013 16:11:29 +0400
Subject: Version 1.1
---
Juick/Properties/AssemblyInfo.cs | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Juick/Properties/AssemblyInfo.cs b/Juick/Properties/AssemblyInfo.cs
index 9a99ba0..7d007ab 100644
--- a/Juick/Properties/AssemblyInfo.cs
+++ b/Juick/Properties/AssemblyInfo.cs
@@ -32,6 +32,6 @@ using System.Resources;
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.9.10")]
-[assembly: AssemblyFileVersion("1.0.9.10")]
+[assembly: AssemblyVersion("1.1.0")]
+[assembly: AssemblyFileVersion("1.1.0")]
[assembly: NeutralResourcesLanguageAttribute("en-US")]
--
cgit v1.2.3
From 9fea202330ebc7e9f85e7f88c4ce9c62ae3490e9 Mon Sep 17 00:00:00 2001
From: Konstantin
Date: Thu, 25 Apr 2013 23:35:23 +0400
Subject: subscribe/unsubscribe
---
Juick/ThreadView.xaml | 108 ++++++++++++-------------
Juick/ThreadView.xaml.cs | 199 +++++++++++++++++++++++++----------------------
2 files changed, 162 insertions(+), 145 deletions(-)
diff --git a/Juick/ThreadView.xaml b/Juick/ThreadView.xaml
index d52a343..2f67219 100644
--- a/Juick/ThreadView.xaml
+++ b/Juick/ThreadView.xaml
@@ -1,53 +1,55 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Juick/ThreadView.xaml.cs b/Juick/ThreadView.xaml.cs
index 4e1da97..354a3cd 100644
--- a/Juick/ThreadView.xaml.cs
+++ b/Juick/ThreadView.xaml.cs
@@ -1,93 +1,108 @@
-using System;
-using System.Linq;
-using System.Windows.Controls;
-using System.Windows.Navigation;
-using Juick.ViewModels;
-using Microsoft.Phone.Controls;
-using Microsoft.Phone.Shell;
-using System.Windows.Data;
-using System.Windows;
-using RestSharp;
-using System.Net;
-
-namespace Juick
-{
- public partial class ThreadView : PhoneApplicationPage
- {
- public ThreadView()
- {
- InitializeComponent();
- Model = new ThreadViewModel(App.AppContext);
- DataContext = Model;
- Loaded += (o, args) =>
- {
- var progressIndicator = SystemTray.ProgressIndicator;
-
- if (progressIndicator != null)
- {
- return;
- }
- progressIndicator = new ProgressIndicator();
-
- SystemTray.SetProgressIndicator(this, progressIndicator);
-
- Binding binding = new Binding("IsDataLoading") { Source = App.AppContext };
-
- BindingOperations.SetBinding(
- progressIndicator, ProgressIndicator.IsVisibleProperty, binding);
-
- binding = new Binding("IsDataLoading") { Source = App.AppContext };
-
- BindingOperations.SetBinding(
- progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding);
- };
- }
-
- public ThreadViewModel Model;
-
- // When page is navigated to set data context to selected item in list
- protected override void OnNavigatedTo(NavigationEventArgs e)
- {
- if (Model.Items.Count > 0)
- return;
- string _mid = "";
- if (NavigationContext.QueryString.TryGetValue("mid", out _mid))
- {
- Model.Mid = int.Parse(_mid);
- }
- Model.RefreshData();
- }
-
- private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
- {
- // If selected index is -1 (no selection) do nothing
- if (((ListBox)sender).SelectedIndex == -1)
- return;
-
- // Navigate to the new page
- var item = Model.Items[((ListBox)sender).SelectedIndex];
- var destUri = string.Format("/NewPostView.xaml?mid={0}", item.MID);
- if (item.RID > 0)
- destUri += string.Format("&rid={0}", item.RID);
- NavigationService.Navigate(new Uri(destUri, UriKind.Relative));
-
- // Reset selected index to -1 (no selection)
- ((ListBox)sender).SelectedIndex = -1;
- }
-
- void RecommendBarMenuItem_Click(object sender, EventArgs e)
- {
- var request = new RestRequest("/post", Method.POST);
- request.AddParameter("body", "! #" + Model.Mid);
- App.AppContext.Client.ExecuteAsync(request, response =>
- {
- App.AppContext.IsDataLoading = false;
- if (response.StatusCode != HttpStatusCode.OK && !string.IsNullOrEmpty(response.Content))
- {
- MessageBox.Show(string.Concat(response.StatusCode, ": ", response.Content));
- }
- });
- App.AppContext.IsDataLoading = true;
- }
- }
+using System;
+using System.Linq;
+using System.Windows.Controls;
+using System.Windows.Navigation;
+using Juick.ViewModels;
+using Microsoft.Phone.Controls;
+using Microsoft.Phone.Shell;
+using System.Windows.Data;
+using System.Windows;
+using RestSharp;
+using System.Net;
+
+namespace Juick
+{
+ public partial class ThreadView : PhoneApplicationPage
+ {
+ public ThreadView()
+ {
+ InitializeComponent();
+ Model = new ThreadViewModel(App.AppContext);
+ DataContext = Model;
+ Loaded += (o, args) =>
+ {
+ var progressIndicator = SystemTray.ProgressIndicator;
+
+ if (progressIndicator != null)
+ {
+ return;
+ }
+ progressIndicator = new ProgressIndicator();
+
+ SystemTray.SetProgressIndicator(this, progressIndicator);
+
+ Binding binding = new Binding("IsDataLoading") { Source = App.AppContext };
+
+ BindingOperations.SetBinding(
+ progressIndicator, ProgressIndicator.IsVisibleProperty, binding);
+
+ binding = new Binding("IsDataLoading") { Source = App.AppContext };
+
+ BindingOperations.SetBinding(
+ progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding);
+ };
+ }
+
+ public ThreadViewModel Model;
+
+ // When page is navigated to set data context to selected item in list
+ protected override void OnNavigatedTo(NavigationEventArgs e)
+ {
+ if (Model.Items.Count > 0)
+ return;
+ string _mid = "";
+ if (NavigationContext.QueryString.TryGetValue("mid", out _mid))
+ {
+ Model.Mid = int.Parse(_mid);
+ }
+ Model.RefreshData();
+ }
+
+ private void ListBox_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
+ {
+ // If selected index is -1 (no selection) do nothing
+ if (((ListBox)sender).SelectedIndex == -1)
+ return;
+
+ // Navigate to the new page
+ var item = Model.Items[((ListBox)sender).SelectedIndex];
+ var destUri = string.Format("/NewPostView.xaml?mid={0}", item.MID);
+ if (item.RID > 0)
+ destUri += string.Format("&rid={0}", item.RID);
+ NavigationService.Navigate(new Uri(destUri, UriKind.Relative));
+
+ // Reset selected index to -1 (no selection)
+ ((ListBox)sender).SelectedIndex = -1;
+ }
+
+ void RecommendBarMenuItem_Click(object sender, EventArgs e)
+ {
+ ExecuteJuickAction("!");
+ }
+
+ void SubscribeBarMenuItem_Click(object sender, EventArgs e)
+ {
+ ExecuteJuickAction("S");
+ }
+
+ void UnsubscribeBarMenuItem_Click(object sender, EventArgs e)
+ {
+ ExecuteJuickAction("U");
+ }
+
+ void ExecuteJuickAction(string action)
+ {
+ var request = new RestRequest("/post", Method.POST);
+ request.AddParameter("body", string.Concat(action, " #", Model.Mid));
+ App.AppContext.Client.ExecuteAsync(request, response =>
+ {
+ App.AppContext.IsDataLoading = false;
+ if(response.StatusCode != HttpStatusCode.OK || !string.IsNullOrEmpty(response.Content))
+ {
+ MessageBox.Show(string.Concat(response.StatusCode, ": ", response.Content));
+ }
+ });
+ App.AppContext.IsDataLoading = true;
+ }
+ }
}
\ No newline at end of file
--
cgit v1.2.3