summaryrefslogtreecommitdiff
path: root/Juick/ViewModels
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/ViewModels')
-rw-r--r--Juick/ViewModels/AppViewModel.cs94
-rw-r--r--Juick/ViewModels/LoginViewModel.cs6
-rw-r--r--Juick/ViewModels/NewPostViewModel.cs28
-rw-r--r--Juick/ViewModels/PostItem.cs9
4 files changed, 70 insertions, 67 deletions
diff --git a/Juick/ViewModels/AppViewModel.cs b/Juick/ViewModels/AppViewModel.cs
index 4b30c08..e3a58bb 100644
--- a/Juick/ViewModels/AppViewModel.cs
+++ b/Juick/ViewModels/AppViewModel.cs
@@ -19,12 +19,7 @@ namespace Juick.ViewModels
readonly HttpNotificationChannel pushChannel;
// The name of our push channel.
- private const string channelName = "JuickChannel";
-
- public void UpdateNetworkStatus()
- {
- NetworkUnavailable = !DeviceNetworkInformation.IsNetworkAvailable;
- }
+ string channelName = "JuickChannel";
public void UpdateNetworkStatus()
{
@@ -38,19 +33,24 @@ namespace Juick.ViewModels
pushChannel = HttpNotificationChannel.Find(channelName);
// If the channel was not found, then create a new connection to the push service.
- if (_pushChannel == null)
+ if (pushChannel == null)
{
- _pushChannel = new HttpNotificationChannel(channelName);
+ 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.
- _pushChannel.ShellToastNotificationReceived += (sender, e) =>
+ pushChannel.ShellToastNotificationReceived += (sender, e) =>
{
- var message = new StringBuilder();
+ StringBuilder message = new StringBuilder();
string relativeUri = string.Empty;
message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString());
@@ -71,21 +71,19 @@ 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.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.
- _pushChannel.ShellToastNotificationReceived += (sender, e) =>
+ pushChannel.ShellToastNotificationReceived += (sender, e) =>
{
StringBuilder message = new StringBuilder();
string relativeUri = string.Empty;
@@ -107,10 +105,8 @@ namespace Juick.ViewModels
}
}
Debug.WriteLine("Received: " + message.ToString());
- };
-
- EnableNotifications(_pushChannel.ChannelUri.ToString());
- }
+ };
+ }
}
private ObservableCollection<PageViewModel> _pages;
public ObservableCollection<PageViewModel> Pages
@@ -145,18 +141,6 @@ namespace Juick.ViewModels
}
}
- private bool _isNetworkUnavailable;
- public bool NetworkUnavailable
- {
- get { return _isNetworkUnavailable; }
- set
- {
- _isNetworkUnavailable = value;
- NotifyPropertyChanged(IsNetworkAvailablePropertyName);
- }
- }
-
-
private AccountManager _acc;
public AccountManager Account
@@ -176,37 +160,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 95528fe..c0bf1f9 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;
@@ -60,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);
}
});
}
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;
+ }
+ }
+}
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)