1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Data;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Juick.ViewModels;
using RestSharp;
namespace Juick
{
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
// Holds the push channel that is created or found.
InitializeComponent();
DataContext = App.AppContext;
Loaded += (o, args) =>
{
var progressIndicator = SystemTray.ProgressIndicator;
if (progressIndicator != null)
{
return;
}
progressIndicator = new ProgressIndicator();
SystemTray.SetProgressIndicator(this, progressIndicator);
Binding binding = new Binding("IsDataLoading") { Source = DataContext };
BindingOperations.SetBinding(
progressIndicator, ProgressIndicator.IsVisibleProperty, binding);
binding = new Binding("IsDataLoading") { Source = DataContext };
BindingOperations.SetBinding(
progressIndicator, ProgressIndicator.IsIndeterminateProperty, binding);
if (App.AppContext.Account.IsAuthenticated)
foreach (var page in ((AppViewModel)DataContext).Pages)
page.RefreshData();
};
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
var loginUriPart = "/LoginView.xaml";
var newPostUriPart = "/NewPostView.xaml";
var navigateUri = string.Empty;
var FileId = string.Empty;
// Get a dictionary of query string keys and values.
IDictionary<string, string> queryStrings = NavigationContext.QueryString;
// Ensure that there is at least one key in the query string, and check
// whether the "FileId" key is present.
navigateUri = App.AppContext.Account.IsAuthenticated ? newPostUriPart : loginUriPart;
if (queryStrings.ContainsKey("FileId"))
{
FileId = queryStrings["FileId"];
navigateUri = string.Format("{0}?FileId={1}", navigateUri, FileId);
}
if (!string.IsNullOrEmpty(FileId) || navigateUri.StartsWith(loginUriPart))
{
((App)Application.Current).NavigateTo(new Uri(navigateUri, UriKind.Relative), true);
}
if (queryStrings.ContainsKey("mid"))
{
var mid = queryStrings["mid"];
navigateUri = string.Format("/ThreadView.xaml?mid={0}", mid);
((App)Application.Current).NavigateTo(new Uri(navigateUri, UriKind.Relative), true);
}
App.AppContext.Client.Authenticator = new HttpBasicAuthenticator(App.AppContext.Account.UserName, App.AppContext.Account.Password);
}
private void ApplicationBarIconButtonClick(object sender, EventArgs e)
{
foreach (var page in App.AppContext.Pages)
{
page.Items.Clear();
page.RefreshData();
}
}
private void ApplicationBarMenuItemClick(object sender, EventArgs e)
{
App.AppContext.Account.SignOut(this);
}
private void ApplicationBarIconButtonClick1(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/NewPostView.xaml", UriKind.Relative));
}
}
}
|