private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            // Set a flag so that, in narrow mode, details-only navigation doesn't occur if
            // the CurrentArticle is changed solely as a side-effect of changing the CurrentFeed.
            if (e.PropertyName == nameof(ViewModel.CurrentFeed))
            {
                isCurrentFeedNew = true;
            }
            else if (e.PropertyName == nameof(ViewModel.CurrentArticle))
            {
                if (ViewModel.CurrentArticle != null)
                {
                    ArticleWebView.Navigate(ViewModel.CurrentArticle.Link);
                }
                else
                {
                    ArticleWebView.NavigateToString(string.Empty);
                }

                if (AdaptiveStates.CurrentState == NarrowState)
                {
                    bool switchToDetailsView = !isCurrentFeedNew;
                    isCurrentFeedNew = false;
                    if (switchToDetailsView)
                    {
                        // Use "drill in" transition for navigating from master list to detail view
                        Frame.Navigate(typeof(DetailPage), null, new DrillInNavigationTransitionInfo());
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Populates the page with content passed during navigation. Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="sender">
        /// The source of the event; typically <see cref="NavigationHelper"/>
        /// </param>
        /// <param name="e">Event data that provides both the navigation parameter passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
        /// a dictionary of state preserved by this page during an earlier
        /// session. The state will be null the first time a page is visited.</param>
        private async void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            var url           = (string)e.NavigationParameter;
            var articleEntity = await _frontPageManager.GetArticleMetaData(url);

            ArticleWebView.NavigateToString(articleEntity.ArticleHtml);
        }
예제 #3
0
        private void Address_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            var tblk      = sender as TextBlock;
            Uri targetUri = new Uri(tblk.Text);

            ArticleWebView.Navigate(targetUri);
        }
예제 #4
0
        private async void calculateArticleHeight()
        {
            var _HeightString = await ArticleWebView.InvokeScriptAsync("eval",
                                                                       new[] { "document.body.scrollHeight.toString()" });

            double height = Window.Current.Bounds.Height;

            ArticleWebView.Height = height;
        }
예제 #5
0
        private async Task loadArticle()
        {
            //var uri = new Uri(ArticleAdressBeg + SelectedArticle.ID);

            /*var uri = new Uri(SelectedArticle.link);
             * var HttpClient = new HttpClient();
             * string resultHTML = "";
             * string finalHTML = "";
             *
             * // Always catch network exceptions for async methods
             * try
             * {
             *  resultHTML = await HttpClient.GetStringAsync(uri);
             * }
             * catch (Exception ex)
             * {
             *  // TODO
             * }
             *
             *
             * HtmlDocument htmlDoc = new HtmlDocument();
             * htmlDoc.LoadHtml(resultHTML);
             * HtmlNode node = htmlDoc.GetElementbyId("content");
             * HtmlNodeCollection nodeCollection = node.ChildNodes;
             * foreach (HtmlNode child in nodeCollection)
             * {
             *  if (child.Name.Equals("article"))
             *  {
             *      HtmlNodeCollection articleNodeCollection = child.ChildNodes;
             *      foreach (HtmlNode articleChild in articleNodeCollection)
             *      {
             *          if (articleChild.GetAttributeValue("class", "").Equals("entry-content"))
             *          {*/
            // finalHTML = articleChild.OuterHtml;

            /*HtmlNodeCollection contentNodeCollection = child.ChildNodes;
             * foreach (HtmlNode contentChild in contentNodeCollection)
             * {
             *  if (contentChild.Name.Equals("p"))
             *  {
             *      finalHTML += contentChild.OuterHtml;
             *  }
             * }*/
            /*}
             * }
             * }
             * }*/
            //this.ArticleWebView.Height = 0;
            //string finalHtml = (String)uri
            Uri uri = new Uri(ArticleAdressBeg + SelectedArticle.ID);

            ArticleWebView.Navigate(uri);
        }
예제 #6
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (ViewModel.CurrentArticle != null)
            {
                ArticleWebView.Navigate(ViewModel.CurrentArticle.Link);
            }

            // Register for hardware and software back request from the system
            SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView();

            systemNavigationManager.BackRequested += DetailPage_BackRequested;
            systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            ViewModel.IsHamburgerMenuVisible = false;
        }
예제 #7
0
        public MasterDetailPage()
        {
            InitializeComponent();

            bool isCurrentFeedNew = false;

            ViewModel.PropertyChanged += (s, e) =>
            {
                // Set a flag so that, in narrow mode, details-only navigation doesn't occur if
                // the CurrentArticle is changed solely as a side-effect of changing the CurrentFeed.
                if (e.PropertyName == nameof(ViewModel.CurrentFeed))
                {
                    isCurrentFeedNew = true;
                }
                else if (e.PropertyName == nameof(ViewModel.CurrentArticle))
                {
                    if (isCurrentFeedNew)
                    {
                        isCurrentFeedNew = false;
                        if (AdaptiveStates.CurrentState == NarrowState)
                        {
                            return;
                        }
                    }

                    if (AdaptiveStates.CurrentState == NarrowState && !isCurrentFeedNew)
                    {
                        // Use "drill in" transition for navigating from master list to detail view
                        Frame.Navigate(typeof(DetailPage), null, new DrillInNavigationTransitionInfo());
                    }
                    else
                    {
                        if (ViewModel.CurrentArticle != null)
                        {
                            ArticleWebView.Navigate(ViewModel.CurrentArticle.Link);
                        }
                        else
                        {
                            ArticleWebView.NavigateToString(string.Empty);
                        }
                        isCurrentFeedNew = false;
                        // Play a refresh animation when the user switches detail items.
                        //EnableContentTransitions();
                    }
                }
            };
        }
예제 #8
0
        private void ViewModelOnOpenWebView(string html, int id)
        {
            _currentId = id;
            var uiSettings = new Windows.UI.ViewManagement.UISettings();
            var color      = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Accent);
            var color1     = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.AccentDark2);
            var color2     = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.AccentLight2);
            var css        = Css.Replace("AccentColourBase", "#" + color.ToString().Substring(3)).
                             Replace("AccentColourLight", "#" + color2.ToString().Substring(3)).
                             Replace("AccentColourDark", "#" + color1.ToString().Substring(3))
                             .Replace("BodyBackgroundThemeColor",
                                      Settings.SelectedTheme == ApplicationTheme.Dark ? "#2d2d2d" : "#e6e6e6")
                             .Replace("BodyForegroundThemeColor",
                                      Settings.SelectedTheme == ApplicationTheme.Dark ? "white" : "black").Replace(
                "HorizontalSeparatorColor", Settings.SelectedTheme == ApplicationTheme.Dark ? "#0d0d0d" : "#b3b3b3");

            ArticleWebView.NavigateToString(css + Begin + html + "</div></body></html>");
        }
예제 #9
0
        private void ViewModelOnOpenWebView(string html, int id)
        {
            //back nav
            ViewModelLocator.NavMgr.RegisterOneTimeMainOverride(new RelayCommand(() =>
            {
                ViewModel.WebViewVisibility                = false;
                ViewModel.ArticleIndexVisibility           = true;
                ViewModelLocator.GeneralMain.CurrentStatus = ViewModel.PrevWorkMode != null &&
                                                             ViewModel.PrevWorkMode.Value == ArticlePageWorkMode.Articles
                    ? "Articles"
                    : "News";
                ViewModel.CurrentNews = -1;
            }));
            //


            ArticleWebView.NavigateToString(CssManager.WrapWithCss(html));
        }
예제 #10
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            slug             = Intent.GetIntExtra("slug", 0);
            handler          = new Handler();
            articlePresenter = new ArticlePresenter(this);

            toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);
            toolbar.SetNavigationIcon(Resource.Drawable.back_24dp);
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            toolbar.SetNavigationOnClickListener(this);
            toolbar.SetOnMenuItemClickListener(this);

            coordinatorLayout = FindViewById <CoordinatorLayout>(Resource.Id.main_content);
            collapsingToolbar = FindViewById <CollapsingToolbarLayout>(Resource.Id.collapsingtoolbar);

            appbar = FindViewById <AppBarLayout>(Resource.Id.appbar);
            appbar.AddOnOffsetChangedListener(this);

            swipeRefreshLayout = FindViewById <SwipeRefreshLayout>(Resource.Id.swipeRefreshLayout);
            swipeRefreshLayout.SetColorSchemeResources(Resource.Color.primary);
            swipeRefreshLayout.SetOnRefreshListener(this);
            scrollView = FindViewById <NestedScrollView>(Resource.Id.scrollView);
            scrollView.ViewTreeObserver.AddOnScrollChangedListener(this);

            toolbarTitle   = FindViewById <TextView>(Resource.Id.toolbarTitle);
            titleImage     = FindViewById <ImageView>(Resource.Id.titleImage);
            imgAvatar      = FindViewById <ImageViewAsync>(Resource.Id.llAvatar);
            org            = FindViewById <ImageView>(Resource.Id.org);
            txtAuthor      = FindViewById <TextView>(Resource.Id.txtAuthor);
            txtTitle       = FindViewById <TextView>(Resource.Id.txtTitle);
            txtBio         = FindViewById <TextView>(Resource.Id.txtBio);
            articleContent = FindViewById <ArticleWebView>(Resource.Id.postContent);
            txtTime        = FindViewById <TextView>(Resource.Id.txtTime);
            txtGood        = FindViewById <TextView>(Resource.Id.txtGood);
            txtComments    = FindViewById <TextView>(Resource.Id.txtComments);

            swipeRefreshLayout.Post(async() =>
            {
                await articlePresenter.GetClientArticle(slug);
            });
        }
예제 #11
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            dataTranferManager.DataRequested += DataTransferManager_DataRequested;

            if (ViewModel.CurrentArticle != null)
            {
                if (ViewModel.CurrentArticle.Link?.WithoutScheme() != ArticleWebView.Source?.WithoutScheme())
                {
                    ArticleWebView.Navigate(ViewModel.CurrentArticle.Link);
                }
                else
                {
                    ArticleWebView.Visibility = Visibility.Visible;
                }
            }

            var backStack      = Frame.BackStack;
            var backStackCount = backStack.Count;

            if (backStackCount > 0)
            {
                var masterPageEntry = backStack[backStackCount - 1];
                backStack.RemoveAt(backStackCount - 1);

                // Clear the navigation parameter so that navigation back to the
                // MasterDetail page won't reset the current article selection.
                var modifiedEntry = new PageStackEntry(
                    masterPageEntry.SourcePageType,
                    null,
                    masterPageEntry.NavigationTransitionInfo
                    );
                backStack.Add(modifiedEntry);
            }

            // Register for hardware and software back request from the system
            SystemNavigationManager systemNavigationManager = SystemNavigationManager.GetForCurrentView();

            systemNavigationManager.BackRequested += DetailPage_BackRequested;
            systemNavigationManager.AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible;
            ViewModel.IsInDetailsMode = true;
        }
예제 #12
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (e.Parameter is Uri || e.Parameter == null ||
                (e.Parameter is string && String.IsNullOrEmpty(e.Parameter as string)))
            {
                if (MasterFrame.CurrentSourcePageType != typeof(FeedView))
                {
                    MasterFrame.Navigate(typeof(FeedView));
                }

                var feedUri = e.Parameter as Uri;
                if (feedUri != null)
                {
                    var feed = ViewModel.Feeds.FirstOrDefault(f => f.Link == feedUri);
                    ViewModel.CurrentFeed = feed;
                    await feed.RefreshAsync();

                    var article = feed.Articles.FirstOrDefault();
                    if (article != null)
                    {
                        ViewModel.CurrentArticle = article;
                        ArticleWebView.Navigate(article.Link);
                    }
                }
            }
            else
            {
                var viewType = e.Parameter as Type;

                if (viewType != null && MasterFrame.CurrentSourcePageType != viewType)
                {
                    MasterFrame.Navigate(viewType);
                }

                UpdateForVisualState(AdaptiveStates.CurrentState);
            }
        }
예제 #13
0
        private void ViewModelOnOpenWebView(string html, MalNewsUnitModel item)
        {
            //BackNav
            ViewModelLocator.NavMgr.RegisterBackNav(PageIndex.PageArticles,
                                                    item.Type == MalNewsType.Article
                    ? MalArticlesPageNavigationArgs.Articles
                    : MalArticlesPageNavigationArgs.News);
            //
            _currentId = ViewModel.Articles.IndexOf(item);
            var uiSettings = new Windows.UI.ViewManagement.UISettings();
            var color      = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Accent);
            var color1     = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.AccentDark2);
            var color2     = uiSettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.AccentLight2);
            var css        = Css.Replace("AccentColourBase", "#" + color.ToString().Substring(3)).
                             Replace("AccentColourLight", "#" + color2.ToString().Substring(3)).
                             Replace("AccentColourDark", "#" + color1.ToString().Substring(3))
                             .Replace("BodyBackgroundThemeColor",
                                      Settings.SelectedTheme == (int)ApplicationTheme.Dark ? "#2d2d2d" : "#e6e6e6")
                             .Replace("BodyForegroundThemeColor",
                                      Settings.SelectedTheme == (int)ApplicationTheme.Dark ? "white" : "black").Replace(
                "HorizontalSeparatorColor", Settings.SelectedTheme == (int)ApplicationTheme.Dark ? "#0d0d0d" : "#b3b3b3");

            ArticleWebView.NavigateToString(css + Begin + html + "</div></body></html>");
        }
예제 #14
0
 protected override void OnNavigatedFrom(NavigationEventArgs e)
 {
     NavMgr.ResetBackNav();
     ArticleWebView.NavigateToString("");
     base.OnNavigatedFrom(e);
 }