Example #1
0
        public void OpenContentPage()
        {
            if (IsHidden)
            {
                // This fragment is hidden, need not open page
                return;
            }

            if (wvContent == null ||            // WebView does not requested
                DataCache.INSTATNCE.Toc == null // Toc has not been retrieved
                )
            {
                return;
            }



            var pub = ((ContentActivity)Activity).Publication;

            if (!DataCache.INSTATNCE.Toc.IsCurrentPublication(pub.Value.BookId))
            {
                // The toc is not belong to current publication
                return;
            }

            var tocNode = DataCache.INSTATNCE.Toc.ShowingLeafNode;
            var tag     = wvContent.Tag as JavaObjWrapper <WebViewTag>;

            if (tag != null && tag.Value.IsCurrentTOC(pub.Value.BookId, tocNode.ID))
            {
                /*
                 *              wvContent.Tag = new JavaObjWrapper<WebViewTag>(
                 *                      WebViewTag.CreateWebViewTagByTOC(
                 *                              pub.Value.BookId,
                 *                              tocNode.ID));
                 */

                ((ContentActivity)Activity).ClosePleaseWaitPageLoadDialog();
                UpdateNavigationIcon();

                if (!tag.Value.IsCurrentNavigationItem())
                {
                    wvContent.LoadUrl("javascript:android.red.applyHighLight();android.red.scrollByNavigation();");
                    tag.Value.BindNavigationItem();

                    if (((ContentActivity)Activity).IsPbo())
                    {
                        var pboPageItem = AsyncHelpers.RunSync <PageItem>(
                            () => PageSearchUtil.Instance.GetFirstPageItem(pub.Value.BookId, tocNode.ID));
                        currentPboPage = pboPageItem != null?pboPageItem.Identifier.ToString() : null;
                    }

                    //UpdatePboPage();
                }

                return;
            }

            var result = AsyncHelpers.RunSync <string>(
                () => PublicationContentUtil.Instance.GetContentFromTOC(pub.Value.BookId, tocNode, true, false));

            //result = SlideToc(result);

            // Only large content need show wait dialog
            if (result.Length > WebViewManager.ShowWaitContentMinLength ||
                WebViewManager.CountATag(result) > WebViewManager.ShowWaitMinATagCount)
            {
                ((ContentActivity)Activity).ShowPleaseWaitDialog();
                Task.Run(() =>
                {
                    Thread.Sleep(100);

                    result = PublicationContentUtil.Instance.RenderHyperLink(result, pub.Value.BookId);
                    result = "<div id='toc_" + tocNode.ID + "' class='tocpagediv' >" + result + "</div>";

                    Application.SynchronizationContext.Post(_ =>
                    {
                        tag = new JavaObjWrapper <WebViewTag>(
                            WebViewTag.CreateWebViewTagByTOC(
                                pub.Value.BookId,
                                tocNode.ID));
                        tag.Value.BindNavigationItem();
                        wvContent.Tag = tag;

                        wvContent.LoadDataWithBaseURL(
                            "file:///android_asset/html/",
                            WebViewManager.Instance.ApplyTemplate(WebViewManager.WebViewType.Content, result),
                            "text/html",
                            "utf-8",
                            null);

                        if (((ContentActivity)Activity).IsPbo())
                        {
                            var pboPageItem = AsyncHelpers.RunSync <PageItem>(
                                () => PageSearchUtil.Instance.GetFirstPageItem(pub.Value.BookId, tocNode.ID));
                            currentPboPage = pboPageItem != null ? pboPageItem.Identifier.ToString() : null;
                        }

                        UpdatePboPage();
                        UpdateNavigationIcon();
                    }, null);
                });

                return;
            }

            //result = PublicationContentUtil.Instance.RenderHyperLink(result, pub.Value.BookId);
            //result = "<div id='toc_" + tocNode.ID + "' class='tocpagediv' >" + result + "</div>";



            //DumpToc(pub.Value.BookId, tocNode.ID, WebViewManager.Instance.ApplyTemplate(WebViewManager.WebViewType.Content, result));

            //tag = new JavaObjWrapper<WebViewTag>(
            //    WebViewTag.CreateWebViewTagByTOC(
            //        pub.Value.BookId,
            //        tocNode.ID));
            //tag.Value.BindNavigationItem();
            //wvContent.Tag = tag;

            //wvContent.LoadDataWithBaseURL(
            //    "file:///android_asset/html/",
            //    WebViewManager.Instance.ApplyTemplate(WebViewManager.WebViewType.Content, result),
            //    "text/html",
            //    "utf-8",
            //    null);

            //if (((ContentActivity)Activity).IsPbo())
            //{
            //    var pboPageItem = AsyncHelpers.RunSync<PageItem>(
            //        () => PageSearchUtil.Instance.GetFirstPageItem(pub.Value.BookId, tocNode.ID));
            //    currentPboPage = pboPageItem != null ? pboPageItem.Identifier.ToString() : null;
            //}

            //UpdatePboPage();
            //UpdateNavigationIcon();
        }
        public void OpenIndexPage()
        {
            if (IsHidden)
            {
                // This fragment is hidden, need not open page
                return;
            }

            if (wvContent == null ||                  // WebView does not requested
                DataCache.INSTATNCE.IndexList == null // Index has not been retrieved
                )
            {
                return;
            }

            var selectedIndex = DataCache.INSTATNCE.IndexList.GetCurrentIndex();

            if (selectedIndex == null)
            {
                tvLeftTopIndex.Text = " ";
            }
            else
            {
                tvLeftTopIndex.Text = selectedIndex.Title.Substring(0, 1);
            }

            SetNoIndexStatus();

            if (selectedIndex == null)
            {
                wvContent.Tag = null;
                wvContent.LoadData("", "text/html", "utf-8");
                ((ContentActivity)Activity).ClosePleaseWaitPageLoadDialog();
                return;
            }

            // Open Page
            var pub = ((ContentActivity)Activity).Publication;
            var tag = wvContent.Tag as JavaObjWrapper <WebViewTag>;

            if (tag != null && tag.Value.IsSameIndexPage(pub.Value.BookId, selectedIndex.Title))
            {
                ((ContentActivity)Activity).ClosePleaseWaitPageLoadDialog();
                wvContent.LoadUrl("javascript:android.red.scrollByIndex();");
                return;
            }

            var result = AsyncHelpers.RunSync <string>(
                () => PublicationContentUtil.Instance.GetContentFromIndex(pub.Value.BookId, selectedIndex, false));

            //DumpToc(pub.Value.BookId, selectedIndex.Title, result);

            // Only large content need show wait dialog
            if (result.Length > WebViewManager.ShowWaitContentMinLength ||
                WebViewManager.CountATag(result) > WebViewManager.ShowWaitMinATagCount)
            {
                ((ContentActivity)Activity).ShowPleaseWaitDialog();

                Task.Run(() =>
                {
                    Thread.Sleep(100);

                    result = PublicationContentUtil.Instance.RenderHyperLink(result, pub.Value.BookId);

                    Application.SynchronizationContext.Post(_ => {
                        wvContent.LoadDataWithBaseURL(
                            "file:///android_asset/html/",
                            WebViewManager.Instance.ApplyTemplate(WebViewManager.WebViewType.Index, result),
                            "text/html",
                            "utf-8",
                            null);
                        wvContent.Tag = new JavaObjWrapper <WebViewTag>(WebViewTag.CreateWebViewTagByIndex(pub.Value.BookId, selectedIndex.Title));
                    }, null);
                });

                return;
            }

            result = PublicationContentUtil.Instance.RenderHyperLink(result, pub.Value.BookId);

            wvContent.LoadDataWithBaseURL(
                "file:///android_asset/html/",
                WebViewManager.Instance.ApplyTemplate(WebViewManager.WebViewType.Index, result),
                "text/html",
                "utf-8",
                null);
            wvContent.Tag = new JavaObjWrapper <WebViewTag>(WebViewTag.CreateWebViewTagByIndex(pub.Value.BookId, selectedIndex.Title));
        }