Exemple #1
0
        public async Task ResetTocByScroll(int tocId)
        {
            var record = new NavigationRecord
            {
                BookId = Publication.BookId,
                TOCId  = tocId,
                Type   = NavigationType.TOCDocument
            };

            if (CurrentTocNode.ID == tocId)
            {
                await RestoreToc(record, TOCAccessMode.NoReload);

                return;
            }

            if (IsSameParent(CurrentTocNode.ID, tocId))
            {
                foreach (var breadcrumb in BreadcrumbNavigator)
                {
                    breadcrumb.IsHighLight = breadcrumb.ID == tocId;
                }
                CurrentTocNode = new TocCurrentNode
                {
                    ID   = tocId,
                    Role = NodeExpandStatue.Leaf
                };
            }
            else
            {
                await RestoreToc(record, TOCAccessMode.NoReload);
            }
        }
Exemple #2
0
        private async Task RestoreToc(NavigationRecord record, TOCAccessMode mode)
        {
            if (record.BookId != Publication.BookId)
            {
                var publications = SessionService.SessionState[ALL_PUBLICATIONS_SESSION_KEY] as List <PublicationViewModel>;
                Publication = publications.FirstOrDefault(x => x.BookId == record.BookId);
                root        = await PublicationUtil.Instance.GetDlBookTOC(Publication.BookId);

                listAll   = root.ChildNodes;
                firstNode = null;
                GetFirstTocNode(listAll, ref firstNode);
                var indexs = await InitialIndexMenu(Publication.BookId);

                IndexMenuCollections = new ObservableCollection <IndexMenuItem>(indexs);
                HasIndex             = IndexMenuCollections == null || IndexMenuCollections.Count == 0 ? false : true;
                Keywords             = string.Empty;
                IsPBO = await PageSearchUtil.Instance.IsPBO(Publication.BookId);
            }
            CurrentTocNode = new TocCurrentNode
            {
                ID   = record.TOCId,
                Role = NodeExpandStatue.Leaf
            };
            var nodes = await InitialBreadcrumMenu(record, mode);

            BreadcrumbNavigator = new ObservableCollection <BreadcrumbNav>(nodes);
        }
Exemple #3
0
        public override async void OnNavigatedTo(object navigationParameter, NavigationMode navigationMode, Dictionary <string, object> viewModelState)
        {
            base.OnNavigatedTo(navigationParameter, navigationMode, viewModelState);
            if (navigationParameter != null)
            {
                string   param     = navigationParameter.ToString();
                string[] paramList = param.Split('|');

                var bookId = int.Parse(paramList[0]);
                if (SessionService.SessionState.ContainsKey(ALL_PUBLICATIONS_SESSION_KEY))
                {
                    var publications =
                        SessionService.SessionState[ALL_PUBLICATIONS_SESSION_KEY] as List <PublicationViewModel>;

                    Publication = publications.FirstOrDefault(x => x.BookId == bookId);
                }
                if (navigationMode == NavigationMode.New)
                {
                    HistoryNavigator = new NavigationRecordManager();
                    if (paramList.Length > 1)
                    {
                        CurrentTocNode = new TocCurrentNode
                        {
                            ID   = int.Parse(paramList[1]),
                            Role = NodeExpandStatue.Leaf
                        };
                    }
                }
                await InitialContent(paramList, navigationMode);
            }
        }
Exemple #4
0
        private async Task <List <BreadcrumbNav> > InitialBreadcrumMenu(NavigationRecord record, TOCAccessMode mode)
        {
            List <BreadcrumbNav> selectedBreadcrumbNavs = null;

            //restore toc and get content
            if (CurrentTocNode != null && CurrentTocNode.ID != 0)
            {
                List <TOCNode> selectedNodes = new List <TOCNode>();
                TOCNode        tocNode       = null;
                GetTocNodeByID(listAll, ref tocNode, CurrentTocNode.ID);

                if (CurrentTocNode.Role == NodeExpandStatue.Leaf)
                {
                    switch (mode)
                    {
                    case TOCAccessMode.All:
                        var content1 = await PublicationContentUtil.Instance.GetContentFromTOC(record.BookId, tocNode);

                        ChangeTocContent(await HtmlHelper.PageSplit(content1, record), record.TOCId);
                        HistoryNavigator.Record(Publication.BookId, tocNode.ID, record.Type, record.PageNum, record.Tag);
                        break;

                    case TOCAccessMode.IgnoreHistory:
                        var content2 = await PublicationContentUtil.Instance.GetContentFromTOC(record.BookId, tocNode, false);

                        ChangeTocContent(await HtmlHelper.PageSplit(content2, record), record.TOCId);
                        break;

                    case TOCAccessMode.NoReload:
                        break;
                    }
                    CurrentLevel = tocNode.NodeLevel - 1;
                }
                else if (CurrentTocNode.Role == NodeExpandStatue.Expand)
                {
                    CurrentLevel = tocNode.NodeLevel;
                }
                else if (CurrentTocNode.Role == NodeExpandStatue.Collapse)
                {
                    CurrentLevel = tocNode.NodeLevel - 1;
                }
                //add parent
                TOCNode tempNode = tocNode.ParentNode;
                while (tempNode != null && tempNode.NodeLevel > 0)
                {
                    selectedNodes.Insert(0, tempNode);
                    tempNode = tempNode.ParentNode;
                }

                //add me and children
                if (CurrentTocNode.Role == NodeExpandStatue.Expand)
                {
                    selectedNodes.Add(tocNode);
                    selectedNodes.AddRange(tocNode.ChildNodes);
                }
                else
                {
                    selectedNodes.AddRange(tocNode.ParentNode.ChildNodes);
                }

                selectedBreadcrumbNavs = selectedNodes.Select(node => new BreadcrumbNav
                {
                    ID             = node.ID,
                    Title          = node.Title,
                    GuideCardTitle = node.GuideCardTitle,
                    Role           = node.Role,
                    NodeLevel      = node.NodeLevel,
                    ChildNodes     = node.ChildNodes,
                    ParentId       = node.ParentId,
                    ParentNode     = node.ParentNode,
                    Icon           = node.Role == Constants.ANCESTOR ? (node.NodeLevel > CurrentLevel ? COLLAPSED_ICON : EXPAND_ICON) : LEAF_NODE_ICON,
                    IsHighLight    = node.ID == CurrentTocNode.ID
                }).ToList <BreadcrumbNav>();
            }
            else
            {
                CurrentTocNode = new TocCurrentNode
                {
                    ID   = record.TOCId,
                    Role = NodeExpandStatue.Leaf
                };
                CurrentLevel = 0;
                var content = await PublicationContentUtil.Instance.GetContentFromTOC(record.BookId, firstNode);

                ChangeTocContent(await HtmlHelper.PageSplit(content, record), record.TOCId);
                HistoryNavigator.Record(Publication.BookId, record.TOCId, record.Type, record.PageNum, record.Tag);
                selectedBreadcrumbNavs = listAll.Select(node => new BreadcrumbNav
                {
                    ID             = node.ID,
                    Title          = node.Title,
                    GuideCardTitle = node.GuideCardTitle,
                    Role           = node.Role,
                    NodeLevel      = node.NodeLevel,
                    ChildNodes     = node.ChildNodes,
                    ParentId       = node.ParentId,
                    ParentNode     = root,
                    Icon           = node.Role == Constants.ANCESTOR ? COLLAPSED_ICON : LEAF_NODE_ICON,
                    IsHighLight    = false
                }).ToList();
                selectedBreadcrumbNavs[0].IsHighLight = true;
            }
            selectedBreadcrumbNavs.Insert(0, new BreadcrumbNav
            {
                ID         = 0,
                Title      = "Table of Contents",
                NodeLevel  = 0,
                ChildNodes = root.ChildNodes
            });
            return(selectedBreadcrumbNavs);
        }
Exemple #5
0
        public async Task BreadcrumItemExpandStatueChange(BreadcrumbNav selectedNode)
        {
            NodeExpandStatue selectedNodeStatue = NodeExpandStatue.Leaf;

            if (selectedNode.NodeLevel == 0)
            {
                if (CurrentLevel > 0)
                {
                    selectedNodeStatue = NodeExpandStatue.Collapse;

                    List <BreadcrumbNav> bindingBreadcrumbNavigator = new List <BreadcrumbNav>();
                    bindingBreadcrumbNavigator.Add(BreadcrumbNavigator[0]);
                    int tocID = BreadcrumbNavigator[1].ID;
                    bindingBreadcrumbNavigator.AddRange(selectedNode.ChildNodes.Select(node => new BreadcrumbNav
                    {
                        ID             = node.ID,
                        Title          = node.Title,
                        GuideCardTitle = node.GuideCardTitle,
                        Role           = node.Role,
                        NodeLevel      = node.NodeLevel,
                        ChildNodes     = node.ChildNodes,
                        ParentId       = node.ParentId,
                        ParentNode     = node.ParentNode,
                        Icon           = node.Role == Constants.ANCESTOR ? COLLAPSED_ICON : LEAF_NODE_ICON,
                        IsHighLight    = tocID == node.ID
                    }));
                    //reset selected node after tapped toc header
                    selectedNode        = bindingBreadcrumbNavigator.First(node => node.ID == tocID);
                    BreadcrumbNavigator = new ObservableCollection <BreadcrumbNav>(bindingBreadcrumbNavigator);
                    CurrentLevel        = 0;
                }
            }
            else if (selectedNode.Role == Constants.ANCESTOR)
            {
                List <BreadcrumbNav> bindingBreadcrumbNavigator = BreadcrumbNavigator.ToList();
                // expand
                if (selectedNode.NodeLevel > CurrentLevel)
                {
                    selectedNodeStatue = NodeExpandStatue.Expand;

                    bindingBreadcrumbNavigator.RemoveAll(n => n.NodeLevel == selectedNode.NodeLevel && n.ID != selectedNode.ID);
                    selectedNode.Icon        = EXPAND_ICON;
                    selectedNode.IsHighLight = true;
                    if (selectedNode.ChildNodes != null)
                    {
                        bindingBreadcrumbNavigator.AddRange(
                            selectedNode.ChildNodes.Select(node => new BreadcrumbNav
                        {
                            ID             = node.ID,
                            Title          = node.Title,
                            GuideCardTitle = node.GuideCardTitle,
                            Role           = node.Role,
                            NodeLevel      = node.NodeLevel,
                            ChildNodes     = node.ChildNodes,
                            ParentId       = node.ParentId,
                            ParentNode     = node.ParentNode,
                            Icon           = node.Role == Constants.ANCESTOR ? COLLAPSED_ICON : LEAF_NODE_ICON
                        }));
                    }
                    foreach (var breadcrumb in bindingBreadcrumbNavigator)
                    {
                        breadcrumb.IsHighLight = breadcrumb.ID == selectedNode.ID;
                    }
                    BreadcrumbNavigator = new ObservableCollection <BreadcrumbNav>(bindingBreadcrumbNavigator);
                    CurrentLevel        = selectedNode.NodeLevel;
                }
                //collapse
                else if (selectedNode.NodeLevel <= CurrentLevel)
                {
                    selectedNodeStatue = NodeExpandStatue.Collapse;

                    bindingBreadcrumbNavigator.RemoveAll(n => n.NodeLevel >= selectedNode.NodeLevel);
                    bindingBreadcrumbNavigator.AddRange(
                        selectedNode.ParentNode.ChildNodes.Select(node => new BreadcrumbNav
                    {
                        ID             = node.ID,
                        Title          = node.Title,
                        GuideCardTitle = node.GuideCardTitle,
                        Role           = node.Role,
                        NodeLevel      = node.NodeLevel,
                        ChildNodes     = node.ChildNodes,
                        ParentId       = node.ParentId,
                        ParentNode     = node.ParentNode,
                        Icon           = node.Role == Constants.ANCESTOR ? COLLAPSED_ICON : LEAF_NODE_ICON
                    }));
                    foreach (var breadcrumb in bindingBreadcrumbNavigator)
                    {
                        breadcrumb.IsHighLight = breadcrumb.ID == selectedNode.ID;
                    }
                    BreadcrumbNavigator = new ObservableCollection <BreadcrumbNav>(bindingBreadcrumbNavigator);
                    CurrentLevel        = selectedNode.NodeLevel - 1;
                }
            }
            else//open doc content
            {
                foreach (var breadcrumb in BreadcrumbNavigator)
                {
                    breadcrumb.IsHighLight = breadcrumb.ID == selectedNode.ID;
                }
                if (selectedNode.ID == CurrentTocNode.ID)
                {
                    return;
                }
                var content = await PublicationContentUtil.Instance.GetContentFromTOC(Publication.BookId, new TOCNode
                {
                    ID             = selectedNode.ID,
                    Title          = selectedNode.Title,
                    ParentId       = selectedNode.ParentId,
                    NodeLevel      = selectedNode.NodeLevel,
                    GuideCardTitle = selectedNode.GuideCardTitle,
                    Role           = selectedNode.Role,
                    ChildNodes     = selectedNode.ChildNodes
                });

                var record = new NavigationRecord
                {
                    TOCId = selectedNode.ID,
                    Type  = NavigationType.TOCDocument
                };

                ChangeTocContent(await HtmlHelper.PageSplit(content, record), record.TOCId);
                CurrentLevel = selectedNode.NodeLevel - 1;
                HistoryNavigator.Record(Publication.BookId, selectedNode.ID);
            }

            CurrentTocNode = new TocCurrentNode
            {
                ID   = selectedNode.ID,
                Role = selectedNodeStatue
            };
        }