refactor(statistics): avoid magic 0.1 schedule with PostRender event

pull/1798/head
Qingping Hou 8 years ago
parent daf754d0f4
commit 2f0544b1b7

@ -259,11 +259,14 @@ function ReaderUI:init()
self:registerPostInitCallback(function()
self.document:loadDocument()
-- read additional settings after the document has been loaded
-- (but not rendered yet)
-- used to read additional settings after the document has been
-- loaded (but not rendered yet)
self:handleEvent(Event:new("PreRenderDocument", self.doc_settings))
self.document:render()
-- CREngine only reports correct page count after rendering is done
self:handleEvent(Event:new("PostRenderDocument", self.doc_settings))
end)
-- typeset controller
self:registerModule("typeset", ReaderTypeset:new{

@ -58,9 +58,7 @@ function ReaderStatistics:initData(config)
if self.is_enabled then
local book_properties = self:getBookProperties()
self:savePropertiesInToData(book_properties)
if config.data.stats then
self.data = config.data.stats
else
if not self.data then
--first time merge data
self:inplaceMigration();
end
@ -490,9 +488,12 @@ function ReaderStatistics:saveSettings(fields)
end
function ReaderStatistics:onReadSettings(config)
-- delay initialization for accurate total pages count of the doc
UIManager:scheduleIn(0.1, function() self:initData(config) end)
self.data = config.data.stats
end
return ReaderStatistics
function ReaderStatistics:onPostRenderDocument()
-- we have correct page count now, do the actual initialization work
self:initData()
end
return ReaderStatistics

Loading…
Cancel
Save