2
0
mirror of https://github.com/koreader/koreader synced 2024-10-31 21:20:20 +00:00

add bookmark navigation function to crereader

This commit is contained in:
Qingping Hou 2012-06-06 16:21:25 +08:00
parent d04370464b
commit d0e7f2240d
2 changed files with 33 additions and 1 deletions

View File

@ -271,6 +271,32 @@ end
----------------------------------------------------
-- bookmarks related methods
----------------------------------------------------
function CREReader:isBookmarkInSequence(a, b)
return self.doc:getPosFromXPointer(a.page) < self.doc:getPosFromXPointer(b.page)
end
function CREReader:nextBookMarkedPage()
for k,v in ipairs(self.bookmarks) do
if self.pos < self.doc:getPosFromXPointer(v.page) then
return v
end
end
return nil
end
function CREReader:prevBookMarkedPage()
local pre_item = nil
for k,v in ipairs(self.bookmarks) do
if self.pos <= self.doc:getPosFromXPointer(v) then
if self.doc:getPosFromXPointer(pre_item) < self.pos then
return pre_item
end
end
pre_item = v
end
return nil
end
function CREReader:showBookMarks()
local menu_items = {}
-- build menu items

View File

@ -1447,6 +1447,10 @@ function UniReader:delJump(pageno)
end
end
function UniReader:isBookmarkInSequence(a, b)
return a.page < b.page
end
-- return nil if page already marked
-- otherwise, return true
function UniReader:addBookmark(pageno)
@ -1466,7 +1470,9 @@ function UniReader:addBookmark(pageno)
notes = notes,
}
table.insert(self.bookmarks, mark_item)
table.sort(self.bookmarks, function(a,b) return a.page < b.page end)
table.sort(self.bookmarks, function(a,b)
return self:isBookmarkInSequence(a, b)
end)
return true
end