summaryrefslogtreecommitdiff
path: root/Juick/Classes
diff options
context:
space:
mode:
Diffstat (limited to 'Juick/Classes')
-rw-r--r--Juick/Classes/AccountManager.cs40
-rw-r--r--Juick/Classes/BooleanToVisibiltyConverter.cs24
-rw-r--r--Juick/Classes/DateHelper.cs67
3 files changed, 98 insertions, 33 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<string>("user", out _userName);
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("user", out _userName);
}
return _userName;
}
@@ -34,7 +36,7 @@ namespace Juick.Classes
{
if (_password == null)
{
- IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("password", out _password);
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("password", out _password);
}
return _password;
}
@@ -47,7 +49,8 @@ namespace Juick.Classes
public bool IsAuthenticated
{
- get {
+ get
+ {
bool authenticated;
IsolatedStorageSettings.ApplicationSettings.TryGetValue<bool>("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<string>("notification_uri", out savedUri);
- return savedUri;
+ string _notificationUri;
+ IsolatedStorageSettings.ApplicationSettings.TryGetValue<string>("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/Classes/BooleanToVisibiltyConverter.cs b/Juick/Classes/BooleanToVisibiltyConverter.cs
deleted file mode 100644
index 679cc3f..0000000
--- a/Juick/Classes/BooleanToVisibiltyConverter.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Globalization;
-using System.Linq;
-using System.Text;
-using System.Windows;
-using System.Windows.Data;
-
-namespace Juick.Classes
-{
- public class BooleanToVisibiltyConverter : IValueConverter
- {
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- var visible = (bool) value;
- return visible ? Visibility.Visible : Visibility.Collapsed;
- }
-
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
-}
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";
+ }
+ }
+}