Skip to content

Commit

Permalink
Book map wip 1
Browse files Browse the repository at this point in the history
  • Loading branch information
poire-z committed Nov 26, 2021
1 parent 3427c20 commit bf9dd9b
Show file tree
Hide file tree
Showing 6 changed files with 1,472 additions and 8 deletions.
30 changes: 30 additions & 0 deletions frontend/apps/reader/modules/readerbookmark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1105,6 +1105,36 @@ function ReaderBookmark:getBookmarkPageString(page)
return tostring(page)
end

function ReaderBookmark:getBookmarkedPages()
local pages = {}
for i, v in ipairs(self.bookmarks) do
local page
if self.ui.document.info.has_pages then
page = v.page
else
page = self.ui.document:getPageFromXPointer(v.page)
end
local bookmark_type
if v.highlighted then
if v.text == nil or v.text == "" or self:isBookmarkAutoText(v) then
btype = "highlight"
else
btype = "note"
end
else
btype = "bookmark"
end
if not pages[page] then
pages[page] = {}
end
table.insert(pages[page], {
page = v.page,
btype = btype,
})
end
return pages
end

function ReaderBookmark:getBookmarkAutoText(bookmark, force_auto_text)
if G_reader_settings:nilOrTrue("bookmarks_items_auto_text") or force_auto_text then
local page = self:getBookmarkPageString(bookmark.page)
Expand Down
36 changes: 35 additions & 1 deletion frontend/apps/reader/modules/readertoc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,30 @@ function ReaderToc:validateAndFixToc()
logger.dbg("validateAndFixToc(): quick scan")
local has_bogus
local cur_page = 0
local max_depth = 0
for i = first, last do
local page = toc[i].page
if page < cur_page then
has_bogus = true
break
end
cur_page = page
-- Use this loop to compute max_depth here (if has_bogus,
-- we will recompute it in the loop below)
if toc[i].depth > max_depth then
max_depth = toc[i].depth
end
end
if not has_bogus then -- no TOC items, or all are valid
logger.dbg("validateAndFixToc(): TOC is fine")
self.toc_depth = max_depth
return
end
logger.dbg("validateAndFixToc(): TOC needs fixing")

-- Bad ordering previously noticed: try to fix the wrong items' page
-- by setting it to the previous or next good item page.
max_depth = 0 -- recompute this
local nb_bogus = 0
local nb_fixed_pages = 0
-- We fix only one bogus item per loop, taking the option that
Expand All @@ -198,6 +206,9 @@ function ReaderToc:validateAndFixToc()
-- (These cases are met in the following code with cur_page=57 and page=6)
cur_page = 0
for i = first, last do
if toc[i].depth > max_depth then
max_depth = toc[i].depth
end
local page = toc[i].fixed_page or toc[i].page
if page >= cur_page then
cur_page = page
Expand Down Expand Up @@ -265,6 +276,7 @@ function ReaderToc:validateAndFixToc()
end
end
logger.info(string.format("TOC had %d bogus page numbers: fixed %d items to keep them ordered.", nb_bogus, nb_fixed_pages))
self.toc_depth = max_depth
end

function ReaderToc:getTocIndexByPage(pn_or_xp, skip_ignored_ticks)
Expand Down Expand Up @@ -631,14 +643,30 @@ function ReaderToc:expandParentNode(index)
end
end

function ReaderToc:onShowBookMap()
local BookMapWidget = require("ui/widget/bookmapwidget")
local title = self.ui.document:getProps().title
if title == "" then
title = nil
end
local bookmap = BookMapWidget:new{
title = title,
ui = self.ui,
-- BookMapWidget will access directly submoduiles it needs from self.ui:
-- document, doc_settings, toc, statistics, bookmarks
}
UIManager:show(bookmap)
end

function ReaderToc:onShowToc()
self:fillToc()
-- build menu items
if #self.toc > 0 and not self.toc[1].text then
local has_hidden_flows = self.ui.document:hasHiddenFlows()
for _, v in ipairs(self.toc) do
v.text = self.toc_indent:rep(v.depth-1)..self:cleanUpTocTitle(v.title, true)
v.mandatory = v.page
if self.ui.document:hasHiddenFlows() then
if has_hidden_flows then
local flow = self.ui.document:getPageFlow(v.page)
if v.orig_page then -- bogus page fixed: show original page number
-- This is an ugly piece of code, which can result in an ugly TOC,
Expand Down Expand Up @@ -911,6 +939,12 @@ function ReaderToc:addToMainMenu(menu_items)
self:onShowToc()
end,
}
menu_items.book_map = {
text = _("Book map"),
callback = function()
self:onShowBookMap()
end,
}
-- ToC (and other navigation) settings
menu_items.navi_settings = {
text = _("Settings"),
Expand Down
18 changes: 11 additions & 7 deletions frontend/device/gesturedetector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -584,9 +584,10 @@ function GestureDetector:handleNonTap(tev)
time = tev.timev,
}
else
local pan_threshold = self.input.pan_threshold_override or self.PAN_THRESHOLD
-- We're still inside a stream of input events, see if we need to switch to other states.
if (tev.x and math.abs(tev.x - self.first_tevs[slot].x) >= self.PAN_THRESHOLD) or
(tev.y and math.abs(tev.y - self.first_tevs[slot].y) >= self.PAN_THRESHOLD) then
if (tev.x and math.abs(tev.x - self.first_tevs[slot].x) >= pan_threshold) or
(tev.y and math.abs(tev.y - self.first_tevs[slot].y) >= pan_threshold) then
-- If user's finger moved far enough on the X or Y axes, switch to pan state.
return self:switchState("panState", tev)
end
Expand Down Expand Up @@ -876,11 +877,14 @@ function GestureDetector:holdState(tev, hold)
},
time = tev.timev,
}
elseif (tev.x and math.abs(tev.x - self.first_tevs[slot].x) >= self.PAN_THRESHOLD) or
(tev.y and math.abs(tev.y - self.first_tevs[slot].y) >= self.PAN_THRESHOLD) then
local ges_ev = self:handlePan(tev)
if ges_ev ~= nil then ges_ev.ges = "hold_pan" end
return ges_ev
else
local pan_threshold = self.input.pan_threshold_override or self.PAN_THRESHOLD
if (tev.x and math.abs(tev.x - self.first_tevs[slot].x) >= pan_threshold) or
(tev.y and math.abs(tev.y - self.first_tevs[slot].y) >= pan_threshold) then
local ges_ev = self:handlePan(tev)
if ges_ev ~= nil then ges_ev.ges = "hold_pan" end
return ges_ev
end
end
end
Expand Down

0 comments on commit bf9dd9b

Please sign in to comment.