Exemple #1
0
        public bool DisplayBook(NavigateControlId id, BookData bookData, BookLocation location = null)
        {
            if (MainBookHandler == null)
            {
                return(false);
            }

            // Is the book actually downloaded?
            if (bookData.DownloadData == null || bookData.DownloadData.CurrFileStatus != DownloadData.FileStatus.Downloaded)
            {
                // TODO: download the book
                return(false);
            }

            MainBookHandler.DisplayBook(bookData, location);
            foreach (var item in SimpleBookHandlers)
            {
                // No hairpin selects
                if (item.Key != id)
                {
                    item.Value.DisplayBook(bookData, location);
                }
            }

            return(true);
        }
Exemple #2
0
 public void RemoveSelectTo(NavigateControlId id)
 {
     if (SelectTos.ContainsKey(id))
     {
         SelectTos.Remove(id);
     }
 }
        /// <summary>
        /// Returns TRUE if a note was edited, FALSE otherwise.
        /// </summary>
        /// <param name="controlId"></param>
        /// <param name="note"></param>
        /// <returns></returns>
        public static async Task <bool> EditNoteAsync(NavigateControlId controlId, UserNote note)
        {
            var bookdb = BookDataContext.Get();

            var edited = false;
            var cd     = new ContentDialog()
            {
                Title               = "Edit Bookmark (Note)",
                PrimaryButtonText   = "OK",
                SecondaryButtonText = "Cancel"
            };
            var ne = new NoteEditor();

            ne.DataContext = note;
            cd.Content     = ne;
            var result = await cd.ShowAsync();

            switch (result)
            {
            case ContentDialogResult.Primary:
                ne.SaveNoteIfNeeded(controlId, bookdb);
                edited = true;
                break;

            case ContentDialogResult.Secondary:
                // Cancel means don't save the note.
                edited = false;
                break;
            }
            return(edited);
        }
Exemple #4
0
        public void SelectTo(NavigateControlId sourceId, string selected)
        {
            var urlTemplate = (uiSearchUrl.SelectedItem as ComboBoxItem).Tag as string;
            var escaped     = Uri.EscapeUriString(selected);
            var dataescaped = Uri.EscapeDataString(selected);
            var url         = urlTemplate.Replace("{SEARCH}", escaped);

            uiSearchWeb.Navigate(new Uri(url));
        }
Exemple #5
0
 public void UpdateProjectRome(NavigateControlId sourceId, BookLocation location)
 {
     foreach (var(id, control) in NavigateTos)
     {
         if (id != sourceId && id == NavigateControlId.ProjectRome)
         {
             control.NavigateTo(sourceId, location);
         }
     }
 }
Exemple #6
0
 /// <summary>
 /// Called (often by the main display) when the user selects some book text.
 /// AFAICT, there's no reason for anyone else to call this. The end result is
 /// that e.g. the web search gets the selected text and does a web search.
 /// </summary>
 /// <param name="sourceId"></param>
 /// <param name="selection"></param>
 public void UserSelected(NavigateControlId sourceId, string selection)
 {
     foreach (var(id, control) in SelectTos)
     {
         if (id != sourceId)
         {
             control.SelectTo(sourceId, selection);
         }
     }
 }
Exemple #7
0
 /// <summary>
 /// Setup routine called just a few times at app startup. Tells the navigator which
 /// displays are which.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="navigateTo"></param>
 public void AddNavigateTo(NavigateControlId id, INavigateTo navigateTo)
 {
     if (NavigateTos.ContainsKey(id))
     {
         NavigateTos[id] = navigateTo;
     }
     else
     {
         NavigateTos.Add(id, navigateTo);
     }
 }
Exemple #8
0
 /// <summary>
 /// Called by any of the displays when the user has picked a place to navigate to.
 /// Is never called automatically. The place is a place inside the already-viewed ebook.
 /// </summary>
 /// <param name="sourceId"></param>
 /// <param name="location"></param>
 public void UserNavigatedTo(NavigateControlId sourceId, BookLocation location)
 {
     Logger.Log($"UserNavigatedTo({location})");
     foreach (var(id, control) in NavigateTos)
     {
         if (id != sourceId)
         {
             control.NavigateTo(sourceId, location);
         }
     }
 }
Exemple #9
0
 public void UpdatedNotes(NavigateControlId id)
 {
     foreach (var item in SimpleBookHandlers)
     {
         // No hairpin selects
         if (item.Key != id)
         {
             if (item.Key == NavigateControlId.NoteListDisplay || item.Key == NavigateControlId.BookSearchDisplay)
             {
                 item.Value.DisplayBook(null, null); // refreshes the book
             }
         }
     }
 }
        public void SaveNoteIfNeeded(NavigateControlId controlId, BookDataContext bookdb)
        {
            var note = DataContext as UserNote;

            if (note == null)
            {
                return;
            }

            bool changed = SaveToContext();

            if (changed)
            {
                CommonQueries.BookNoteSave(bookdb, note);
                Navigator.Get().UpdatedNotes(controlId);
            }
        }
Exemple #11
0
        /// <summary>
        /// NavigateTo means navigate to a spot in the book. Will also do a navigation with User...
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="location"></param>
        public void NavigateTo(NavigateControlId sourceId, BookLocation location)
        {
            var bookdb = BookDataContext.Get();

            if (Logger.LogExtraTiming)
            {
                Logger.Log($"MainEpubReader: Navigation: to {location}");
            }
            // Save the fact that we navigated to here. Only the main reader saves this information
            var navigationData = CommonQueries.BookNavigationDataFind(bookdb, BookData.BookId);

            if (navigationData == null)
            {
                navigationData = new BookNavigationData()
                {
                    BookId = BookData.BookId, CurrStatus = BookNavigationData.UserStatus.Reading
                };
                CommonQueries.BookNavigationDataAdd(bookdb, navigationData, CommonQueries.ExistHandling.IfNotExists);
            }
            navigationData.CurrSpot   = location.Location;
            navigationData.CurrStatus = BookNavigationData.UserStatus.Reading; // If I'm navigating then I'm reading?


            // And now actually navigate. There are two types of navigation: navigation
            // via tags and navigation by percent.
            // Both need to be handled.
            var percent = location.HtmlPercent;

            if (percent >= 0.0)
            {
                if (Logger.LogExtraTiming)
                {
                    Logger.Log($"MainEpubReader: Navigation: to percent");
                }
                NavigateToPercent(location);
            }
            else
            {
                if (Logger.LogExtraTiming)
                {
                    Logger.Log($"MainEpubReader: Navigation: via location, not percent ({location})");
                }
                NavigateToLocation(location);
            }
        }
Exemple #12
0
        public async void NavigateTo(NavigateControlId sourceId, BookLocation location)
        {
            if (!ProjectRomeEnabled)
            {
                return;
            }
            try
            {
                var channel  = UserActivityChannel.GetDefault();
                var activity = await channel.GetOrCreateUserActivityAsync(CurrBookId);

                if (!string.IsNullOrEmpty(activity.VisualElements.DisplayText))
                {
                    // If the activity wasn't already created, don't create it now!
                    activity.ActivationUri = AsUri(CurrBookId, location);
                    await activity.SaveAsync();
                }
            }
            catch (Exception)
            {
                // Project Rome is pretty delicate; it fails for no good reasons.
            }
        }
        /// <summary>
        /// Called when the user has navigated to somewhere in the book. The chapter display
        /// tries to sync itself to the value. The chapter display depends on the caller being
        /// fully initialized first!
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="location"></param>
        public async void NavigateTo(NavigateControlId sourceId, BookLocation location)
        {
            string chapterid = "";
            var    nav       = Navigator.Get();

            if (!double.IsNaN(location.ScrollPercent))
            {
                chapterid = await nav.MainBookHandler.GetChapterBeforePercentAsync(location);
            }
            else
            {
                chapterid = nav.MainBookHandler.GetChapterContainingId(location.Location, location.HtmlIndex);
            }
            EpubChapterData foundChapter = null;

            if (foundChapter == null && location.HtmlIndex >= 0)
            {
                var html = Book.ResourcesHtmlOrdered[location.HtmlIndex];
                foreach (var chapter in Chapters)
                {
                    // FAIL: Intro to Planetary Nebulae the location is html 8, id tit1 which is shared by multiple chapters.
                    if (html.Href.EndsWith(chapter.FileName) && chapter.Anchor == chapterid)
                    {
                        foundChapter = chapter;
                        break;
                    }
                }
            }

            // Most common: there's an id, and it matches a single chapter.
            if (foundChapter == null)
            {
                foreach (var chapter in Chapters)
                {
                    if (chapter.Anchor == chapterid || chapter.FileName == chapterid)
                    {
                        foundChapter = chapter;
                        break;
                    }
                }
            }

            if (foundChapter == null && location.HtmlIndex >= 0)
            {
                var html = Book.ResourcesHtmlOrdered[location.HtmlIndex];
                foreach (var chapter in Chapters)
                {
                    // FAIL: Intro to Planetary Nebulae the location is html 8, id tit1 which is shared by multiple chapters.
                    if (html.Href.EndsWith(chapter.FileName))
                    {
                        foundChapter = chapter;
                        break;
                    }
                }
            }

            // Worse case scenario, but it's better to display something
            if (foundChapter == null)
            {
                foreach (var chapter in Chapters)
                {
                    if (string.IsNullOrEmpty(chapterid))
                    {
                        App.Error($"ChapterDisplay:Navigate({location}) was asked to find an empty chapter");
                        foundChapter = chapter;
                        break;
                    }
                }
            }

            if (foundChapter == null)
            {
                // Truly desperate.
                if (Chapters.Count > 0)
                {
                    App.Error($"ChapterDisplay:Navigate({location}) completely failed");
                    foundChapter = Chapters[0];
                }
                else
                {
                    App.Error($"ChapterDisplay:Navigate({location}) last ditch completely failed -- no chapters at all!");
                }
            }

            if (foundChapter != null)
            {
                // Select this one
                uiChapterList.SelectedItem = foundChapter;
                uiChapterList.ScrollIntoView(foundChapter);
                return; // all done!
            }
        }
Exemple #14
0
 public void AddSimpleBookHandler(NavigateControlId id, SimpleBookHandler simple)
 {
     SimpleBookHandlers.Add(id, simple);
 }
Exemple #15
0
 public void UserPickedEbook(NavigateControlId sourceId, string bookId)
 {
 }
Exemple #16
0
 public void AddSetAppColor(NavigateControlId id, ISetAppColors setColor)
 {
     AppColors[id] = setColor;
 }
Exemple #17
0
 public void AddSelectTo(NavigateControlId id, ISelectTo selectTo)
 {
     SelectTos.Add(id, selectTo);
 }