2013-10-18 20:38:07 +00:00
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
|
|
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")
|
2016-03-12 08:59:15 +00:00
|
|
|
local HorizontalSpan = require("ui/widget/horizontalspan")
|
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")
|
2015-03-12 06:35:43 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-12-15 12:19:06 +00:00
|
|
|
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")
|
2015-03-12 06:35:43 +00:00
|
|
|
local _ = require("gettext")
|
2015-11-27 15:13:01 +00:00
|
|
|
local util = require("util")
|
2013-02-23 18:25:57 +00:00
|
|
|
|
2016-02-04 03:28:50 +00:00
|
|
|
|
2016-04-28 07:02:15 +00:00
|
|
|
local MODE = {
|
|
|
|
off = 0,
|
|
|
|
page_progress = 1,
|
|
|
|
time = 2,
|
|
|
|
pages_left = 3,
|
|
|
|
battery = 4,
|
|
|
|
percentage = 5,
|
|
|
|
book_time_to_read = 6,
|
|
|
|
chapter_time_to_read = 7,
|
2016-10-16 17:22:26 +00:00
|
|
|
frontlight = 8,
|
2016-04-28 07:02:15 +00:00
|
|
|
}
|
2016-11-02 08:38:52 +00:00
|
|
|
|
2016-04-28 07:02:15 +00:00
|
|
|
local MODE_INDEX = {}
|
|
|
|
for k,v in pairs(MODE) do
|
|
|
|
MODE_INDEX[v] = k
|
|
|
|
end
|
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
-- functions that generates footer text for each mode
|
|
|
|
local footerTextGeneratorMap = {
|
|
|
|
empty = function() return "" end,
|
|
|
|
frontlight = function()
|
|
|
|
if not Device:hasFrontlight() then return "L: NA" end
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
if powerd.is_fl_on ~= nil and powerd.is_fl_on == true then
|
|
|
|
if powerd.fl_intensity ~= nil then
|
|
|
|
return string.format("L: %d%%", powerd.fl_intensity)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
return "L: Off"
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
battery = function()
|
|
|
|
local powerd = Device:getPowerDevice()
|
|
|
|
return "B:" .. (powerd:isCharging() and "+" or "") .. powerd:getCapacity() .. "%"
|
|
|
|
end,
|
|
|
|
time = function()
|
|
|
|
return os.date("%H:%M")
|
|
|
|
end,
|
|
|
|
page_progress = function(footer)
|
|
|
|
if footer.pageno then
|
|
|
|
return string.format("%d / %d", footer.pageno, footer.pages)
|
|
|
|
else
|
|
|
|
return string.format("%d / %d", footer.position, footer.doc_height)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
pages_left = function(footer)
|
|
|
|
local left = footer.ui.toc:getChapterPagesLeft(
|
|
|
|
footer.pageno, footer.toc_level)
|
|
|
|
return "=> " .. (left and left or footer.pages - footer.pageno)
|
|
|
|
end,
|
|
|
|
percentage = function(footer)
|
|
|
|
return string.format("R:%1.f%%", footer.progress_bar.percentage * 100)
|
|
|
|
end,
|
|
|
|
book_time_to_read = function(footer)
|
|
|
|
local current_page
|
|
|
|
if footer.view.document.info.has_pages then
|
|
|
|
current_page = footer.ui.paging.current_page
|
|
|
|
else
|
|
|
|
current_page = footer.view.document:getCurrentPage()
|
|
|
|
end
|
|
|
|
return footer:getDataFromStatistics("TB: ", footer.pages - current_page)
|
|
|
|
end,
|
|
|
|
chapter_time_to_read = function(footer)
|
|
|
|
local left = footer.ui.toc:getChapterPagesLeft(
|
|
|
|
footer.pageno, footer.toc_level)
|
|
|
|
return footer:getDataFromStatistics(
|
|
|
|
"TC: ", (left and left or footer.pages - footer.pageno))
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
local ReaderFooter = InputContainer:new{
|
2016-04-28 07:02:15 +00:00
|
|
|
mode = MODE.page_progress,
|
2014-03-13 13:52:43 +00:00
|
|
|
pageno = nil,
|
|
|
|
pages = nil,
|
2014-10-07 09:09:37 +00:00
|
|
|
toc_level = 0,
|
2014-03-13 13:52:43 +00:00
|
|
|
progress_percentage = 0.0,
|
2016-11-02 08:38:52 +00:00
|
|
|
footer_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-11-20 22:07:39 +00:00
|
|
|
bar_height = Screen:scaleBySize(DMINIBAR_HEIGHT),
|
|
|
|
height = Screen:scaleBySize(DMINIBAR_CONTAINER_HEIGHT),
|
2016-03-12 08:59:15 +00:00
|
|
|
horizontal_margin = Screen:scaleBySize(10),
|
|
|
|
text_left_margin = Screen:scaleBySize(10),
|
2015-03-12 06:35:43 +00:00
|
|
|
settings = {},
|
2016-11-02 08:38:52 +00:00
|
|
|
-- added to expose them to unit tests
|
|
|
|
textGeneratorMap = footerTextGeneratorMap,
|
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
|
|
|
|
|
2015-03-12 06:35:43 +00:00
|
|
|
self.settings = G_reader_settings:readSetting("footer") or {
|
|
|
|
disabled = false,
|
|
|
|
all_at_once = false,
|
|
|
|
toc_markers = true,
|
|
|
|
battery = true,
|
|
|
|
time = true,
|
|
|
|
page_progress = true,
|
2015-03-12 07:51:59 +00:00
|
|
|
pages_left = true,
|
2015-03-12 06:35:43 +00:00
|
|
|
percentage = true,
|
2015-11-27 15:13:01 +00:00
|
|
|
book_time_to_read = true,
|
|
|
|
chapter_time_to_read = true,
|
2016-10-16 17:22:26 +00:00
|
|
|
frontlight = false,
|
2015-03-12 06:35:43 +00:00
|
|
|
}
|
2016-11-02 08:38:52 +00:00
|
|
|
|
2016-03-12 21:59:49 +00:00
|
|
|
if self.settings.disabled then
|
2016-11-02 08:38:52 +00:00
|
|
|
-- footer featuren disabled completely, stop initialization now
|
|
|
|
self:disableFooter()
|
2016-03-12 21:59:49 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
self.has_no_mode = true
|
|
|
|
for _, m in ipairs(MODE_INDEX) do
|
|
|
|
if self.settings[m] then
|
|
|
|
self.has_no_mode = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self.footer_text = TextWidget:new{
|
2016-03-12 08:59:15 +00:00
|
|
|
text = '',
|
2014-03-13 13:52:43 +00:00
|
|
|
face = Font:getFace(self.text_font_face, self.text_font_size),
|
|
|
|
}
|
2016-11-02 08:38:52 +00:00
|
|
|
-- all width related values will be initialized in self:resetLayout()
|
|
|
|
self.text_width = 0
|
2014-06-05 04:48:48 +00:00
|
|
|
self.progress_bar = ProgressWidget:new{
|
2016-11-02 08:38:52 +00:00
|
|
|
width = nil,
|
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-10-07 09:09:37 +00:00
|
|
|
tick_width = DMINIBAR_TOC_MARKER_WIDTH,
|
2016-03-19 06:22:17 +00:00
|
|
|
ticks = nil, -- ticks will be populated in self:updateFooterText
|
|
|
|
last = nil, -- last will be initialized in self:updateFooterText
|
2014-06-05 04:48:48 +00:00
|
|
|
}
|
2016-11-02 08:38:52 +00:00
|
|
|
|
|
|
|
local margin_span = HorizontalSpan:new{width = self.horizontal_margin}
|
2016-03-12 08:59:15 +00:00
|
|
|
self.horizontal_group = HorizontalGroup:new{margin_span}
|
|
|
|
self.text_container = RightContainer:new{
|
2016-11-02 08:38:52 +00:00
|
|
|
dimen = Geom:new{w = 0, h = self.height},
|
|
|
|
self.footer_text,
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2016-11-02 08:38:52 +00:00
|
|
|
table.insert(self.horizontal_group, self.progress_bar)
|
2016-03-12 08:59:15 +00:00
|
|
|
table.insert(self.horizontal_group, self.text_container)
|
|
|
|
table.insert(self.horizontal_group, margin_span)
|
2014-03-13 13:52:43 +00:00
|
|
|
self[1] = BottomContainer:new{
|
2016-11-02 08:38:52 +00:00
|
|
|
dimen = Geom:new{},
|
2014-05-18 15:27:52 +00:00
|
|
|
BottomContainer:new{
|
2016-11-02 08:38:52 +00:00
|
|
|
dimen = Geom:new{w = 0, h = self.height*2},
|
2014-05-18 15:27:52 +00:00
|
|
|
FrameContainer:new{
|
2016-03-08 06:42:46 +00:00
|
|
|
self.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
|
|
|
}
|
|
|
|
}
|
2016-03-08 06:42:46 +00:00
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
self.mode = G_reader_settings:readSetting("reader_footer_mode") or self.mode
|
|
|
|
if self.settings.all_at_once then
|
|
|
|
self.view.footer_visible = (self.mode ~= MODE.off)
|
|
|
|
self:updateFooterTextGenerator()
|
|
|
|
else
|
|
|
|
self:applyFooterMode()
|
|
|
|
end
|
2016-03-08 06:42:46 +00:00
|
|
|
self:resetLayout()
|
|
|
|
|
|
|
|
if self.settings.auto_refresh_time then
|
2016-11-02 08:38:52 +00:00
|
|
|
self:setupAutoRefreshTime()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:setupAutoRefreshTime()
|
|
|
|
if not self.autoRefreshTime then
|
|
|
|
self.autoRefreshTime = function()
|
|
|
|
self:updateFooter()
|
|
|
|
UIManager:scheduleIn(61 - tonumber(os.date("%S")), self.autoRefreshTime)
|
2016-03-08 06:42:46 +00:00
|
|
|
end
|
|
|
|
end
|
2016-11-02 08:38:52 +00:00
|
|
|
self.onCloseDocument = function()
|
|
|
|
UIManager:unschedule(self.autoRefreshTime)
|
|
|
|
end
|
|
|
|
UIManager:scheduleIn(61 - tonumber(os.date("%S")), self.autoRefreshTime)
|
2016-03-08 06:42:46 +00:00
|
|
|
end
|
|
|
|
|
2016-03-12 08:59:15 +00:00
|
|
|
-- call this method whenever the screen size changed
|
2016-03-08 06:42:46 +00:00
|
|
|
function ReaderFooter:resetLayout()
|
2016-03-12 08:59:15 +00:00
|
|
|
local new_screen_width = Screen:getWidth()
|
|
|
|
if new_screen_width == self._saved_screen_width then return end
|
|
|
|
local new_screen_height = Screen:getHeight()
|
|
|
|
|
|
|
|
self.progress_bar.width = math.floor(new_screen_width - self.text_width - self.horizontal_margin*2)
|
2016-03-08 06:42:46 +00:00
|
|
|
self.horizontal_group:resetLayout()
|
2016-03-12 08:59:15 +00:00
|
|
|
self[1].dimen.w = new_screen_width
|
|
|
|
self[1].dimen.h = new_screen_height
|
|
|
|
self[1][1].dimen.w = new_screen_width
|
2016-03-08 06:42:46 +00:00
|
|
|
self.dimen = self[1]:getSize()
|
|
|
|
|
2016-03-12 08:59:15 +00:00
|
|
|
self._saved_screen_width = new_screen_width
|
2014-03-13 13:52:43 +00:00
|
|
|
if Device:isTouchDevice() then
|
2016-04-26 02:45:55 +00:00
|
|
|
local range = Geom:new{
|
|
|
|
x = new_screen_width*DTAP_ZONE_MINIBAR.x,
|
|
|
|
y = new_screen_height*DTAP_ZONE_MINIBAR.y,
|
|
|
|
w = new_screen_width*DTAP_ZONE_MINIBAR.w,
|
|
|
|
h = new_screen_height*DTAP_ZONE_MINIBAR.h
|
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
function ReaderFooter:getHeight()
|
|
|
|
return self.footer_text:getSize().h
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:disableFooter()
|
|
|
|
self.onReaderReady = function() end
|
|
|
|
self.resetLayout = function() end
|
|
|
|
self.onCloseDocument = nil
|
|
|
|
self.onPageUpdate = function() end
|
|
|
|
self.onPosUpdate = function() end
|
|
|
|
self.onUpdatePos = function() end
|
|
|
|
self.onSetStatusLine = function() end
|
|
|
|
self.mode = MODE.off
|
|
|
|
self.view.footer_visible = false
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:updateFooterTextGenerator()
|
|
|
|
local footerTextGenerators = {}
|
|
|
|
for _, m in pairs(MODE_INDEX) do
|
|
|
|
if self.settings[m] then
|
|
|
|
table.insert(footerTextGenerators,
|
|
|
|
footerTextGeneratorMap[m])
|
|
|
|
if not self.settings.all_at_once then
|
|
|
|
-- if not show all at once, then one is enough
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if #footerTextGenerators == 0 then
|
|
|
|
-- all modes are disabled
|
|
|
|
self.genFooterText = footerTextGeneratorMap.empty
|
|
|
|
elseif #footerTextGenerators == 1 then
|
|
|
|
-- there is only one mode enabled, simplify the generator
|
|
|
|
-- function to that one
|
|
|
|
self.genFooterText = footerTextGenerators[1]
|
|
|
|
else
|
|
|
|
self.footerTextGenerators = footerTextGenerators
|
|
|
|
self.genFooterText = self.genAllFooterText
|
|
|
|
end
|
|
|
|
-- notify caller that UI needs update
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
local option_titles = {
|
2015-03-12 06:35:43 +00:00
|
|
|
all_at_once = _("Show all at once"),
|
2016-11-02 08:38:52 +00:00
|
|
|
toc_markers = _("Show table of content markers"),
|
2016-02-04 03:28:50 +00:00
|
|
|
auto_refresh_time = _("Auto refresh time"),
|
2015-03-20 13:22:14 +00:00
|
|
|
page_progress = _("Current page"),
|
2016-11-02 08:38:52 +00:00
|
|
|
time = _("Current time"),
|
2015-03-20 13:22:14 +00:00
|
|
|
pages_left = _("Pages left in this chapter"),
|
2016-11-02 08:38:52 +00:00
|
|
|
battery = _("Battery status"),
|
2015-03-20 13:22:14 +00:00
|
|
|
percentage = _("Progress percentage"),
|
2015-11-27 15:13:01 +00:00
|
|
|
book_time_to_read = _("Book time to read"),
|
|
|
|
chapter_time_to_read = _("Chapter time to read"),
|
2016-10-16 17:22:26 +00:00
|
|
|
frontlight = _("Frontlight level"),
|
2015-03-12 06:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderFooter:addToMainMenu(tab_item_table)
|
2016-04-26 02:45:55 +00:00
|
|
|
local sub_items = {}
|
2016-11-02 08:38:52 +00:00
|
|
|
table.insert(tab_item_table.setting, {
|
|
|
|
text = _("Status bar"),
|
|
|
|
sub_item_table = sub_items,
|
|
|
|
})
|
|
|
|
|
|
|
|
-- menu item to fake footer tapping when touch area is disabled
|
2016-04-26 02:45:55 +00:00
|
|
|
if Geom:new{
|
|
|
|
x = DTAP_ZONE_MINIBAR.x,
|
|
|
|
y = DTAP_ZONE_MINIBAR.y,
|
|
|
|
w = DTAP_ZONE_MINIBAR.w,
|
|
|
|
h = DTAP_ZONE_MINIBAR.h
|
|
|
|
}:sizeof() == 0 then
|
|
|
|
table.insert(sub_items, {
|
2016-11-02 08:38:52 +00:00
|
|
|
text = _("Toggle mode"),
|
2016-04-26 02:45:55 +00:00
|
|
|
enabled_func = function()
|
|
|
|
return not self.view.flipping_visible
|
|
|
|
end,
|
2016-11-02 08:38:52 +00:00
|
|
|
callback = function() self:onTapFooter() end,
|
2016-04-26 02:45:55 +00:00
|
|
|
})
|
|
|
|
end
|
2016-11-02 08:38:52 +00:00
|
|
|
|
|
|
|
-- footer is enabled, build the full status bar menu
|
|
|
|
local isEnabled = function()
|
|
|
|
return not self.settings.disabled
|
2016-04-26 02:45:55 +00:00
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
local getMinibarOption = function(option, callback)
|
|
|
|
return {
|
|
|
|
text = option_titles[option],
|
|
|
|
checked_func = function()
|
|
|
|
return self.settings[option] == true
|
|
|
|
end,
|
|
|
|
enabled_func = isEnabled,
|
|
|
|
callback = function()
|
|
|
|
self.settings[option] = not self.settings[option]
|
|
|
|
G_reader_settings:saveSetting("footer", self.settings)
|
|
|
|
-- only case that we don't need a UI update is enable/disable
|
|
|
|
-- non-current mode when all_at_once is disabled.
|
|
|
|
local should_update = false
|
|
|
|
local first_enabled_mode_num
|
|
|
|
local prev_has_no_mode = self.has_no_mode
|
|
|
|
self.has_no_mode = true
|
|
|
|
for mode_num, m in pairs(MODE_INDEX) do
|
|
|
|
if self.settings[m] then
|
|
|
|
first_enabled_mode_num = mode_num
|
|
|
|
self.has_no_mode = false
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if callback then
|
|
|
|
should_update = callback(self)
|
|
|
|
elseif self.settings.all_at_once then
|
|
|
|
should_update = self:updateFooterTextGenerator()
|
|
|
|
elseif (MODE[option] == self.mode and self.settings[option] == false)
|
|
|
|
or (prev_has_no_mode ~= self.has_no_mode) then
|
|
|
|
-- current mode got disabled, redraw footer with other
|
|
|
|
-- enabled modes. if all modes are disabled, then only show
|
|
|
|
-- progress bar
|
|
|
|
if not self.has_no_mode then
|
|
|
|
self.mode = first_enabled_mode_num
|
|
|
|
end
|
|
|
|
should_update = true
|
|
|
|
self:applyFooterMode()
|
|
|
|
end
|
|
|
|
if should_update then
|
|
|
|
self:updateFooter()
|
|
|
|
UIManager:setDirty("all", "partial")
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
}
|
2016-10-16 17:22:26 +00:00
|
|
|
end
|
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
table.insert(sub_items,
|
|
|
|
getMinibarOption("all_at_once", self.updateFooterTextGenerator))
|
|
|
|
table.insert(sub_items, getMinibarOption("toc_markers", self.setTocMarkers))
|
|
|
|
-- TODO: only enable auto refresh when time is shown
|
|
|
|
table.insert(sub_items, getMinibarOption("auto_refresh_time", function()
|
|
|
|
if self.settings.auto_refresh_time then
|
|
|
|
self:setupAutoRefreshTime()
|
|
|
|
else
|
|
|
|
UIManager:unschedule(self.autoRefreshTime)
|
|
|
|
self.onCloseDocument = nil
|
|
|
|
end
|
|
|
|
end))
|
|
|
|
table.insert(sub_items, getMinibarOption("page_progress"))
|
|
|
|
table.insert(sub_items, getMinibarOption("time"))
|
|
|
|
table.insert(sub_items, getMinibarOption("pages_left"))
|
|
|
|
table.insert(sub_items, getMinibarOption("battery"))
|
|
|
|
table.insert(sub_items, getMinibarOption("percentage"))
|
|
|
|
table.insert(sub_items, getMinibarOption("book_time_to_read"))
|
|
|
|
table.insert(sub_items, getMinibarOption("chapter_time_to_read"))
|
|
|
|
table.insert(sub_items, getMinibarOption("frontlight"))
|
2014-10-07 09:09:37 +00:00
|
|
|
end
|
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
-- this method will be updated at runtime based on user setting
|
|
|
|
function ReaderFooter:genFooterText() end
|
2014-10-07 09:09:37 +00:00
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
function ReaderFooter:genAllFooterText()
|
|
|
|
local info = {}
|
|
|
|
for _, gen in ipairs(self.footerTextGenerators) do
|
|
|
|
table.insert(info, gen(self))
|
2016-03-12 08:59:15 +00:00
|
|
|
end
|
2016-11-02 08:38:52 +00:00
|
|
|
return table.concat(info, " | ")
|
2014-10-07 09:09:37 +00:00
|
|
|
end
|
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
-- this function should never be called with footer is disabled
|
|
|
|
function ReaderFooter:setTocMarkers()
|
|
|
|
if self.settings.toc_markers then
|
|
|
|
if self.progress_bar.ticks ~= nil then return end
|
|
|
|
local ticks_candidates = {}
|
|
|
|
if self.ui.toc then
|
|
|
|
local max_level = self.ui.toc:getMaxDepth()
|
|
|
|
for i = 0, -max_level, -1 do
|
|
|
|
local ticks = self.ui.toc:getTocTicks(i)
|
|
|
|
table.insert(ticks_candidates, ticks)
|
|
|
|
end
|
|
|
|
-- find the finest toc ticks by sorting out the largest one
|
|
|
|
table.sort(ticks_candidates, function(a, b) return #a > #b end)
|
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
|
2016-11-02 08:38:52 +00:00
|
|
|
if #ticks_candidates > 0 then
|
|
|
|
self.progress_bar.ticks = ticks_candidates[1]
|
|
|
|
self.progress_bar.last = self.pages or self.view.document:getPageCount()
|
|
|
|
else
|
|
|
|
-- we still set ticks here so self.progress_bar.ticks will not be
|
|
|
|
-- initialized again if ticks_candidates is empty
|
|
|
|
self.progress_bar.ticks = {}
|
|
|
|
end
|
2015-12-26 04:54:13 +00:00
|
|
|
else
|
2016-11-02 08:38:52 +00:00
|
|
|
self.progress_bar.ticks = nil
|
2015-12-26 04:54:13 +00:00
|
|
|
end
|
2015-11-27 15:13:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getDataFromStatistics(title, pages)
|
|
|
|
local statistics_data = self.ui.doc_settings:readSetting("stats")
|
2015-12-23 06:35:46 +00:00
|
|
|
local sec = 'na'
|
2015-11-27 15:13:01 +00:00
|
|
|
if statistics_data and statistics_data.performance_in_pages then
|
2016-01-29 06:37:46 +00:00
|
|
|
local read_pages = util.tableSize(statistics_data.performance_in_pages)
|
2015-11-27 15:13:01 +00:00
|
|
|
local average_time_per_page = statistics_data.total_time_in_sec / read_pages
|
2015-12-23 06:35:46 +00:00
|
|
|
sec = util.secondsToClock(pages * average_time_per_page, true)
|
2015-11-27 15:13:01 +00:00
|
|
|
end
|
2015-12-23 06:35:46 +00:00
|
|
|
return title .. sec
|
2015-11-27 15:13:01 +00:00
|
|
|
end
|
|
|
|
|
2016-03-12 08:59:15 +00:00
|
|
|
function ReaderFooter:updateFooter()
|
|
|
|
if self.pageno then
|
|
|
|
self:updateFooterPage()
|
|
|
|
else
|
|
|
|
self:updateFooterPos()
|
|
|
|
end
|
|
|
|
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
|
2016-03-12 08:59:15 +00:00
|
|
|
self:updateFooterText()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:updateFooterPos()
|
|
|
|
if type(self.position) ~= "number" then return end
|
|
|
|
self.progress_bar.percentage = self.position / self.doc_height
|
|
|
|
self:updateFooterText()
|
|
|
|
end
|
|
|
|
|
2016-06-03 08:31:46 +00:00
|
|
|
-- updateFooterText will start as a noop. After onReaderReady event is
|
2016-07-24 00:57:29 +00:00
|
|
|
-- received, it will initialized as _updateFooterText below
|
2016-03-12 08:59:15 +00:00
|
|
|
function ReaderFooter:updateFooterText()
|
2016-06-03 08:31:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- only call this function after document is fully loaded
|
|
|
|
function ReaderFooter:_updateFooterText()
|
2016-11-02 08:38:52 +00:00
|
|
|
self.footer_text:setText(self:genFooterText())
|
|
|
|
if self.has_no_mode then
|
|
|
|
self.text_width = 0
|
2014-07-02 08:43:24 +00:00
|
|
|
else
|
2016-11-02 08:38:52 +00:00
|
|
|
self.text_width = self.footer_text:getSize().w + self.text_left_margin
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2016-03-12 08:59:15 +00:00
|
|
|
self.progress_bar.width = math.floor(
|
|
|
|
self._saved_screen_width - self.text_width - self.horizontal_margin*2)
|
|
|
|
self.text_container.dimen.w = self.text_width
|
|
|
|
self.horizontal_group:resetLayout()
|
|
|
|
UIManager:setDirty(self.view.dialog, "ui", self[1][1][1].dimen)
|
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
|
2016-03-19 06:22:17 +00:00
|
|
|
self.pages = self.view.document:getPageCount()
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|
2016-03-12 08:59:15 +00:00
|
|
|
-- see documentation for more info about this event.
|
2016-11-02 08:38:52 +00:00
|
|
|
ReaderFooter.onUpdatePos = ReaderFooter.updateFooter
|
2014-07-22 13:52:41 +00:00
|
|
|
|
2016-06-03 08:31:46 +00:00
|
|
|
function ReaderFooter:onReaderReady()
|
2016-11-02 08:38:52 +00:00
|
|
|
self:setTocMarkers()
|
2016-06-03 08:31:46 +00:00
|
|
|
self.updateFooterText = self._updateFooterText
|
|
|
|
self:updateFooter()
|
|
|
|
end
|
2016-03-19 06:22:17 +00:00
|
|
|
|
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
|
2015-03-12 06:35:43 +00:00
|
|
|
-- 5 for progress percentage
|
2015-11-27 15:13:01 +00:00
|
|
|
-- 6 for from statistics book time to read
|
|
|
|
-- 7 for from statistics chapter time to read
|
2016-10-16 17:22:26 +00:00
|
|
|
-- 8 for front light level
|
2014-05-19 06:23:31 +00:00
|
|
|
if mode ~= nil then self.mode = mode end
|
2016-04-28 07:02:15 +00:00
|
|
|
self.view.footer_visible = (self.mode ~= MODE.off)
|
2016-11-02 08:38:52 +00:00
|
|
|
if not self.view.footer_visible or self.settings.all_at_once then return end
|
|
|
|
|
|
|
|
local mode_name = MODE_INDEX[self.mode]
|
|
|
|
if not self.settings[mode_name] or self.has_no_mode then
|
|
|
|
-- all modes disabled, only show progress bar
|
|
|
|
mode_name = "empty"
|
|
|
|
end
|
|
|
|
self.genFooterText = footerTextGeneratorMap[mode_name]
|
2014-04-04 13:20:26 +00:00
|
|
|
end
|
|
|
|
|
2014-05-19 06:23:31 +00:00
|
|
|
function ReaderFooter:onEnterFlippingMode()
|
|
|
|
self.orig_mode = self.mode
|
2016-04-28 07:02:15 +00:00
|
|
|
self:applyFooterMode(MODE.page_progress)
|
2014-05-19 06:23:31 +00:00
|
|
|
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
|
2016-11-02 08:38:52 +00:00
|
|
|
if self.settings.all_at_once or self.has_no_mode then
|
2016-04-28 07:02:15 +00:00
|
|
|
if self.mode >= 1 then
|
|
|
|
self.mode = MODE.off
|
|
|
|
else
|
|
|
|
self.mode = MODE.page_progress
|
|
|
|
end
|
|
|
|
else
|
2016-10-16 17:22:26 +00:00
|
|
|
self.mode = (self.mode + 1) % 9
|
2016-04-28 07:02:15 +00:00
|
|
|
for i, m in ipairs(MODE_INDEX) do
|
|
|
|
if self.mode == MODE.off then break end
|
|
|
|
if self.mode == i then
|
|
|
|
if self.settings[m] then
|
|
|
|
break
|
|
|
|
else
|
2016-10-16 17:22:26 +00:00
|
|
|
self.mode = (self.mode + 1) % 9
|
2016-04-28 07:02:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
2014-04-04 13:20:26 +00:00
|
|
|
self:applyFooterMode()
|
2014-11-30 17:28:18 +00:00
|
|
|
G_reader_settings:saveSetting("reader_footer_mode", self.mode)
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2016-03-12 08:59:15 +00:00
|
|
|
self:updateFooter()
|
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)
|
2016-04-28 07:02:15 +00:00
|
|
|
if self.mode == MODE.off then return end
|
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)
|
2016-07-24 00:57:29 +00:00
|
|
|
-- 1 is min progress bar while 0 is full cre header progress bar
|
|
|
|
if status_line == 1 then
|
|
|
|
self.view.footer_visible = (self.mode ~= MODE.off)
|
|
|
|
else
|
|
|
|
self:applyFooterMode(MODE.off)
|
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
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
|