2013-03-12 17:18:53 +00:00
|
|
|
require "ui/widget/notification"
|
2013-01-01 23:08:19 +00:00
|
|
|
|
2013-01-01 19:38:29 +00:00
|
|
|
ReaderBookmark = InputContainer:new{
|
2013-04-08 07:21:59 +00:00
|
|
|
bm_menu_title = _("Bookmarks"),
|
2013-01-01 19:38:29 +00:00
|
|
|
bookmarks = nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderBookmark:init()
|
|
|
|
if Device:hasKeyboard() then
|
|
|
|
self.key_events = {
|
|
|
|
ShowToc = {
|
|
|
|
{ "B" },
|
2013-04-08 07:21:59 +00:00
|
|
|
doc = _("show bookmarks") },
|
2013-01-01 19:38:29 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
|
|
|
|
2013-02-02 06:36:29 +00:00
|
|
|
function ReaderBookmark:initGesListener()
|
|
|
|
self.ges_events = {
|
2013-02-24 11:49:23 +00:00
|
|
|
ToggleBookmark = {
|
2013-02-02 06:36:29 +00:00
|
|
|
GestureRange:new{
|
2013-02-24 11:49:23 +00:00
|
|
|
ges = "tap",
|
2013-02-02 06:36:29 +00:00
|
|
|
range = Geom:new{
|
2013-02-24 11:49:23 +00:00
|
|
|
x = Screen:getWidth()*7/8, y = 0,
|
|
|
|
w = Screen:getWidth()/8,
|
|
|
|
h = Screen:getHeight()/8
|
2013-02-02 06:36:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2013-01-01 19:38:29 +00:00
|
|
|
function ReaderBookmark:onReadSettings(config)
|
|
|
|
self.bookmarks = config:readSetting("bookmarks") or {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:onCloseDocument()
|
|
|
|
self.ui.doc_settings:saveSetting("bookmarks", self.bookmarks)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:onSetDimensions(dimen)
|
2013-02-02 06:36:29 +00:00
|
|
|
-- update listening according to new screen dimen
|
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self:initGesListener()
|
|
|
|
end
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:onToggleBookmark()
|
2013-01-01 19:38:29 +00:00
|
|
|
local pn_or_xp = nil
|
|
|
|
if self.ui.document.getXPointer then
|
|
|
|
pn_or_xp = self.ui.document:getXPointer()
|
|
|
|
else
|
|
|
|
pn_or_xp = self.view.state.page
|
|
|
|
end
|
2013-02-24 11:49:23 +00:00
|
|
|
self:toggleBookmark(pn_or_xp)
|
|
|
|
self.view.dogear_visible = not self.view.dogear_visible
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
|
|
|
end
|
2013-01-01 22:27:10 +00:00
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:setDogearVisibility(pn_or_xp)
|
|
|
|
if self:isBookmarked(pn_or_xp) then
|
|
|
|
self.ui:handleEvent(Event:new("SetDogearVisibility", true))
|
|
|
|
else
|
|
|
|
self.ui:handleEvent(Event:new("SetDogearVisibility", false))
|
2013-01-01 22:27:10 +00:00
|
|
|
end
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:onPageUpdate(pageno)
|
|
|
|
self:setDogearVisibility(pageno)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:onPosUpdate(pos)
|
|
|
|
-- TODO: cannot check if this pos is bookmarked or not.
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-01-01 19:38:29 +00:00
|
|
|
function ReaderBookmark:onShowBookmark()
|
|
|
|
-- build up item_table
|
|
|
|
for k, v in ipairs(self.bookmarks) do
|
|
|
|
local page = v.page
|
|
|
|
-- for CREngine, bookmark page is xpointer
|
|
|
|
if type(page) == "string" then
|
|
|
|
page = self.ui.document:getPageFromXPointer(v.page)
|
|
|
|
end
|
|
|
|
v.text = "Page "..page.." "..v.notes.." @ "..v.datetime
|
|
|
|
end
|
|
|
|
|
|
|
|
local bm_menu = Menu:new{
|
|
|
|
title = "Bookmarks",
|
|
|
|
item_table = self.bookmarks,
|
2013-03-24 10:28:54 +00:00
|
|
|
width = Screen:getWidth()-50,
|
|
|
|
height = Screen:getHeight()-50,
|
2013-01-01 19:38:29 +00:00
|
|
|
}
|
|
|
|
-- buid up menu widget method as closure
|
|
|
|
local doc = self.ui.document
|
|
|
|
local sendEv = function(ev)
|
|
|
|
self.ui:handleEvent(ev)
|
|
|
|
end
|
|
|
|
function bm_menu:onMenuChoice(item)
|
|
|
|
if doc.info.has_pages then
|
|
|
|
sendEv(Event:new("PageUpdate", item.page))
|
|
|
|
elseif self.view.view_mode == "page" then
|
|
|
|
sendEv(Event:new("PageUpdate", doc:getPageFromXPointer(item.page)))
|
|
|
|
else
|
|
|
|
sendEv(Event:new("PosUpdate", doc:getPosFromXPointer(item.page)))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local menu_container = CenterContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
|
|
|
bm_menu,
|
|
|
|
}
|
2013-03-12 17:18:53 +00:00
|
|
|
bm_menu.close_callback = function()
|
2013-01-01 19:38:29 +00:00
|
|
|
UIManager:close(menu_container)
|
|
|
|
end
|
|
|
|
|
|
|
|
UIManager:show(menu_container)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2013-03-14 05:58:42 +00:00
|
|
|
function ReaderBookmark:addToMainMenu(tab_item_table)
|
2013-01-01 19:38:29 +00:00
|
|
|
-- insert table to main reader menu
|
2013-03-14 05:58:42 +00:00
|
|
|
table.insert(tab_item_table.navi, {
|
2013-01-01 19:38:29 +00:00
|
|
|
text = self.bm_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowBookmark()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:isBookmarked(pn_or_xp)
|
2013-01-01 19:38:29 +00:00
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
if v.page == pn_or_xp then
|
2013-02-24 11:49:23 +00:00
|
|
|
return true
|
2013-01-01 19:38:29 +00:00
|
|
|
end
|
|
|
|
end
|
2013-02-24 11:49:23 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderBookmark:addBookmark(pn_or_xp)
|
2013-01-01 19:38:29 +00:00
|
|
|
-- build notes from TOC
|
|
|
|
local notes = self.ui.toc:getTocTitleByPage(pn_or_xp)
|
|
|
|
if notes ~= "" then
|
|
|
|
notes = "in "..notes
|
|
|
|
end
|
|
|
|
mark_item = {
|
|
|
|
page = pn_or_xp,
|
|
|
|
datetime = os.date("%Y-%m-%d %H:%M:%S"),
|
|
|
|
notes = notes,
|
|
|
|
}
|
|
|
|
table.insert(self.bookmarks, mark_item)
|
|
|
|
table.sort(self.bookmarks, function(a,b)
|
|
|
|
return self:isBookmarkInSequence(a, b)
|
|
|
|
end)
|
|
|
|
return true
|
2013-03-12 17:18:53 +00:00
|
|
|
end
|
2013-01-01 19:38:29 +00:00
|
|
|
|
|
|
|
function ReaderBookmark:isBookmarkInSequence(a, b)
|
|
|
|
return a.page < b.page
|
|
|
|
end
|
|
|
|
|
2013-02-24 11:49:23 +00:00
|
|
|
function ReaderBookmark:toggleBookmark(pn_or_xp)
|
|
|
|
for k,v in ipairs(self.bookmarks) do
|
|
|
|
if v.page == pn_or_xp then
|
|
|
|
table.remove(self.bookmarks, k)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self:addBookmark(pn_or_xp)
|
|
|
|
end
|