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
|
|
|
|
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-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 = {},
|
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()
|
|
|
|
|
2015-03-12 06:35:43 +00:00
|
|
|
self.settings = G_reader_settings:readSetting("footer") or {
|
|
|
|
disabled = false,
|
|
|
|
all_at_once = false,
|
|
|
|
progress_bar = true,
|
|
|
|
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,
|
2015-03-12 06:35:43 +00:00
|
|
|
}
|
2014-03-13 13:52:43 +00:00
|
|
|
self.progress_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-03-12 08:59:15 +00:00
|
|
|
self.text_width = self.progress_text:getSize().w + self.text_left_margin
|
|
|
|
self:applyFooterMode()
|
2014-11-18 08:50:37 +00:00
|
|
|
local ticks_candidates = {}
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.ui.toc and self.settings.toc_markers then
|
2014-10-20 14:17:53 +00:00
|
|
|
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{
|
2016-03-08 06:42:46 +00:00
|
|
|
width = nil, -- width will be updated in self:resetLayout()
|
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
|
|
|
}
|
2016-03-12 08:59:15 +00:00
|
|
|
local margin_span = HorizontalSpan:new{width=self.horizontal_margin}
|
|
|
|
local screen_width = Screen:getWidth()
|
|
|
|
self.horizontal_group = HorizontalGroup:new{margin_span}
|
|
|
|
self.text_container = RightContainer:new{
|
|
|
|
dimen = Geom:new{w = self.text_width, h = self.height},
|
2014-03-13 13:52:43 +00:00
|
|
|
self.progress_text,
|
|
|
|
}
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.progress_bar then
|
2016-03-12 08:59:15 +00:00
|
|
|
table.insert(self.horizontal_group, self.progress_bar)
|
2014-08-07 18:22:28 +00:00
|
|
|
end
|
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{
|
|
|
|
dimen = Screen:getSize(),
|
2014-05-18 15:27:52 +00:00
|
|
|
BottomContainer:new{
|
2016-03-12 08:59:15 +00:00
|
|
|
dimen = Geom:new{w = screen_width, 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
|
|
|
|
|
|
|
self.mode = G_reader_settings:readSetting("reader_footer_mode") or self.mode
|
|
|
|
self:resetLayout()
|
|
|
|
|
|
|
|
if self.settings.auto_refresh_time then
|
|
|
|
if not self.autoRefreshTime then
|
|
|
|
self.autoRefreshTime = function()
|
2016-03-12 08:59:15 +00:00
|
|
|
self:updateFooter()
|
2016-03-08 06:42:46 +00:00
|
|
|
UIManager:scheduleIn(61 - tonumber(os.date("%S")), self.autoRefreshTime)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
self.onCloseDocument = function()
|
|
|
|
UIManager:unschedule(self.autoRefreshTime)
|
|
|
|
end
|
|
|
|
UIManager:scheduleIn(61 - tonumber(os.date("%S")), self.autoRefreshTime)
|
|
|
|
end
|
|
|
|
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-06-08 11:07:14 +00:00
|
|
|
local range = Geom:new{
|
2016-03-12 08:59:15 +00:00
|
|
|
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-06-08 11:07:14 +00:00
|
|
|
}
|
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
|
2013-02-23 18:25:57 +00:00
|
|
|
end
|
|
|
|
|
2015-03-12 06:35:43 +00:00
|
|
|
local options = {
|
|
|
|
all_at_once = _("Show all at once"),
|
2016-02-04 03:28:50 +00:00
|
|
|
auto_refresh_time = _("Auto refresh time"),
|
2015-03-12 06:35:43 +00:00
|
|
|
progress_bar = _("Progress bar"),
|
|
|
|
toc_markers = _("Chapter markers"),
|
|
|
|
battery = _("Battery status"),
|
|
|
|
time = _("Current time"),
|
2015-03-20 13:22:14 +00:00
|
|
|
page_progress = _("Current page"),
|
|
|
|
pages_left = _("Pages left in this chapter"),
|
|
|
|
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"),
|
2015-03-12 06:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderFooter:addToMainMenu(tab_item_table)
|
|
|
|
local get_minibar_option = function(option)
|
|
|
|
return {
|
|
|
|
text = options[option],
|
|
|
|
checked_func = function()
|
|
|
|
return self.settings[option] == true
|
|
|
|
end,
|
|
|
|
enabled_func = function()
|
2016-02-04 03:28:50 +00:00
|
|
|
return not self.settings.disabled
|
2015-03-12 06:35:43 +00:00
|
|
|
end,
|
|
|
|
callback = function()
|
|
|
|
self.settings[option] = not self.settings[option]
|
|
|
|
G_reader_settings:saveSetting("footer", self.settings)
|
2016-03-12 08:59:15 +00:00
|
|
|
self:updateFooter()
|
2015-03-12 06:35:43 +00:00
|
|
|
UIManager:setDirty("all", "partial")
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
table.insert(tab_item_table.setting, {
|
|
|
|
text = _("Status bar"),
|
|
|
|
sub_item_table = {
|
|
|
|
get_minibar_option("all_at_once"),
|
2016-02-04 03:28:50 +00:00
|
|
|
get_minibar_option("auto_refresh_time"),
|
2015-03-12 06:35:43 +00:00
|
|
|
get_minibar_option("progress_bar"),
|
|
|
|
get_minibar_option("toc_markers"),
|
|
|
|
get_minibar_option("battery"),
|
|
|
|
get_minibar_option("time"),
|
|
|
|
get_minibar_option("page_progress"),
|
2015-03-12 07:51:59 +00:00
|
|
|
get_minibar_option("pages_left"),
|
2015-03-12 06:35:43 +00:00
|
|
|
get_minibar_option("percentage"),
|
2015-11-27 15:13:01 +00:00
|
|
|
get_minibar_option("book_time_to_read"),
|
|
|
|
get_minibar_option("chapter_time_to_read"),
|
2015-03-12 06:35:43 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2014-10-07 09:09:37 +00:00
|
|
|
function ReaderFooter:getBatteryInfo()
|
|
|
|
local powerd = Device:getPowerDevice()
|
2015-09-09 15:37:35 +00:00
|
|
|
return "B:" .. (powerd:isCharging() and "+" or "") .. powerd:getCapacity() .. "%"
|
2014-10-07 09:09:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getTimeInfo()
|
|
|
|
return os.date("%H:%M")
|
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getProgressInfo()
|
2016-03-12 08:59:15 +00:00
|
|
|
if self.pageno then
|
|
|
|
return string.format("%d / %d", self.pageno, self.pages)
|
|
|
|
else
|
|
|
|
return string.format("%d / %d", self.position, self.doc_height)
|
|
|
|
end
|
2014-10-07 09:09:37 +00:00
|
|
|
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
|
|
|
|
|
2015-03-12 06:35:43 +00:00
|
|
|
function ReaderFooter:getProgressPercentage()
|
|
|
|
return string.format("R:%1.f%%", self.progress_bar.percentage * 100)
|
|
|
|
end
|
|
|
|
|
2015-11-27 15:13:01 +00:00
|
|
|
function ReaderFooter:getBookTimeToRead()
|
2015-12-26 04:54:13 +00:00
|
|
|
local current_page
|
|
|
|
if self.view.document.info.has_pages then
|
|
|
|
current_page = self.ui.paging.current_page
|
|
|
|
else
|
|
|
|
current_page = self.view.document:getCurrentPage()
|
|
|
|
end
|
2015-12-21 06:49:03 +00:00
|
|
|
return self:getDataFromStatistics("TB: ", self.pages - current_page)
|
2015-11-27 15:13:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function ReaderFooter:getChapterTimeToRead()
|
|
|
|
local left = self.ui.toc:getChapterPagesLeft(self.pageno, self.toc_level)
|
|
|
|
return self:getDataFromStatistics("TC: ", (left and left or self.pages - self.pageno))
|
|
|
|
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
|
|
|
|
|
|
|
|
function ReaderFooter:updateFooterText()
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.all_at_once then
|
2014-10-07 09:09:37 +00:00
|
|
|
local info = {}
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.battery then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getBatteryInfo())
|
2014-07-04 12:42:36 +00:00
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.time then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getTimeInfo())
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.page_progress then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getProgressInfo())
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2015-03-12 07:51:59 +00:00
|
|
|
if self.settings.pages_left then
|
2014-10-07 09:09:37 +00:00
|
|
|
table.insert(info, self:getNextChapterInfo())
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.percentage then
|
|
|
|
table.insert(info, self:getProgressPercentage())
|
|
|
|
end
|
2015-11-27 15:13:01 +00:00
|
|
|
if self.settings.book_time_to_read then
|
|
|
|
table.insert(info, self:getBookTimeToRead())
|
|
|
|
end
|
|
|
|
if self.settings.chapter_time_to_read then
|
|
|
|
table.insert(info, self:getChapterTimeToRead())
|
|
|
|
end
|
2016-03-08 06:42:46 +00:00
|
|
|
self.progress_text:setText(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()
|
2015-03-12 06:35:43 +00:00
|
|
|
elseif self.mode == 5 then
|
|
|
|
info = self:getProgressPercentage()
|
2015-11-27 15:13:01 +00:00
|
|
|
elseif self.mode == 6 then
|
|
|
|
info = self:getBookTimeToRead()
|
|
|
|
elseif self.mode == 7 then
|
|
|
|
info = self:getChapterTimeToRead()
|
2014-07-17 13:27:35 +00:00
|
|
|
end
|
2016-03-08 06:42:46 +00:00
|
|
|
self.progress_text:setText(info)
|
2014-07-02 08:43:24 +00:00
|
|
|
end
|
2016-03-12 08:59:15 +00:00
|
|
|
self.text_width = self.progress_text:getSize().w + self.text_left_margin
|
|
|
|
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
|
|
|
|
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
|
2016-03-12 08:59:15 +00:00
|
|
|
-- see documentation for more info about this event.
|
2014-07-22 13:52:41 +00:00
|
|
|
function ReaderFooter:onUpdatePos()
|
2016-03-12 08:59:15 +00:00
|
|
|
self:updateFooter()
|
2014-07-22 13:52:41 +00:00
|
|
|
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
|
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
|
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
|
2015-11-27 15:13:01 +00:00
|
|
|
self.mode = (self.mode + 1) % 8
|
2015-03-12 06:35:43 +00:00
|
|
|
if self.settings.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
|
2015-03-12 06:35:43 +00:00
|
|
|
if (self.mode == 1) and not self.settings.page_progress then
|
2014-07-02 08:43:24 +00:00
|
|
|
self.mode = 2
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
if (self.mode == 2) and not self.settings.time then
|
2014-07-02 08:43:24 +00:00
|
|
|
self.mode = 3
|
2014-07-02 08:32:17 +00:00
|
|
|
end
|
2015-03-12 07:51:59 +00:00
|
|
|
if (self.mode == 3) and not self.settings.pages_left then
|
2014-07-04 12:42:36 +00:00
|
|
|
self.mode = 4
|
|
|
|
end
|
2015-03-12 06:35:43 +00:00
|
|
|
if (self.mode == 4) and not self.settings.battery then
|
|
|
|
self.mode = 5
|
|
|
|
end
|
|
|
|
if (self.mode == 5) and not self.settings.percentage then
|
2015-11-27 15:13:01 +00:00
|
|
|
self.mode = 6
|
|
|
|
end
|
|
|
|
if (self.mode == 6) and not self.settings.book_time_to_read then
|
|
|
|
self.mode = 7
|
|
|
|
end
|
|
|
|
if (self.mode == 7) and not self.settings.chapter_time_to_read 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-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)
|
2015-03-28 14:04:12 +00:00
|
|
|
if self.mode == 0 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)
|
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
|