コード例 #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();
        }