From 233f375af4a6da346ce9b0f7b0fce201c4f19d5e Mon Sep 17 00:00:00 2001 From: poire-z Date: Mon, 22 Oct 2018 18:29:36 +0200 Subject: [PATCH] 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. --- frontend/apps/reader/modules/readerfooter.lua | 18 +++++------------- frontend/apps/reader/modules/readerrolling.lua | 9 ++++++++- spec/unit/readerfooter_spec.lua | 6 +++--- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 41b443108..1b0ed10e7 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -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() diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index 13cd40316..bbb86a64a 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -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() diff --git a/spec/unit/readerfooter_spec.lua b/spec/unit/readerfooter_spec.lua index e757756f1..023d6a401 100644 --- a/spec/unit/readerfooter_spec.lua +++ b/spec/unit/readerfooter_spec.lua @@ -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)