#1730 Create complete book feature

pull/1785/head
Alex Pletnev 8 years ago
parent 85ca00bbfb
commit c0a2b3d4d9

@ -13,6 +13,7 @@ local ReaderStatus = InputContainer:new {
modified = "", modified = "",
}, },
enabled = true, enabled = true,
total_pages = 0
} }
function ReaderStatus:init() function ReaderStatus:init()
@ -20,6 +21,7 @@ function ReaderStatus:init()
self.enabled = false self.enabled = false
return return
end end
self.total_pages = self.document:getPageCount()
UIManager:scheduleIn(0.1, function() self.ui.menu:registerToMainMenu(self) end) UIManager:scheduleIn(0.1, function() self.ui.menu:registerToMainMenu(self) end)
end end
@ -45,7 +47,12 @@ end
function ReaderStatus:onPageUpdate(pageno) function ReaderStatus:onPageUpdate(pageno)
if self.enabled then if self.enabled then
if pageno == self.document:getPageCount() then --in case when pageUpdate event generated before _document:render()
if pageno > self.total_pages or self.total_pages == 1 then
self.total_pages = self.document:getPageCount()
end
if pageno == self.total_pages and self.total_pages ~= 1 then
self:showStatus() self:showStatus()
end end
end end

@ -14,6 +14,8 @@ local ProgressWidget = require("ui/widget/progresswidget")
local LineWidget = require("ui/widget/linewidget") local LineWidget = require("ui/widget/linewidget")
local TextWidget = require("ui/widget/textwidget") local TextWidget = require("ui/widget/textwidget")
local ImageWidget = require("ui/widget/imagewidget") local ImageWidget = require("ui/widget/imagewidget")
local TextBoxWidget = require("ui/widget/textboxwidget")
local CloseButton = require("ui/widget/closebutton") local CloseButton = require("ui/widget/closebutton")
local InputDialog = require("ui/widget/inputdialog") local InputDialog = require("ui/widget/inputdialog")
@ -51,9 +53,8 @@ local StatusWidget = InputContainer:new {
}, },
stats = { stats = {
total_time_in_sec = 0, total_time_in_sec = 0,
performance_in_pages = nil, performance_in_pages = {},
pages = nil, pages = 0,
} }
} }
@ -146,9 +147,9 @@ function StatusWidget:showStatus()
local header_group = HorizontalGroup:new { local header_group = HorizontalGroup:new {
align = "center", align = "center",
self:addHeader(screen_width * 0.95, Screen:scaleBySize(15), _("Progress")) self:addHeader(screen_width * 0.95, Screen:scaleBySize(15), _("Progress")),
CloseButton:new { window = self }
} }
table.insert(header_group, CloseButton:new { window = self })
table.insert(main_group, header_group) table.insert(main_group, header_group)
table.insert(main_group, cover_with_title_and_author_container) table.insert(main_group, cover_with_title_and_author_container)
@ -375,72 +376,67 @@ function StatusWidget:setStar(num)
return true return true
end end
--TODO generate from table
function StatusWidget:generateStatisticsGroup(width, height, days, average, pages) function StatusWidget:generateStatisticsGroup(width, height, days, average, pages)
local statistics_container = CenterContainer:new { local statistics_container = CenterContainer:new {
dimen = Geom:new { w = width, h = height }, dimen = Geom:new { w = width, h = height },
} }
local statistics_group = VerticalGroup:new { align = "left" } local statistics_group = VerticalGroup:new { align = "left" }
local titles_group = HorizontalGroup:new { align = "center" }
local data_group = HorizontalGroup:new { align = "center" }
local tile_width = width * 0.33333 local tile_width = width / 3
local tile_height = height * 0.5 local tile_height = height / 2
local title_days_container = CenterContainer:new { local titles_group = HorizontalGroup:new {
dimen = Geom:new { w = tile_width, h = tile_height }, align = "center",
TextWidget:new { CenterContainer:new {
text = _("Days"), dimen = Geom:new { w = tile_width, h = tile_height },
face = self.small_font_face, TextWidget:new {
text = _("Days"),
face = self.small_font_face,
},
}, },
} CenterContainer:new {
local title_time_container = CenterContainer:new { dimen = Geom:new { w = tile_width, h = tile_height },
dimen = Geom:new { w = tile_width, h = tile_height }, TextWidget:new {
TextWidget:new { text = _("Time"),
text = _("Time"), face = self.small_font_face,
face = self.small_font_face, },
}, },
} CenterContainer:new {
local title_read_pages_container = CenterContainer:new { dimen = Geom:new { w = tile_width, h = tile_height },
dimen = Geom:new { w = tile_width, h = tile_height }, TextWidget:new {
TextWidget:new { text = _("Read pages"),
text = _("Read pages"), face = self.small_font_face,
face = self.small_font_face, }
} }
} }
table.insert(titles_group, title_days_container)
table.insert(titles_group, title_time_container)
table.insert(titles_group, title_read_pages_container)
local days_container = CenterContainer:new { local data_group = HorizontalGroup:new {
dimen = Geom:new { w = tile_width, h = tile_height }, align = "center",
TextWidget:new { CenterContainer:new {
text = days, dimen = Geom:new { w = tile_width, h = tile_height },
face = self.medium_font_face, TextWidget:new {
text = days,
face = self.medium_font_face,
},
}, },
} CenterContainer:new {
local average_time_container = CenterContainer:new { dimen = Geom:new { w = tile_width, h = tile_height },
dimen = Geom:new { w = tile_width, h = tile_height }, TextWidget:new {
TextWidget:new { text = average,
text = average, face = self.medium_font_face,
face = self.medium_font_face, },
}, },
} CenterContainer:new {
local read_pages_container = CenterContainer:new { dimen = Geom:new { w = tile_width, h = tile_height },
dimen = Geom:new { w = tile_width, h = tile_height }, TextWidget:new {
TextWidget:new { text = pages,
text = pages, face = self.medium_font_face,
face = self.medium_font_face, }
} }
} }
table.insert(data_group, days_container)
table.insert(data_group, average_time_container)
table.insert(data_group, read_pages_container)
table.insert(statistics_group, titles_group) table.insert(statistics_group, titles_group)
table.insert(statistics_group, data_group) table.insert(statistics_group, data_group)
@ -454,29 +450,16 @@ function StatusWidget:generateTitleAuthorProgressGroup(width, height, title, aut
dimen = Geom:new { w = width, h = height }, dimen = Geom:new { w = width, h = height },
} }
local title_author_progressbar_group = VerticalGroup:new { align = "left" } local title_author_progressbar_group = VerticalGroup:new {
align = "center",
table.insert(title_author_progressbar_group, VerticalSpan:new { width = height * 0.2 }) VerticalSpan:new { width = height * 0.2 },
TextBoxWidget:new {
local title_text = self:_getVerticalList(title, width, self.medium_font_face, false) text = title,
width = width,
for i = 1, util.tableSize(title_text) do
local row = {}
for y = 1, util.tableSize(title_text[i]) do
table.insert(row, title_text[i][y].word)
end
local text_title = TextWidget:new {
text = table.concat(row),
face = self.medium_font_face, face = self.medium_font_face,
alignment = "center",
} }
local title_text_container = CenterContainer:new { }
dimen = Geom:new { w = width, h = text_title:getSize().h },
text_title
}
table.insert(title_author_progressbar_group, title_text_container)
end
local text_author = TextWidget:new { local text_author = TextWidget:new {
text = authors, text = authors,
face = self.small_font_face, face = self.small_font_face,
@ -532,78 +515,15 @@ function StatusWidget:onClose()
return true return true
end end
--TODO: MOVE TO UTILS AND CHANGE ALSO TEXTBOXWIDGET
function StatusWidget:_wrapGreedyAlg(h_list, width)
local cur_line_width = 0
local cur_line = {}
local v_list = {}
for k, w in ipairs(h_list) do
w.box = {
x = cur_line_width,
w = w.width,
}
cur_line_width = cur_line_width + w.width
if w.word == "\n" then
if cur_line_width > 0 then
-- hard line break
table.insert(v_list, cur_line)
cur_line = {}
cur_line_width = 0
end
elseif cur_line_width > width then
-- wrap to next line
table.insert(v_list, cur_line)
cur_line = {}
cur_line_width = w.width
table.insert(cur_line, w)
else
table.insert(cur_line, w)
end
end
-- handle last line
table.insert(v_list, cur_line)
return v_list
end
--TODO: MOVE TO UTILS AND CHANGE ALSO TEXTBOXWIDGET
function StatusWidget:_getVerticalList(text, width, face, bold)
-- build horizontal list
local h_list = {}
for line in util.gsplit(text, "\n", true) do
for words in line:gmatch("[\32-\127\192-\255]+[\128-\191]*") do
for word in util.gsplit(words, "%s+", true) do
for w in util.gsplit(word, "%p+", true) do
local word_box = {}
word_box.word = w
word_box.width = RenderText:sizeUtf8Text(0, Screen:getWidth(), face, w, true, bold).x
table.insert(h_list, word_box)
end
end
end
if line:sub(-1) == "\n" then table.insert(h_list, { word = '\n', width = 0 }) end
end
-- @TODO check alg here 25.04 2012 (houqp)
-- @TODO replace greedy algorithm with K&P algorithm 25.04 2012 (houqp)
return self:_wrapGreedyAlg(h_list, width)
end
function StatusWidget:getStatisticsSettings() function StatusWidget:getStatisticsSettings()
local lastfile = G_reader_settings:readSetting("lastfile")
if lastfile then
local settings = DocSettings:open(lastfile)
if settings then
self.stats = settings:readSetting("stats")
end
end
if self.settings then if self.settings then
local currStats = self.settings:readSetting("stats") local stats = self.settings:readSetting("stats")
self.stats.total_time_in_sec = self.stats.total_time_in_sec + currStats.total_time_in_sec if stats then
for k, v in pairs(currStats.performance_in_pages) do self.stats.performance_in_pages[k] = v end self.stats.total_time_in_sec = self.stats.total_time_in_sec + stats.total_time_in_sec
for k, v in pairs(stats.performance_in_pages) do
self.stats.performance_in_pages[k] = v
end
end
end end
end end

Loading…
Cancel
Save