private void ChangedText(DependencyPropertyChangedEventArgs e) { if (e.OldValue != e.NewValue) { Paragraph richtext = GoogleTalkHelper.Linkify((string)e.NewValue); RichText.Blocks.Add(richtext); } }
public GoogleTalk() { LoggedIn = false; var uri = new Uri(GoogleTalkHelper.IsPaid() ? "PlusApiKey.txt" : "ApiKey.txt", UriKind.RelativeOrAbsolute); var resourceStream = App.GetResourceStream(uri); using (var sr = new StreamReader(resourceStream.Stream)) { ApiKey = sr.ReadLine().Trim(); } }
private void Login_Click(object sender, EventArgs e) { if (settings.Contains("username") && ((string)settings["username"]) == Username.Text && (settings.Contains("auth") || (settings.Contains("token") && settings.Contains("rootUrl")))) { NavigationService.GoBack(); return; } // track login attempt FlurryWP7SDK.Api.LogEvent("Login started", true); ShowProgressBar(AppResources.Login_Progress); Username.IsEnabled = false; Password.IsEnabled = false; (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = false; settings["username"] = Username.Text; settings["password"] = ProtectedData.Protect(Encoding.UTF8.GetBytes(Password.Password), null); settings.Save(); GoogleTalkHelper.GoogleLogin( Username.Text, Password.Password, token => Dispatcher.BeginInvoke(() => { settings["auth"] = ProtectedData.Protect( Encoding.UTF8.GetBytes(token), null ); settings.Save(); var par = new List <Parameter>(); par.Add(new Parameter("Result", "success")); FlurryWP7SDK.Api.EndTimedEvent("Login started", par); NavigationService.GoBack(); }), error => Dispatcher.BeginInvoke(() => { MessageBox.Show(error, AppResources.Error_AuthErrorTitle, MessageBoxButton.OK); HideProgressBar(); Username.IsEnabled = true; Password.IsEnabled = true; (ApplicationBar.Buttons[0] as ApplicationBarIconButton).IsEnabled = true; // track unsuccessful login var par = new List <Parameter>(); par.Add(new Parameter("Result", "auth error")); FlurryWP7SDK.Api.EndTimedEvent("Login started", par); }) ); }
private void SetLicenseNotice() { if (GoogleTalkHelper.IsPaid()) { PaidVersionNotice.FontSize = (double)App.Current.Resources["PhoneFontSizeMedium"]; FreeVersionNotice.FontSize = 0.1; } else { FreeVersionNotice.FontSize = (double)App.Current.Resources["PhoneFontSizeMedium"]; PaidVersionNotice.FontSize = 0.1; } }
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) { base.OnNavigatedTo(e); FlurryWP7SDK.Api.LogEvent("ContactList - ContactList started", true); if (App.Current.LastPage != null && App.Current.LastPage.StartsWith("/Pages/Chat.xaml?from=") && App.Current.RootFrame.BackStack.Count() > 0) { App.Current.RootFrame.RemoveBackEntry(); } App.Current.LastPage = e.Uri.OriginalString; if (gtalkHelper != App.Current.GtalkHelper) { gtalkHelper = App.Current.GtalkHelper; Dispatcher.BeginInvoke(() => AllContactsListBox.ItemsSource = App.Current.Roster); } gtalkHelper.RosterUpdated += RosterLoaded; gtalkHelper.ConnectFailed += ConnectFailed; gtalkHelper.SetCorrectOrientation(this); Dispatcher.BeginInvoke( () => { if (gtalkHelper.RosterLoaded) { HideProgressBar(); } else { ShowProgressBar(AppResources.ContactList_ProgressLoading); } }); if (gtalkHelper.RosterLoaded && App.Current.GtalkClient.LoggedIn) { if (e.IsNavigationInitiator) { gtalkHelper.GetOfflineMessages(() => { }); } } else { UpdateRoster(); } gtalkHelper.LoginIfNeeded(); gtalkHelper.MessageReceived += gtalkHelper.ShowToast; }
// Code to execute when the application is activated (brought to foreground) // This code will not execute when the application is first launched private void Application_Activated(object sender, ActivatedEventArgs e) { if (!e.IsApplicationInstancePreserved) { if (Settings == null) { Settings = IsolatedStorageSettings.ApplicationSettings; } if (PushHelper == null) { PushHelper = new PushHelper(); } if (GtalkClient == null) { GtalkClient = new GoogleTalk(); } if (RecentContacts == null) { if (!Settings.Contains("recent")) { Settings["recent"] = RecentContacts = new ObservableCollection <Contact>(); } RecentContacts = Settings["recent"] as ObservableCollection <Contact>; } if (!Settings.Contains("chatlog")) { Settings["chatlog"] = new Dictionary <string, List <Message> >(); } if (!Settings.Contains("unread")) { Settings["unread"] = new Dictionary <string, int>(); } if (GtalkHelper == null) { GtalkHelper = new GoogleTalkHelper(); } InitAnalytics(); PushHelper.RegisterPushNotifications(); } Roster.Load(); }
// Code to execute when the application is launching (eg, from Start) // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { Settings = IsolatedStorageSettings.ApplicationSettings; PushHelper = new PushHelper(); GtalkClient = new GoogleTalk(); if (!Settings.Contains("chatlog")) { Settings["chatlog"] = new Dictionary <string, List <Message> >(); } if (!Settings.Contains("unread")) { Settings["unread"] = new Dictionary <string, int>(); } if (!Settings.Contains("recent")) { Settings["recent"] = new ObservableCollection <Contact>(); } GtalkHelper = new GoogleTalkHelper(); Roster.Load(); RecentContacts = Settings["recent"] as ObservableCollection <Contact>; PushHelper.RegisterPushNotifications(); InitAnalytics(); if (Settings.Contains("lastError")) { RootFrame.Dispatcher.BeginInvoke(() => { var result = MessageBox.Show( AppResources.CrashReport_Message, AppResources.CrashReport_Title, MessageBoxButton.OKCancel ); if (result == MessageBoxResult.OK) { GtalkClient.CrashReport(Settings["lastError"] as string, success => Settings.Remove("lastError"), error => { }); } else { Settings.Remove("lastError"); } }); } }
private void InitAnalytics() { // Init flurry analytics var uri = new Uri("FlurryApiKey.txt", UriKind.RelativeOrAbsolute); var resourceStream = App.GetResourceStream(uri); string apikey; if (resourceStream != null) { using (var sr = new StreamReader(resourceStream.Stream)) { apikey = sr.ReadLine().Trim(); } FlurryWP7SDK.Api.StartSession(apikey); FlurryWP7SDK.Api.SetSecureTransportEnabled(); FlurryWP7SDK.Api.SetVersion(String.Format("{0} {1}", AppResources.AppName, AppResources.AppVersion)); if (GoogleTalkHelper.IsPaid()) { FlurryWP7SDK.Api.LogEvent("Paid user"); } } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); FlurryWP7SDK.Api.LogEvent("Chat - Chat started", true); App.Current.LastPage = e.Uri.OriginalString; gtalk = App.Current.GtalkClient; gtalkHelper = App.Current.GtalkHelper; settings = App.Current.Settings; App.Current.GtalkHelper.SetCorrectOrientation(this); currentContact = null; if (NavigationContext.QueryString.ContainsKey("from")) { to = NavigationContext.QueryString["from"]; email = to; if (email.Contains("/")) { email = email.Substring(0, email.IndexOf('/')); } App.Current.CurrentChat = email; to = email; if (App.Current.Roster.Contains(email)) { currentContact = App.Current.Roster[email]; } } gtalkHelper.MessageReceived += DisplayMessage; if (gtalkHelper.RosterLoaded && gtalk.LoggedIn && App.Current.Roster.Contains(email)) { Initialize(); if (e.NavigationMode == NavigationMode.Back) { ShowProgressBar(AppResources.Chat_ProgressGettingMessages); gtalkHelper.GetOfflineMessages(() => Dispatcher.BeginInvoke(() => HideProgressBar())); } } else { Initialize(); ShowProgressBar(AppResources.Chat_ProgressGettingMessages); gtalkHelper.RosterUpdated += () => HideProgressBar(); gtalkHelper.RosterUpdated += Initialize; } object savedText; if (State.TryGetValue("message", out savedText)) { MessageText.Text = (string)savedText; } gtalkHelper.LoginIfNeeded(); ScrollToBottom(); }