From 151e56ec2e3466389804b8874b4224bf6bd08097 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 3 Apr 2013 05:03:20 +0400 Subject: New pages, LoginViewModel, Validation (in progress) --- Juick/App.xaml.cs | 25 +++++--- Juick/Classes/AccountManager.cs | 62 +++++++++++--------- Juick/Controls/MessageList.xaml | 2 +- Juick/Juick.csproj | 2 + Juick/LoginView.xaml | 36 +++++++----- Juick/LoginView.xaml.cs | 22 +++----- Juick/MainPage.xaml | 19 ++++--- Juick/MainPage.xaml.cs | 55 ++++++++++-------- Juick/NewPostView.xaml.cs | 2 +- Juick/ViewModels/LoginViewModel.cs | 72 ++++++++++++++++++++++++ Juick/ViewModels/PageViewModel.cs | 4 +- Juick/ViewModels/Validation/DataViewModelBase.cs | 44 +++++++++++++++ 12 files changed, 245 insertions(+), 100 deletions(-) create mode 100644 Juick/ViewModels/LoginViewModel.cs create mode 100644 Juick/ViewModels/Validation/DataViewModelBase.cs (limited to 'Juick') diff --git a/Juick/App.xaml.cs b/Juick/App.xaml.cs index 98dc31c..03e0d10 100644 --- a/Juick/App.xaml.cs +++ b/Juick/App.xaml.cs @@ -10,22 +10,31 @@ namespace Juick { public partial class App : Application { - public void NavigateTo(Uri param) { - RootFrame.Navigate(param); + public void NavigateTo(Uri param, bool removeFromStack = false) + { + var page = (PhoneApplicationPage) RootFrame.Content; + var service = page.NavigationService; + service.Navigate(param); + if (removeFromStack) + { + page.Dispatcher.BeginInvoke(() => service.RemoveBackEntry()); + } } - private static AppViewModel context = null; + private static AppViewModel _context = null; public static AppViewModel AppContext { get { // Delay creation of the view model until necessary - if (context == null) { - context = new AppViewModel(); - context.Pages.Add(new PageViewModel(context) { RestUri = "/home?1=1" }); - context.Pages.Add(new PageViewModel(context) { RestUri = "/messages?1=1" }); + if (_context == null) { + _context = new AppViewModel(); + _context.Pages.Add(new PageViewModel(_context) { RestUri = "/home?1=1", Caption = "My feed"}); + _context.Pages.Add(new PageViewModel(_context) { RestUri = "/messages?1=1", Caption = "Last"}); + _context.Pages.Add(new PageViewModel(_context) { RestUri = "/messages?1=1&popular=1", Caption = "Top"}); + _context.Pages.Add(new PageViewModel(_context) { RestUri = "/messages?1=1&media=all", Caption = "Images" }); }; - return context; + return _context; } } /// diff --git a/Juick/Classes/AccountManager.cs b/Juick/Classes/AccountManager.cs index 8f8e366..4741992 100644 --- a/Juick/Classes/AccountManager.cs +++ b/Juick/Classes/AccountManager.cs @@ -1,53 +1,63 @@ using System; using System.IO.IsolatedStorage; using System.Net; +using System.Windows; using System.Windows.Controls; namespace Juick.Classes { public class AccountManager { - const string FileName = "account.xml"; - public NetworkCredential Credentials + private string _userName; + private string _password; + + public string UserName { get { - string userName; - string password; - IsolatedStorageSettings.ApplicationSettings.TryGetValue("user", out userName); - IsolatedStorageSettings.ApplicationSettings.TryGetValue("password", out password); - return new NetworkCredential - { - UserName = userName, - Password = password, - }; + if (_userName == null) + { + IsolatedStorageSettings.ApplicationSettings.TryGetValue("user", out _userName); + } + return _userName; } set { - var creds = value; - if (creds != null) - { - IsolatedStorageSettings.ApplicationSettings["user"] = value.UserName; - IsolatedStorageSettings.ApplicationSettings["password"] = value.Password; - } - else + _userName = value; + IsolatedStorageSettings.ApplicationSettings["user"] = _userName; + } + } + + public string Password + { + get + { + if (_password == null) { - IsolatedStorageSettings.ApplicationSettings["user"] = null; - IsolatedStorageSettings.ApplicationSettings["password"] = null; + IsolatedStorageSettings.ApplicationSettings.TryGetValue("password", out _password); } + return _password; + } + set + { + _password = value; + IsolatedStorageSettings.ApplicationSettings["password"] = value; } } - public void SignIn(Page page, string login, string pass, Uri nextUri) + public bool IsAuthenticated { - Credentials = new NetworkCredential(login, pass); - page.NavigationService.Navigate(nextUri); - page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); + get { + bool authenticated; + IsolatedStorageSettings.ApplicationSettings.TryGetValue("authenticated", out authenticated); + return authenticated; + } + set { IsolatedStorageSettings.ApplicationSettings["authenticated"] = value; } } - + public void SignOut(Page page) { - Credentials = null; + IsAuthenticated = false; page.NavigationService.Navigate(new Uri("/LoginView.xaml", UriKind.Relative)); page.Dispatcher.BeginInvoke(() => page.NavigationService.RemoveBackEntry()); } diff --git a/Juick/Controls/MessageList.xaml b/Juick/Controls/MessageList.xaml index 7a7d823..afa6c69 100644 --- a/Juick/Controls/MessageList.xaml +++ b/Juick/Controls/MessageList.xaml @@ -14,7 +14,7 @@ d:DesignHeight="480" d:DesignWidth="480"> - diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj index ebe128c..33fbd5c 100644 --- a/Juick/Juick.csproj +++ b/Juick/Juick.csproj @@ -103,9 +103,11 @@ ThreadView.xaml + + diff --git a/Juick/LoginView.xaml b/Juick/LoginView.xaml index ad1d70c..004580a 100644 --- a/Juick/LoginView.xaml +++ b/Juick/LoginView.xaml @@ -3,15 +3,19 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" - xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" + xmlns:phoneshell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:viewModels="clr-namespace:Juick.ViewModels" FontFamily="{StaticResource PhoneFontFamilyNormal}" FontSize="{StaticResource PhoneFontSizeNormal}" Foreground="{StaticResource PhoneForegroundBrush}" SupportedOrientations="Portrait" Orientation="Portrait" mc:Ignorable="d" d:DesignHeight="768" d:DesignWidth="480" - shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded"> + phoneshell:SystemTray.IsVisible="True"> + + + @@ -28,24 +32,26 @@ - - - -