/// <summary> /// Fired when a post is tapped /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PostList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ui_postList.SelectedIndex == -1) { return; } // Get the post var tappedPost = (Post)ui_postList.SelectedItem; // Navigate to the post var args = new Dictionary <string, object>(); args.Add(PanelManager.NavArgsSubredditName, tappedPost.Subreddit); args.Add(PanelManager.NavArgsForcePostId, tappedPost.Id); // Make sure the page id is unique _mHost.Navigate(typeof(FlipViewPanel), tappedPost.Subreddit + SortTypes.Hot + SortTimeTypes.Week + tappedPost.Id, args); // Color the title so the user knows they read this. tappedPost.TitleTextColor = Color.FromArgb(255, 152, 152, 152); // Reset the selected index ui_postList.SelectedIndex = -1; TelemetryManager.ReportEvent(this, "UserProfilePostOpened"); }
/// <summary> /// Fired when a post is tapped /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommentList_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (ui_commentList.SelectedIndex == -1) { return; } // Get the post var tappedComment = (Comment)ui_commentList.SelectedItem; // Navigate flip view and force it to the post and comment. var args = new Dictionary <string, object>(); args.Add(PanelManager.NavArgsSubredditName, tappedComment.Subreddit); args.Add(PanelManager.NavArgsForcePostId, tappedComment.LinkId.Substring(3)); args.Add(PanelManager.NavArgsForceCommentId, tappedComment.Id); // Make sure the page Id is unique _mHost.Navigate(typeof(FlipViewPanel), tappedComment.Subreddit + SortTypes.Hot + SortTimeTypes.Week + tappedComment.LinkId + tappedComment.Id, args); // Reset the selected index ui_commentList.SelectedIndex = -1; // Report TelemetryManager.ReportEvent(this, "UserProfileCommentOpened"); }
private void HidePost_Click(object sender, RoutedEventArgs e) { var post = (sender as FrameworkElement)?.DataContext as Post; _collector.SaveOrHidePost(post, null, post != null && !post.IsHidden); TelemetryManager.ReportEvent(this, "HidePostTapped"); }
private void Post_Holding(object sender, HoldingRoutedEventArgs e) { if (sender is FrameworkElement element) { FlyoutBase.ShowAttachedFlyout(element); } TelemetryManager.ReportEvent(this, "PostHeldOpenedContextMenu"); }
private void Post_RightTapped(object sender, RightTappedRoutedEventArgs e) { if (sender is FrameworkElement element) { FlyoutBase.ShowAttachedFlyout(element); } TelemetryManager.ReportEvent(this, "RightClickedOpenedContextMenu"); }
private void Favorite_Tapped(object sender, TappedRoutedEventArgs e) { // Get the subreddit from the sender var sub = ((sender as Grid).DataContext as Subreddit); // Reverse the status App.BaconMan.SubredditMan.SetFavorite(sub.Id, !sub.IsFavorite); TelemetryManager.ReportEvent(this, "SubredditListFavoriteTapped"); }
/// <summary> /// Fired then the post sort is tapped /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CommentSort_Tapped(object sender, TappedRoutedEventArgs e) { var element = sender as FrameworkElement; var textBlock = FindCommentSortText(element); if (textBlock != null) { FlyoutBase.ShowAttachedFlyout(textBlock); } TelemetryManager.ReportEvent(this, "UserProfileCommentSort"); }
/// <summary> /// Fired when the user taps prfile in the menu. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ProfileGrid_Tapped(object sender, TappedRoutedEventArgs e) { if (App.BaconMan.UserMan.IsUserSignedIn) { // Navigate to the user. var args = new Dictionary <string, object>(); args.Add(PanelManager.NavArgsUserName, App.BaconMan.UserMan.CurrentUser.Name); _panelManager.Navigate(typeof(UserProfile), App.BaconMan.UserMan.CurrentUser.Name, args); TelemetryManager.ReportEvent(this, "GoToProfileViaGlobalMenu"); } ToggleMenu(false); }
private void CopyPermalink_Click(object sender, RoutedEventArgs e) { // Get the post and copy the url into the clipboard var post = (sender as FrameworkElement)?.DataContext as Post; var data = new DataPackage(); if (post != null) { data.SetText("http://www.reddit.com" + post.Permalink); } Clipboard.SetContent(data); TelemetryManager.ReportEvent(this, "CopyLinkTapped"); }
public async void OnNavigatingTo() { // Set the status bar color and get the size returned. If it is not 0 use that to move the // color of the page into the status bar. var statusBarHeight = await _host.SetStatusBar(null, 0); ApplicationSettingsRoot.Margin = new Thickness(0, -statusBarHeight, 0, 0); ApplicationSettingsRoot.Padding = new Thickness(0, statusBarHeight, 0, 0); _takeAction = false; TelemetryManager.ReportEvent(this, "ApplicationSettings"); AnalyticCollection.IsOn = App.BaconMan.UiSettingsMan.AnalyticCollection; _takeAction = true; }
private void ViewUser_Click(object sender, RoutedEventArgs e) { // Get the post var post = (sender as FrameworkElement)?.DataContext as Post; if (post != null) { var args = new Dictionary <string, object> { { PanelManager.NavArgsUserName, post.Author } }; _host.Navigate(typeof(UserProfile), post.Author, args); } TelemetryManager.ReportEvent(this, "SubredditNavToUser"); }
/// <summary> /// Fired when the search header is tapped /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SearchHeader_Tapped(object sender, TappedRoutedEventArgs e) { // If the search box is empty close or open the box if (string.IsNullOrWhiteSpace(ui_quickSearchBox.Text)) { TelemetryManager.ReportEvent(this, "QuickSearchOpened"); ToggleQuickSearch(); } else { // We have search content, go to search. var args = new Dictionary <string, object> { { PanelManager.NavArgsSearchQuery, ui_quickSearchBox.Text } }; _panelManager.Navigate(typeof(Search), "Search", args); CloseAllPanels(true); } }
public async void OnNavigatingTo() { // Set the status bar color and get the size returned. If it is not 0 use that to move the // color of the page into the status bar. var statusBarHeight = await _host.SetStatusBar(null, 0); ui_contentRoot.Margin = new Thickness(0, -statusBarHeight, 0, 0); ui_contentRoot.Padding = new Thickness(0, statusBarHeight, 0, 0); _takeAction = false; TelemetryManager.ReportEvent(this, "DevSettingsOpened"); ui_debuggingOn.IsOn = App.BaconMan.UiSettingsMan.DeveloperDebug; ui_preventAppCrashes.IsOn = App.BaconMan.UiSettingsMan.DeveloperStopFatalCrashesAndReport; ui_showMemoryOverlay.IsOn = App.BaconMan.UiSettingsMan.DeveloperShowMemoryOverlay; _takeAction = true; // Set the clean up text ui_numberPagesCleanedUp.Text = $"Pages cleaned up for memory pressure: {App.BaconMan.UiSettingsMan.PagesMemoryCleanedUp}"; }
private async void ReportUserLoadFailed() { // Show a message App.BaconMan.MessageMan.ShowMessageSimple("Failed To Load", "Check your Internet connection."); // Report TelemetryManager.ReportEvent(this, "UserProfileFailedToLoad"); var wentBack = false; do { // Try to go back wentBack = _mHost.GoBack(); // Wait for a bit and try again. await Task.Delay(100); }while (wentBack); }
private void LoginButton_Click(object sender, RoutedEventArgs e) { TelemetryManager.ReportEvent(this, "LoginButtonClicked"); var loginBegin = DateTime.Now; // Change the UI //CrossfadeUi(true); // Make the call //var result = await App.BaconMan.UserMan.SignInNewUser(); _nonce = Guid.NewGuid().ToString("N"); AuthWebView.Source = new Uri(App.BaconMan.UserMan.AuthManager.GetAuthRequestString(_nonce)); AuthWebViewUi.Visibility = Visibility.Visible; //if(result.WasSuccess) //{ // TelemetryManager.ReportEvent(this, "LoginSuccess"); // TelemetryManager.ReportPerfEvent(this,"LoginTime", loginBegin); // ShowWelcomeAndLeave(); //} //else //{ // // We failed // CrossfadeUi(false); // if (result.WasErrorNetwork) // { // TelemetryManager.ReportEvent(this, "LoginFailedNetworkError"); // App.BaconMan.MessageMan.ShowMessageSimple("Check Your Connection", "We can't talk to reddit right now, check your internet connection."); // } // if(result.WasUserCanceled) // { // // Don't do anything, they know what they did. // TelemetryManager.ReportEvent(this, "LoginFailedUserCancled"); // } // else // { // App.BaconMan.MessageMan.ShowMessageSimple("Something Went Wrong", "We can't log you in right now, try again later."); // TelemetryManager.ReportUnexpectedEvent(this, "LoginFailedUnknown"); // } //} }
private void ReadingMode_Tapped(object sender, TappedRoutedEventArgs e) { // Show loading try { lock (_lockObject) { ui_readingModeLoading.Visibility = Visibility.Visible; ui_readingModeLoading.IsActive = true; ui_readingModeIconHolder.Visibility = Visibility.Collapsed; _webView.Navigate(new Uri($"http://www.readability.com/m?url={_contentPanelBase.Source.Url}", UriKind.Absolute)); } } catch (Exception ex) { TelemetryManager.ReportUnexpectedEvent(this, "FailedToNavReadingMode", ex); } TelemetryManager.ReportEvent(this, "ReadingModeEnabled"); }
public async void OnNavigatingTo() { // Set the status bar color and get the size returned. If it is not 0 use that to move the // color of the page into the status bar. var statusBarHeight = await _mHost.SetStatusBar(null, 0); ui_contentRoot.Margin = new Thickness(0, -statusBarHeight, 0, 0); ui_contentRoot.Padding = new Thickness(0, statusBarHeight, 0, 0); var package = Package.Current; var packageId = package.Id; var version = packageId.Version; ui_buildString.Text = $"Build: {version.Major}.{version.Minor}.{version.Build}.{version.Revision}"; TelemetryManager.ReportEvent(this, "AboutOpened"); // Resume snow if it was going ui_letItSnow.OkNowIWantMoreSnowIfItHasBeenStarted(); }
private void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { if (_mShareComment != null) { var commentLink = "https://reddit.com" + _post.Permalink + _mShareComment.Id; // #todo use a markdown-less body text var shareBody = _mShareComment.Body.Length > 50 ? _mShareComment.Body.Substring(0, 50) + "..." : _mShareComment.Body; args.Request.Data.Properties.ApplicationName = "Baconit"; args.Request.Data.Properties.ContentSourceWebLink = new Uri(commentLink, UriKind.Absolute); args.Request.Data.Properties.Title = "A Reddit Post Shared From Baconit"; args.Request.Data.Properties.Description = shareBody; args.Request.Data.SetText($" \r\n\r\n{shareBody}\r\n\r\n{commentLink}"); _mShareComment = null; TelemetryManager.ReportEvent(this, "CommentShared"); } else { args.Request.FailWithDisplayText("Baconit doesn't have anything to share!"); TelemetryManager.ReportUnexpectedEvent(this, "FailedToShareCommentHelperCommentNoShareComment"); } }
private async void AuthWebViewNavigationStarting(WebView sender, WebViewNavigationStartingEventArgs args) { var url = args.Uri.ToString(); var redirectPath = new Uri(AuthManager.BaconitRedirectUrl); if (args.Uri.AbsolutePath.Equals(redirectPath.AbsolutePath) && !_startingAuth) { _startingAuth = true; CrossfadeUi(true); AuthWebViewUi.Visibility = Visibility.Collapsed; var result = ParseState(url); if (!result.WasSuccess) { return; } // Try to get the access token var accessToken = await App.BaconMan.UserMan.AuthManager.RefreshAccessToken(result.Message, false); if (accessToken == null) { CrossfadeUi(false); return; } // Try to get the new user result = await App.BaconMan.UserMan.InternalUpdateUser(); if (!result.WasSuccess) { return; } TelemetryManager.ReportEvent(this, "LoginSuccess"); ShowWelcomeAndLeave(); _startingAuth = false; } }
/// <summary> /// Tries to get a youtube link from a post. If it fails /// it returns null. /// </summary> /// <param name="source"></param> /// <returns></returns> private static async Task <YouTubeVideoInfo> GetYouTubeVideoInfoAsync(ContentPanelSource source) { if (string.IsNullOrWhiteSpace(source.Url)) { return(null); } try { // Try to find the ID var youtubeVideoId = TryToGetYouTubeId(source); if (!string.IsNullOrWhiteSpace(youtubeVideoId)) { return(await YouTubeHelper.GetVideoInfoAsync(youtubeVideoId)); } } catch (Exception ex) { TelemetryManager.ReportEvent("YoutubeString", "Failed to find youtube video"); } return(null); }
/// <summary> /// Call the global content viewer to show the content. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void ContentRoot_Tapped(object sender, TappedRoutedEventArgs e) { if (!string.IsNullOrWhiteSpace(_contentPanelBase.Source.Url)) { // Try to parse out the app id if we can, loading the webpage can take a long // time so we want to avoid it if possible var successfullyParsedAppId = false; try { // We are looking to parse 9nblggh58t2h out of something like this // https://www.microsoft.com/en-us/store/apps/device-diagnostics-hub/9nblggh58t2h?cid=appraisin // or this // https://www.microsoft.com/store/apps/9wzdncrfhw68 // // Note the /apps/ changes also // Find the last / this should be just before the app id. var appIdStart = _contentPanelBase.Source.Url.LastIndexOf('/') + 1; // Make sure we found one. if (appIdStart != 0) { // Find the ending, look for a ? if there is one. var appIdEnd = _contentPanelBase.Source.Url.IndexOf('?', appIdStart); if (appIdEnd == -1) { appIdEnd = _contentPanelBase.Source.Url.Length; } // Get the app id var appId = _contentPanelBase.Source.Url.Substring(appIdStart, appIdEnd - appIdStart); // Do a quick sanity check if (appId.Length > 4) { successfullyParsedAppId = await Windows.System.Launcher.LaunchUriAsync(new Uri($"ms-windows-store://pdp/?ProductId={appId}")); } } } catch (Exception ex) { App.BaconMan.MessageMan.DebugDia("failed to parse app id", ex); TelemetryManager.ReportEvent(this, "FailedToParseAppId"); } // If we failed use the web browser if (successfullyParsedAppId) { return; } // Show our loading overlay ui_loadingOverlay.Show(); // If we have a link open it in our hidden webview, this will cause the store // to redirect us. _hiddenWebView = new WebView(WebViewExecutionMode.SeparateThread); _hiddenWebView.NavigationCompleted += HiddenWebView_NavigationCompleted; _hiddenWebView.Navigate(new Uri(_contentPanelBase.Source.Url, UriKind.Absolute)); } }
/// <summary> /// Fired when the keyboard combo is fired. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void KeyboardShortcutHepler_OnQuickSearchActivation(object sender, EventArgs e) { TelemetryManager.ReportEvent(this, "QuickSearchKeyboardShortcut"); ToggleMenu(true); SearchHeader_Tapped(null, null); }
private async void RateAndReview_Tapped(object sender, TappedRoutedEventArgs e) { await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-windows-store:reviewapp?appid=" + CurrentApp.AppId)); TelemetryManager.ReportEvent(this, "RateAndReviewTapped"); }
private void OpenBaconitSub_Tapped(object sender, TappedRoutedEventArgs e) { //#todo make this open in app when we support it OpenGlobalPresenter("http://reddit.com/r/Baconit"); TelemetryManager.ReportEvent(this, "SubredditOpened"); }
private void Facebook_Tapped(object sender, TappedRoutedEventArgs e) { OpenGlobalPresenter("http://facebook.com/Baconit"); TelemetryManager.ReportEvent(this, "FacebookOpened"); }
private void Website_Tapped(object sender, TappedRoutedEventArgs e) { OpenGlobalPresenter("http://baconit.quinndamerell.com/"); TelemetryManager.ReportEvent(this, "WebsiteOpened"); }
private void Twitter_Tapped(object sender, TappedRoutedEventArgs e) { OpenGlobalPresenter("http://twitter.com/BaconitWP"); TelemetryManager.ReportEvent(this, "TwitterOpened"); }
private void ShowSource_Tapped(object sender, TappedRoutedEventArgs e) { OpenGlobalPresenter("http://github.com/QuinnDamerell/Baconit"); TelemetryManager.ReportEvent(this, "SourceOpened"); }
/// <summary> /// Attempts to get a youtube id from a url. /// </summary> /// <param name="source"></param> /// <returns></returns> private static string TryToGetYouTubeId(ContentPanelSource source) { if (string.IsNullOrWhiteSpace(source.Url)) { return(null); } try { // Try to find the ID var youtubeVideoId = string.Empty; var urlLower = source.Url.ToLower(); if (urlLower.Contains("youtube.com")) { // Check for an attribution link var attribution = urlLower.IndexOf("attribution_link?", StringComparison.OrdinalIgnoreCase); if (attribution != -1) { // We need to parse out the video id // looks like this attribution_link?a=bhvqtDGQD6s&u=%2Fwatch%3Fv%3DrK0D1ehO7CA%26feature%3Dshare var uIndex = urlLower.IndexOf("u=", attribution, StringComparison.OrdinalIgnoreCase); var encodedUrl = source.Url.Substring(uIndex + 2); var decodedUrl = WebUtility.UrlDecode(encodedUrl); urlLower = decodedUrl.ToLower(); // At this point urlLower should be something like "v=jfkldfjl&feature=share" } var beginId = urlLower.IndexOf("v=", StringComparison.OrdinalIgnoreCase); var endId = urlLower.IndexOf("&", beginId, StringComparison.OrdinalIgnoreCase); if (beginId == -1) { return(youtubeVideoId); } if (endId == -1) { endId = urlLower.Length; } // Important! Since this might be case sensitive use the original url! beginId += 2; youtubeVideoId = source.Url.Substring(beginId, endId - beginId); } else if (urlLower.Contains("youtu.be")) { var domain = urlLower.IndexOf("youtu.be", StringComparison.OrdinalIgnoreCase); var beginId = urlLower.IndexOf("/", domain, StringComparison.OrdinalIgnoreCase); var endId = urlLower.IndexOf("?", beginId, StringComparison.OrdinalIgnoreCase); // If we can't find a ? search for a & if (endId == -1) { endId = urlLower.IndexOf("&", beginId, StringComparison.OrdinalIgnoreCase); } if (beginId == -1) { return(youtubeVideoId); } if (endId == -1) { endId = urlLower.Length; } // Important! Since this might be case sensitive use the original url! beginId++; youtubeVideoId = source.Url.Substring(beginId, endId - beginId); } return(youtubeVideoId); } catch (Exception) { TelemetryManager.ReportEvent("YoutubeString", "Failed to find youtube video"); } return(null); }