2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local RightContainer = require("ui/widget/container/rightcontainer")
|
|
|
|
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local ProgressWidget = require("ui/widget/progresswidget")
|
2013-12-15 12:19:06 +00:00
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
2013-10-18 20:38:07 +00:00
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2013-12-15 12:19:06 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local UIManager = require("ui/uimanager")
|
2014-10-30 18:42:18 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Screen = require("device").screen
|
2013-10-18 20:38:07 +00:00
|
|
|
local Geom = require("ui/geometry")
|
2013-12-17 14:42:25 +00:00
|
|
|
local Event = require("ui/event")
|
2013-10-18 20:38:07 +00:00
|
|
|
local Font = require("ui/font")
|
2013-12-15 12:19:06 +00:00
|
|
|
local DEBUG = require("dbg")
|
2014-10-22 13:34:11 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-02-23 18:25:57 +00:00
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderFooter = InputContainer:new{
|
2014-04-04 13:20:26 +00:00
|
|
|
mode = 1,
|
2014-03-13 13:52:43 +00:00
|
|
|
visible = true,
|
|
|
|
pageno = nil,
|
|
|
|
pages = nil,
|
2014-10-07 09:09:37 +00:00
|
|
|
toc_level = 0,
|
2014-11-18 08:50:37 +00:00
|
|
|
max_ticks = 100,
|
2014-03-13 13:52:43 +00:00
|
|
|
progress_percentage = 0.0,
|
2014-07-02 12:46:23 +00:00
|
|
|
progress_text = nil,
|
2014-03-13 13:52:43 +00:00
|
|
|
text_font_face = "ffont",
|
2014-09-27 10:56:47 +00:00
|
|
|
text_font_size = DMINIBAR_FONT_SIZE,
|
2014-08-11 03:09:45 +00:00
|
|
|
bar_height = Screen:scaleByDPI(DMINIBAR_HEIGHT),
|
|
|
|
height = Screen:scaleByDPI(DMINIBAR_CONTAINER_HEIGHT),
|
2014-07-02 08:32:17 +00:00
|
|
|
padding = Screen:scaleByDPI(10),
|
2013-02-23 18:25:57 +00:00
|
|
|
}
|
|
|
|
|
2013-02-24 07:25:08 +00:00
|
|
|
function ReaderFooter:init()
|
2014-07-22 13:52:41 +00:00
|
|
|
self.pageno = self.view.state.page
|
|
|
|
self.pages = self.view.document:getPageCount()
|
|
|
|
|
2014-10-07 09:09:37 +00:00
|
|
|
local text_default = ""
|
2014-07-02 12:46:23 +00:00
|
|
|
if DMINIBAR_ALL_AT_ONCE then
|
2014-10-07 09:09:37 +00:00
|
|
|
local info = {}
|
|
|
|
if DMINIBAR_BATTERY then
|
|
|
|
table.insert(info, "B:100%")
|
|
|
|
end
|
2014-07-22 13:52:41 +00:00
|
|
|
if DMINIBAR_TIME then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, "WW:WW")
|
2014-07-22 13:52:41 +00:00
|
|
|
end
|
|
|
|
if DMINIBAR_PAGES then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, "0000 / 0000")
|
2014-07-22 13:52:41 +00:00
|
|
|
end
|
|
|
|
if DMINIBAR_NEXT_CHAPTER then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, "=> 000")
|
2014-07-22 13:52:41 +00:00
|
|
|
end
|
2014-10-07 09:09:37 +00:00
|
|
|
text_default = table.concat(info, " | ")
|
2014-07-02 12:46:23 +00:00
|
|
|
else
|
2014-10-07 09:09:37 +00:00
|
|
|
text_default = string.format(" %d / %d ", self.pages, self.pages)
|
2014-07-02 12:46:23 +00:00
|
|
|
end
|
|
|
|
|
2014-03-13 13:52:43 +00:00
|
|
|
self.progress_text = TextWidget:new{
|
2014-10-07 09:09:37 +00:00
|
|
|
text = text_default,
|
2014-03-13 13:52:43 +00:00
|
|
|
face = Font:getFace(self.text_font_face, self.text_font_size),
|
|
|
|
}
|
2014-06-05 04:48:48 +00:00
|
|
|
local text_width = self.progress_text:getSize().w
|
2014-11-18 08:50:37 +00:00
|
|
|
local ticks_candidates = {}
|
2014-10-20 14:17:53 +00:00
|
|
|
if self.ui.toc and DMINIBAR_PROGRESS_MARKER then
|
|
|
|
local max_level = self.ui.toc:getMaxDepth()
|
2014-11-18 08:50:37 +00:00
|
|
|
for i = 0, -max_level, -1 do
|
|
|
|
local ticks = self.ui.toc:getTocTicks(i)
|
|
|
|
if #ticks < self.max_ticks then
|
|
|
|
table.insert(ticks_candidates, ticks)
|
|
|
|
end
|
2014-10-20 14:17:53 +00:00
|
|
|
end
|
2014-11-18 08:50:37 +00:00
|
|
|
-- find the finest toc ticks by sorting out the largest one
|
|
|
|
table.sort(ticks_candidates, function(a, b) return #a > #b end)
|
2014-10-20 14:17:53 +00:00
|
|
|
end
|
2014-06-05 04:48:48 +00:00
|
|
|
self.progress_bar = ProgressWidget:new{
|
|
|
|
width = math.floor(Screen:getWidth() - text_width - self.padding),
|
2014-07-17 13:27:35 +00:00
|
|
|
height = self.bar_height,
|
2014-06-05 04:48:48 +00:00
|
|
|
percentage = self.progress_percentage,
|
2014-11-18 08:50:37 +00:00
|
|
|
ticks = ticks_candidates[1] or {},
|
2014-10-07 09:09:37 +00:00
|
|
|
tick_width = DMINIBAR_TOC_MARKER_WIDTH,
|
2014-08-09 06:59:55 +00:00
|
|
|
last = self.pages,
|
2014-06-05 04:48:48 +00:00
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
local horizontal_group = HorizontalGroup:new{}
|
|
|
|
local bar_container = RightContainer:new{
|
2014-06-05 04:48:48 +00:00
|
|
|
dimen = Geom:new{ w = Screen:getWidth() - text_width, h = self.height },
|
2014-03-13 13:52:43 +00:00
|
|
|
self.progress_bar,
|
|
|
|
}
|
|
|
|
local text_container = CenterContainer:new{
|
2014-06-05 04:48:48 +00:00
|
|
|
dimen = Geom:new{ w = text_width, h = self.height },
|
2014-03-13 13:52:43 +00:00
|
|
|
self.progress_text,
|
|
|
|
}
|
2014-08-07 18:22:28 +00:00
|
|
|
if DMINIBAR_PROGRESSBAR then
|
|
|
|
table.insert(horizontal_group, bar_container)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
table.insert(horizontal_group, text_container)
|
|
|
|
self[1] = BottomContainer:new{
|
|
|
|
dimen = Screen:getSize(),
|
2014-05-18 15:27:52 +00:00
|
|
|
BottomContainer:new{
|
|
|
|
dimen = Geom:new{w = Screen:getWidth(), h = self.height*2},
|
|
|
|
FrameContainer:new{
|
|
|
|
horizontal_group,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-05-18 15:27:52 +00:00
|
|
|
bordersize = 0,
|
|
|
|
padding = 0,
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
self.dimen = self[1]:getSize()
|
|
|
|
self:updateFooterPage()
|
2014-06-08 11:07:14 +00:00
|
|
|
local range = Geom:new{
|
|
|
|
x = Screen:getWidth()*DTAP_ZONE_MINIBAR.x,
|
|
|
|
y = Screen:getHeight()*DTAP_ZONE_MINIBAR.y,
|
|
|
|
w = Screen:getWidth()*DTAP_ZONE_MINIBAR.w,
|
|
|
|
h = Screen:getHeight()*DTAP_ZONE_MINIBAR.h
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events = {
|
|
|
|
TapFooter = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
2014-06-08 11:07:14 +00:00
|
|
|
range = range,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
HoldFooter = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
2014-06-08 11:07:14 +00:00
|
|
|
range = range,
|
2014-03-13 13:52:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
2014-05-01 10:51:48 +00:00
|
|
|
self.mode = G_reader_settings:readSetting("reader_footer_mode") or self.mode
|
|
|
|
self:applyFooterMode()
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
|
|
|
|
2014-10-07 09:09:37 +00:00
|
|
|
function ReaderFooter:getBatteryInfo()
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
--local state = powerd:isCharging() and -1 or powerd:getCapacity()
|
|
|
|
return "B:" .. powerd:getCapacity() .. "%"
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getTimeInfo()
|
|
|
|
return os.date("%H:%M")
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getProgressInfo()
|
|
|
|
return string.format("%d / %d", self.pageno, self.pages)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getNextChapterInfo()
|
|
|
|
local left = self.ui.toc:getChapterPagesLeft(self.pageno, self.toc_level)
|
|
|
|
return "=> " .. (left and left or self.pages - self.pageno)
|
2014-07-02 05:06:43 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function ReaderFooter:updateFooterPage()
|
2014-03-13 13:52:43 +00:00
|
|
|
if type(self.pageno) ~= "number" then return end
|
|
|
|
self.progress_bar.percentage = self.pageno / self.pages
|
2014-07-02 08:43:24 +00:00
|
|
|
if DMINIBAR_ALL_AT_ONCE then
|
2014-10-07 09:09:37 +00:00
|
|
|
local info = {}
|
2014-08-05 04:17:50 +00:00
|
|
|
if DMINIBAR_BATTERY then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getBatteryInfo())
|
2014-07-04 12:42:36 +00:00
|
|
|
end
|
2014-07-02 08:43:24 +00:00
|
|
|
if DMINIBAR_TIME then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getTimeInfo())
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
|
|
|
if DMINIBAR_PAGES then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getProgressInfo())
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
|
|
|
if DMINIBAR_NEXT_CHAPTER then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getNextChapterInfo())
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2014-10-07 09:09:37 +00:00
|
|
|
self.progress_text.text = table.concat(info, " | ")
|
2014-07-02 08:43:24 +00:00
|
|
|
else
|
2014-10-07 09:09:37 +00:00
|
|
|
local info = ""
|
2014-07-17 13:27:35 +00:00
|
|
|
if self.mode == 1 then
|
2014-10-07 09:09:37 +00:00
|
|
|
info = self:getProgressInfo()
|
2014-07-17 13:27:35 +00:00
|
|
|
elseif self.mode == 2 then
|
2014-10-07 09:09:37 +00:00
|
|
|
info = self:getTimeInfo()
|
2014-07-17 13:27:35 +00:00
|
|
|
elseif self.mode == 3 then
|
2014-10-07 09:09:37 +00:00
|
|
|
info = self:getNextChapterInfo()
|
2014-07-17 13:27:35 +00:00
|
|
|
elseif self.mode == 4 then
|
2014-10-07 09:09:37 +00:00
|
|
|
info = self:getBatteryInfo()
|
2014-07-17 13:27:35 +00:00
|
|
|
end
|
2014-10-07 09:09:37 +00:00
|
|
|
self.progress_text.text = info
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2014-07-04 12:42:36 +00:00
|
|
|
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function ReaderFooter:updateFooterPos()
|
2014-03-13 13:52:43 +00:00
|
|
|
if type(self.position) ~= "number" then return end
|
|
|
|
self.progress_bar.percentage = self.position / self.doc_height
|
2014-04-04 13:20:26 +00:00
|
|
|
|
2014-07-02 08:32:17 +00:00
|
|
|
if self.show_time then
|
2014-10-07 09:09:37 +00:00
|
|
|
self.progress_text.text = self:getTimeInfo()
|
2014-07-02 08:32:17 +00:00
|
|
|
else
|
2014-10-07 09:09:37 +00:00
|
|
|
local percentage = self.progress_bar.percentage
|
|
|
|
self.progress_text.text = string.format("%1.f", percentage*100) .. "%"
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
2013-02-24 07:25:08 +00:00
|
|
|
function ReaderFooter:onPageUpdate(pageno)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.pageno = pageno
|
|
|
|
self.pages = self.view.document.info.number_of_pages
|
|
|
|
self:updateFooterPage()
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:onPosUpdate(pos)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.position = pos
|
|
|
|
self.doc_height = self.view.document.info.doc_height
|
|
|
|
self:updateFooterPos()
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
|
2014-07-22 13:52:41 +00:00
|
|
|
-- recalculate footer sizes when document page count is updated
|
|
|
|
function ReaderFooter:onUpdatePos()
|
|
|
|
UIManager:scheduleIn(0.1, function() self:init() end)
|
|
|
|
end
|
|
|
|
|
2014-05-19 06:23:31 +00:00
|
|
|
function ReaderFooter:applyFooterMode(mode)
|
2014-04-04 13:20:26 +00:00
|
|
|
-- three modes switcher for reader footer
|
|
|
|
-- 0 for footer off
|
|
|
|
-- 1 for footer page info
|
2014-07-02 08:32:17 +00:00
|
|
|
-- 2 for footer time info
|
|
|
|
-- 3 for footer next_chapter info
|
2014-07-04 12:42:36 +00:00
|
|
|
-- 4 for battery status
|
2014-05-19 06:23:31 +00:00
|
|
|
if mode ~= nil then self.mode = mode end
|
2014-04-04 13:20:26 +00:00
|
|
|
if self.mode == 0 then
|
|
|
|
self.view.footer_visible = false
|
|
|
|
else
|
|
|
|
self.view.footer_visible = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-19 06:23:31 +00:00
|
|
|
function ReaderFooter:onEnterFlippingMode()
|
|
|
|
self.orig_mode = self.mode
|
|
|
|
self:applyFooterMode(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:onExitFlippingMode()
|
|
|
|
self:applyFooterMode(self.orig_mode)
|
|
|
|
end
|
|
|
|
|
2013-12-17 14:42:25 +00:00
|
|
|
function ReaderFooter:onTapFooter(arg, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.view.flipping_visible then
|
|
|
|
local pos = ges.pos
|
|
|
|
local dimen = self.progress_bar.dimen
|
2014-05-19 06:23:31 +00:00
|
|
|
-- if reader footer is not drawn before the dimen value should be nil
|
|
|
|
if dimen then
|
|
|
|
local percentage = (pos.x - dimen.x)/dimen.w
|
|
|
|
self.ui:handleEvent(Event:new("GotoPercentage", percentage))
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
else
|
2014-07-04 12:42:36 +00:00
|
|
|
self.mode = (self.mode + 1) % 5
|
2014-07-02 08:32:17 +00:00
|
|
|
if DMINIBAR_ALL_AT_ONCE and (self.mode > 1) then
|
2014-07-02 08:43:24 +00:00
|
|
|
self.mode = 0
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
|
|
|
if (self.mode == 1) and not DMINIBAR_PAGES then
|
2014-07-02 08:43:24 +00:00
|
|
|
self.mode = 2
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
|
|
|
if (self.mode == 2) and not DMINIBAR_TIME then
|
2014-07-02 08:43:24 +00:00
|
|
|
self.mode = 3
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
|
|
|
if (self.mode == 3) and not DMINIBAR_NEXT_CHAPTER then
|
2014-07-04 12:42:36 +00:00
|
|
|
self.mode = 4
|
|
|
|
end
|
|
|
|
if (self.mode == 4) and not DMINIBAR_BATTERY then
|
2014-07-02 08:43:24 +00:00
|
|
|
self.mode = 0
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
2014-04-04 13:20:26 +00:00
|
|
|
self:applyFooterMode()
|
2014-11-12 15:51:52 +00:00
|
|
|
local region = Geom:new{
|
|
|
|
x = 0,
|
|
|
|
y = Screen:getHeight() - self.height,
|
|
|
|
w = Screen:getWidth(),
|
|
|
|
h = self.height
|
|
|
|
}
|
|
|
|
UIManager.update_regions_func = function()
|
|
|
|
return {region}
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
|
|
|
if self.pageno then
|
|
|
|
self:updateFooterPage()
|
|
|
|
else
|
|
|
|
self:updateFooterPos()
|
|
|
|
end
|
|
|
|
UIManager:setDirty(self.view.dialog, "partial")
|
2014-05-01 10:51:48 +00:00
|
|
|
G_reader_settings:saveSetting("reader_footer_mode", self.mode)
|
2014-04-04 13:20:26 +00:00
|
|
|
return true
|
2013-12-15 12:19:06 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 12:41:16 +00:00
|
|
|
function ReaderFooter:onHoldFooter(arg, ges)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.ui:handleEvent(Event:new("ShowGotoDialog"))
|
|
|
|
return true
|
2014-02-12 12:41:16 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 07:26:56 +00:00
|
|
|
function ReaderFooter:onSetStatusLine(status_line)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.view.footer_visible = status_line == 1 and true or false
|
|
|
|
self.ui.document:setStatusLineProp(status_line)
|
|
|
|
self.ui:handleEvent(Event:new("UpdatePos"))
|
2014-02-12 07:26:56 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return ReaderFooter
|