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); } }
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); }
public async void LinkAnalyze(string url) { var link = PublicationContentUtil.Instance.BuildHyperLink(Publication.BookId, url); if (link is IntraHyperlink)//current book { var intralink = link as IntraHyperlink; NavigationRecord record = new NavigationRecord { BookId = Publication.BookId, TOCId = intralink.TOCID, Type = NavigationType.IntraLink, Tag = intralink.Refpt }; await RestoreToc(record, TOCAccessMode.All); } else if (link is InternalHyperlink)//other books { var internallink = link as InternalHyperlink; NavigationRecord record = new NavigationRecord { BookId = internallink.BookID, TOCId = internallink.TOCID, Type = NavigationType.InternalLink, Tag = internallink.Refpt }; await RestoreToc(record, TOCAccessMode.All); } else if (link is ExternalHyperlink) { var exterlink = link as ExternalHyperlink; await Windows.System.Launcher.LaunchUriAsync(new Uri(exterlink.Url)); } else if (link is AttachmentHyperlink) { var attachlink = link as AttachmentHyperlink; try { var file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(attachlink.TargetFileName); if (file != null) { var options = new Windows.System.LauncherOptions(); options.PreferredApplicationDisplayName = file.DisplayType; options.PreferredApplicationPackageFamilyName = file.ContentType; await Windows.System.Launcher.LaunchFileAsync(file, options); } } catch { //TODO:log } } }
public async void GotoPage(SearchPageModel result) { var record = new NavigationRecord { BookId = Publication.BookId, TOCId = result.TOCID, Type = NavigationType.PBO, PageNum = result.PageNum }; await RestoreToc(record, TOCAccessMode.All); }
public async Task SearchResultToToc(SearchResultModel result) { var record = new NavigationRecord { BookId = Publication.BookId, TOCId = result.TocId, Type = NavigationType.Search, Tag = result }; await RestoreToc(record, TOCAccessMode.All); }
public async Task RecentHistoryToTOC(RecentHistoryItem recentHistoryItem) { int TOCId = await PublicationContentUtil.Instance.GetTOCIDByDocId(recentHistoryItem.BookId, recentHistoryItem.DOCID); var record = new NavigationRecord { BookId = recentHistoryItem.BookId, TOCId = TOCId, Type = NavigationType.History }; await RestoreToc(record, TOCAccessMode.All); }
private async Task InitialContent(string[] paramList, NavigationMode navigationMode) { #region PBO Search IsPBO = await PageSearchUtil.Instance.IsPBO(Publication.BookId); #endregion #region toc initial root = await PublicationUtil.Instance.GetDlBookTOC(Publication.BookId); listAll = root.ChildNodes; firstNode = null; GetFirstTocNode(listAll, ref firstNode); NavigationRecord record = new NavigationRecord { BookId = Publication.BookId, TOCId = firstNode.ID, Type = NavigationType.TOCDocument }; var nodes = await InitialBreadcrumMenu(record, TOCAccessMode.All); BreadcrumbNavigator = new ObservableCollection <BreadcrumbNav>(nodes); #endregion if (navigationMode == NavigationMode.New) { #region index initial var indexs = await InitialIndexMenu(Publication.BookId); IndexMenuCollections = new ObservableCollection <IndexMenuItem>(indexs); HasIndex = IndexMenuCollections == null || IndexMenuCollections.Count == 0 ? false : true; #endregion #region tag var tags = AnnCategoryTagUtil.Instance.GetTags(); var tagList = tags.Select(tag => new TagItem { Tag = tag, IsCheck = false }); TagCollections = new ObservableCollection <TagItem>(tagList); #endregion } }
private async void ScriptNotify(object sender, NotifyEventArgs e) { var notify = JsonConvert.DeserializeObject <NotifytModel>(e.Value); var contentPageViewModel = DataContext as ContentPageViewModel; switch (notify.Type) { case "POSITION": ContentMenuPosition = HtmlHelper.ConvertToPoint(notify.Value1, notify.Value2); break; case "SELECTED": string text = notify.Value1; SelectContent = SearchTools.RemoveBlank(text); double PaddingLeft = LeftSidePanelGrid.Visibility == Visibility.Visible ? 368 : 48; ContextMenuInitial(ContentMenuPosition, PaddingLeft); break; case "INFINITE": if (Navigating) { return; } await Task.Run(() => { Navigating = true; }); WebView webView = sender as WebView; switch (notify.Value1) { case "UP": var last = contentPageViewModel.GetBackwardNode(); if (last == null) { break; } contentPageViewModel.LoadingContent(last.Title, RollingDirection.Up); await InvokeScript(webView, "loadingupvisible();"); string backwardContent = await contentPageViewModel.GoBackWardContent(last); var recordUP = new NavigationRecord { TOCId = last.ID, Type = NavigationType.TOCDocument }; backwardContent = await HtmlHelper.PageSplit(backwardContent, recordUP); string jsonUp = JsonConvert.SerializeObject(new { content = backwardContent, selector = string.Format("#tocId{0}", last.ID) }); await InvokeScript(webView, "AppendHtml_Top(" + jsonUp + ");"); contentPageViewModel.LoadingCompleted(); await InvokeScript(webView, string.Format("ListenHref('#tocId{0} a');", last.ID)); break; case "DOWN": var next = contentPageViewModel.GetForwardNode(); if (next == null) { break; } contentPageViewModel.LoadingContent(next.Title, RollingDirection.Down); await InvokeScript(webView, "loadingdownvisible();"); string forwardContent = await contentPageViewModel.GoForWardContent(next); var recordDown = new NavigationRecord { TOCId = next.ID, Type = NavigationType.TOCDocument }; forwardContent = await HtmlHelper.PageSplit(forwardContent, recordDown); string jsonDowm = JsonConvert.SerializeObject(new { content = forwardContent, selector = string.Format("#tocId{0}", next.ID) }); await InvokeScript(webView, "AppendHtml_Bottom(" + jsonDowm + ");"); contentPageViewModel.LoadingCompleted(); await InvokeScript(webView, string.Format("ListenHref('#tocId{0} a');", next.ID)); break; } //avoid scroll event hannpens twice Task.Run(() => { using (ManualResetEvent manualResetEvent = new ManualResetEvent(false)) { manualResetEvent.WaitOne(1000); Navigating = false; } }); break; case "SCROLL": int tocId = int.Parse(notify.Value1.Substring(5)); await contentPageViewModel.ResetTocByScroll(tocId); break; case "HREF": if (notify.Value1.StartsWith("about:")) { notify.Value1 = notify.Value1.Replace("about:", "http://"); } contentPageViewModel.LinkAnalyze(notify.Value1); break; case "PBO": string pageNum = notify.Value1; contentPageViewModel.PageNum = "Page " + pageNum; break; case "COUNTRYCODE": break; } }
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); }
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 }; }