Cleanup onSetStatusLine()

Follow up to fa0117bb (#4268), to make things a bit clearer:
Only ReaderRolling get the 'SetStatusLine' event, and tells
crengine about the change, and then send the 'UpdatePos' event.
ReaderFooter now just gets a :setVisible() method.

Now, all the code that calls a self.ui.document:set* method, that
most probably triggers a full re-rendering by crengine, do signal
'UpdatePos' immediately after. This event signals that all page
number, pages count, positions... are no more valid and must be
queried or computed again.
This could also be used if we ever want to cache Page Links or
Screen Boxes: this event will have us dropped these caches.
pull/4288/head
poire-z 6 years ago
parent 653741dfac
commit 233f375af4

@ -692,18 +692,11 @@ function ReaderFooter:onHoldFooter()
return true
end
function ReaderFooter:onSetStatusLine(status_line, on_read_settings)
-- Ignore this event when it is first sent by ReaderCoptListener
-- on book loading, so we stay with the saved footer settings
if on_read_settings then
return
end
-- 1 is min progress bar while 0 is full cre header progress bar
if status_line == 1 then
-- If footer was off (if previously with full status bar), make the
-- footer visible, as if we taped on it (and so we don't duplicate
-- this code - not if flipping_visible as in this case, a ges.pos
-- argument to onTapFooter(ges) is required)
function ReaderFooter:setVisible(visible)
if visible then
-- If it was off, just do as if we tap'ed on it (so we don't
-- duplicate onTapFooter() code - not if flipping_visible as in
-- this case, a ges.pos argument to onTapFooter(ges) is required)
if self.mode == MODE.off and not self.view.flipping_visible then
self:onTapFooter()
end
@ -711,7 +704,6 @@ function ReaderFooter:onSetStatusLine(status_line, on_read_settings)
else
self:applyFooterMode(MODE.off)
end
self.ui:handleEvent(Event:new("UpdatePos"))
end
function ReaderFooter:onResume()

@ -709,11 +709,18 @@ function ReaderRolling:updatePageLink()
end
--]]
function ReaderRolling:onSetStatusLine(status_line)
function ReaderRolling:onSetStatusLine(status_line, on_read_settings)
-- status_line values:
-- in crengine: 0=header enabled, 1=disabled
-- in koreader: 0=top status bar, 1=bottom mini bar
self.ui.document:setStatusLineProp(status_line)
self.cre_top_bar_enabled = status_line == 0
if not on_read_settings then
-- Ignore this event when it is first sent by ReaderCoptListener
-- on book loading, so we stay with the saved footer settings
self.view.footer:setVisible(status_line == 1)
end
self.ui:handleEvent(Event:new("UpdatePos"))
end
function ReaderRolling:updateBatteryState()

@ -625,16 +625,16 @@ describe("Readerfooter module", function()
footer:applyFooterMode(0)
assert.is.same(0, footer.mode)
assert.falsy(readerui.view.footer_visible)
readerui.view.footer:onSetStatusLine(1)
readerui.rolling:onSetStatusLine(1)
assert.is.same(1, footer.mode)
assert.truthy(readerui.view.footer_visible)
footer.mode = 1
readerui.view.footer:onSetStatusLine(1)
readerui.rolling:onSetStatusLine(1)
assert.is.same(1, footer.mode)
assert.truthy(readerui.view.footer_visible)
readerui.view.footer:onSetStatusLine(0)
readerui.rolling:onSetStatusLine(0)
assert.is.same(0, footer.mode)
assert.falsy(readerui.view.footer_visible)
end)

Loading…
Cancel
Save