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/MainPage.xaml.cs | 55 ++++++++++++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 24 deletions(-) (limited to 'Juick/MainPage.xaml.cs') diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs index a634e7f..1c76ee1 100644 --- a/Juick/MainPage.xaml.cs +++ b/Juick/MainPage.xaml.cs @@ -4,10 +4,12 @@ using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; +using Juick.Controls; using Microsoft.Phone.Controls; using Microsoft.Phone.Notification; using Microsoft.Phone.Shell; using Juick.ViewModels; +using RestSharp; namespace Juick { @@ -23,7 +25,7 @@ namespace Juick //string channelName = "JuickChannel"; // unused variable InitializeComponent(); - + /* // Try to find the push channel. pushChannel = HttpNotificationChannel.Find(channelName); @@ -61,33 +63,32 @@ namespace Juick }*/ - // Set the data context of the listbox control to the sample data DataContext = App.AppContext; - Home.DataContext = ((AppViewModel)DataContext).Pages[0]; - Last.DataContext = ((AppViewModel)DataContext).Pages[1]; + Loaded += (o, args) => - { - var progressIndicator = SystemTray.ProgressIndicator; + { + Pages.SelectedIndex = 0; + var progressIndicator = SystemTray.ProgressIndicator; - if (progressIndicator != null) - { - return; - } + if (progressIndicator != null) + { + return; + } - progressIndicator = new ProgressIndicator(); + progressIndicator = new ProgressIndicator(); - SystemTray.SetProgressIndicator(this, progressIndicator); + SystemTray.SetProgressIndicator(this, progressIndicator); - Binding binding = new Binding("IsDataLoading") { Source = DataContext }; + Binding binding = new Binding("IsDataLoading") { Source = DataContext }; - BindingOperations.SetBinding( - progressIndicator, ProgressIndicator.IsVisibleProperty, binding); + BindingOperations.SetBinding( + progressIndicator, ProgressIndicator.IsVisibleProperty, binding); - binding = new Binding("IsDataLoading") { Source = DataContext }; + binding = new Binding("IsDataLoading") { Source = DataContext }; - BindingOperations.SetBinding( - progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding); - }; + BindingOperations.SetBinding( + progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding); + }; } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) @@ -102,7 +103,7 @@ namespace Juick // Ensure that there is at least one key in the query string, and check // whether the "FileId" key is present. - navigateUri = string.IsNullOrEmpty(App.AppContext.Account.Credentials.UserName) ? loginUriPart : newPostUriPart; + navigateUri = App.AppContext.Account.IsAuthenticated ? newPostUriPart : loginUriPart; if (queryStrings.ContainsKey("FileId")) { FileId = queryStrings["FileId"]; @@ -112,6 +113,11 @@ namespace Juick { NavigationService.Navigate(new Uri(navigateUri, UriKind.Relative)); } + App.AppContext.Client.Authenticator = new HttpBasicAuthenticator(App.AppContext.Account.UserName, App.AppContext.Account.Password); + if (App.AppContext.Account.IsAuthenticated) + foreach (var page in ((AppViewModel)DataContext).Pages) + page.RefreshData(); + } void PushChannel_ChannelUriUpdated(object sender, NotificationChannelUriEventArgs e) @@ -163,10 +169,11 @@ namespace Juick private void ApplicationBarIconButtonClick(object sender, EventArgs e) { - App.AppContext.Pages[0].Items.Clear(); - App.AppContext.Pages[1].Items.Clear(); - App.AppContext.Pages[0].RefreshData(); - App.AppContext.Pages[1].RefreshData(); + foreach (var page in App.AppContext.Pages) + { + page.Items.Clear(); + page.RefreshData(); + } } private void ApplicationBarMenuItemClick(object sender, EventArgs e) -- cgit v1.2.3