コード例 #1
0
        /// <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");
        }
コード例 #2
0
        /// <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");
        }
コード例 #3
0
        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");
        }
コード例 #4
0
 private void Post_Holding(object sender, HoldingRoutedEventArgs e)
 {
     if (sender is FrameworkElement element)
     {
         FlyoutBase.ShowAttachedFlyout(element);
     }
     TelemetryManager.ReportEvent(this, "PostHeldOpenedContextMenu");
 }
コード例 #5
0
 private void Post_RightTapped(object sender, RightTappedRoutedEventArgs e)
 {
     if (sender is FrameworkElement element)
     {
         FlyoutBase.ShowAttachedFlyout(element);
     }
     TelemetryManager.ReportEvent(this, "RightClickedOpenedContextMenu");
 }
コード例 #6
0
ファイル: MainPage.xaml.cs プロジェクト: wrhighfield/Baconit
        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");
        }
コード例 #7
0
        /// <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");
        }
コード例 #8
0
ファイル: MainPage.xaml.cs プロジェクト: wrhighfield/Baconit
 /// <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);
 }
コード例 #9
0
        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");
        }
コード例 #10
0
        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;
        }
コード例 #11
0
        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");
        }
コード例 #12
0
ファイル: MainPage.xaml.cs プロジェクト: wrhighfield/Baconit
 /// <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);
     }
 }
コード例 #13
0
        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}";
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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");
            //    }
            //}
        }
コード例 #16
0
        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");
        }
コード例 #17
0
        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();
        }
コード例 #18
0
 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");
     }
 }
コード例 #19
0
        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;
            }
        }
コード例 #20
0
        /// <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);
        }
コード例 #21
0
        /// <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));
            }
        }
コード例 #22
0
ファイル: MainPage.xaml.cs プロジェクト: wrhighfield/Baconit
 /// <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);
 }
コード例 #23
0
        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");
        }
コード例 #24
0
 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");
 }
コード例 #25
0
 private void Facebook_Tapped(object sender, TappedRoutedEventArgs e)
 {
     OpenGlobalPresenter("http://facebook.com/Baconit");
     TelemetryManager.ReportEvent(this, "FacebookOpened");
 }
コード例 #26
0
 private void Website_Tapped(object sender, TappedRoutedEventArgs e)
 {
     OpenGlobalPresenter("http://baconit.quinndamerell.com/");
     TelemetryManager.ReportEvent(this, "WebsiteOpened");
 }
コード例 #27
0
 private void Twitter_Tapped(object sender, TappedRoutedEventArgs e)
 {
     OpenGlobalPresenter("http://twitter.com/BaconitWP");
     TelemetryManager.ReportEvent(this, "TwitterOpened");
 }
コード例 #28
0
 private void ShowSource_Tapped(object sender, TappedRoutedEventArgs e)
 {
     OpenGlobalPresenter("http://github.com/QuinnDamerell/Baconit");
     TelemetryManager.ReportEvent(this, "SourceOpened");
 }
コード例 #29
0
        /// <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&amp;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);
        }