From b483c54be8c727160d829c8a385f60b5b2a9097c Mon Sep 17 00:00:00 2001 From: poire-z Date: Thu, 5 Oct 2017 21:49:59 +0200 Subject: [PATCH] Fix footer, stats, TOC position with cre in scroll mode (#3304) This gives the page position to these modules even in scroll mode. Also, in readerrolling: don't query battery/charging status when crengine does not need it (used only when it shows its top progress bar). --- frontend/apps/reader/modules/readerfooter.lua | 7 ++++++- frontend/apps/reader/modules/readerrolling.lua | 16 +++++++++++++--- frontend/apps/reader/modules/readertoc.lua | 4 ++++ plugins/statistics.koplugin/main.lua | 4 ++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 6f8363926..9641a081f 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -568,9 +568,14 @@ function ReaderFooter:onPageUpdate(pageno) self:updateFooterPage() end -function ReaderFooter:onPosUpdate(pos) +function ReaderFooter:onPosUpdate(pos, pageno) self.position = pos self.doc_height = self.view.document.info.doc_height + if pageno then + self.pageno = pageno + self.pages = self.view.document:getPageCount() + self.ui.doc_settings:saveSetting("doc_pages", self.pages) -- for Book information + end self:updateFooterPos() end diff --git a/frontend/apps/reader/modules/readerrolling.lua b/frontend/apps/reader/modules/readerrolling.lua index 9578dc256..78c42b3db 100644 --- a/frontend/apps/reader/modules/readerrolling.lua +++ b/frontend/apps/reader/modules/readerrolling.lua @@ -43,6 +43,7 @@ local ReaderRolling = InputContainer:new{ panning_steps = ReaderPanning.panning_steps, show_overlap_enable = nil, overlap = 20, + cre_top_bar_enabled = false, } function ReaderRolling:init() @@ -145,6 +146,8 @@ function ReaderRolling:onReadSettings(config) self.show_overlap_enable = DSHOWOVERLAP end self.inverse_reading_order = config:readSetting("inverse_reading_order") or false + + self:onSetStatusLine(config:readSetting("copt_status_line") or DCREREADER_PROGRESS_BAR) end -- in scroll mode percent_finished must be save before close document @@ -555,7 +558,10 @@ function ReaderRolling:_gotoPos(new_pos) self.view.dim_area.y = 0 end end - self.ui:handleEvent(Event:new("PosUpdate", new_pos)) + -- The current page we get in scroll mode may be a bit innacurate, + -- but we give it anyway to onPosUpdate so footer and statistics can + -- keep up with page. + self.ui:handleEvent(Event:new("PosUpdate", new_pos, self.ui.document:getCurrentPage())) end function ReaderRolling:_gotoPercent(new_percent) @@ -585,9 +591,13 @@ function ReaderRolling:updatePageLink() self.view.links = links end +function ReaderRolling:onSetStatusLine(status_line) + self.cre_top_bar_enabled = status_line == 0 +end + function ReaderRolling:updateBatteryState() - logger.dbg("update battery state") - if self.view.view_mode == "page" then + if self.view.view_mode == "page" and self.cre_top_bar_enabled then + logger.dbg("update battery state") local powerd = Device:getPowerDevice() -- -1 is CR_BATTERY_STATE_CHARGING @ crengine/crengine/include/lvdocview.h local state = powerd:isCharging() and -1 or powerd:getCapacity() diff --git a/frontend/apps/reader/modules/readertoc.lua b/frontend/apps/reader/modules/readertoc.lua index f43fa7c8c..b5bd89d5a 100644 --- a/frontend/apps/reader/modules/readertoc.lua +++ b/frontend/apps/reader/modules/readertoc.lua @@ -72,6 +72,10 @@ function ReaderToc:onPageUpdate(pageno) self.pageno = pageno end +function ReaderToc:onPosUpdate(pos, pageno) + self.pageno = pageno +end + function ReaderToc:fillToc() if self.toc and #self.toc > 0 then return end self.toc = self.ui.document:getToc() diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 3a9d793d3..d5ebff49b 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -1568,6 +1568,10 @@ function ReaderStatistics:deleteBook(id_book) conn:close() end +function ReaderStatistics:onPageUpdate(pos, pageno) + self:onPageUpdate(pageno) +end + function ReaderStatistics:onPageUpdate(pageno) if self:isDocless() or not self.is_enabled then return