AltStatusBar/Footer: add the read timer value (#12002)

Closes #11950
This commit is contained in:
zwim
2024-07-19 22:55:31 +02:00
committed by GitHub
parent ce8e27a67c
commit df48d51eca
4 changed files with 245 additions and 31 deletions

View File

@@ -12,6 +12,10 @@ local ReaderCoptListener = EventListener:extend{}
local CRE_HEADER_DEFAULT_SIZE = 20
function ReaderCoptListener:init()
self.additional_header_content = {} -- place, where additional header content can be inserted.
end
function ReaderCoptListener:onReadSettings(config)
local view_mode_name = self.document.configurable.view_mode == 0 and "page" or "scroll"
-- Let crengine know of the view mode before rendering, as it can
@@ -44,6 +48,7 @@ function ReaderCoptListener:onReadSettings(config)
-- We will build the top status bar page info string ourselves,
-- if we have to display any chunk of it
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
or (self.battery == 1 and self.battery_percent == 1) -- don't forget a sole battery
self.document:setPageInfoOverride("") -- an empty string lets crengine display its own page info
self:onTimeFormatChanged()
@@ -84,7 +89,10 @@ end
function ReaderCoptListener:updatePageInfoOverride(pageno)
pageno = pageno or self.ui.view.footer.pageno
if not (self.document.configurable.status_line == 0 and self.view.view_mode == "page" and self.page_info_override) then
if self.document.configurable.status_line ~= 0 or self.view.view_mode ~= "page"
or not self.page_info_override or not next(self.additional_header_content) then
self.document:setPageInfoOverride("")
return
end
-- There are a few cases where we may not be updated on change, at least:
@@ -126,7 +134,18 @@ function ReaderCoptListener:updatePageInfoOverride(pageno)
end
end
local page_info = ""
local additional_content = ""
for dummy, v in ipairs(self.additional_header_content) do
local value = v()
if value and value ~= "" then
additional_content = additional_content .. value
if self.page_number == 1 or self.page_count == 1 then
additional_content = additional_content .. " " -- double spaces as crengine's own drawing
end
end
end
local page_info = additional_content
if self.page_number == 1 or self.page_count == 1 then
page_info = page_info .. page_pre
if self.page_number == 1 then
@@ -158,13 +177,13 @@ function ReaderCoptListener:updatePageInfoOverride(pageno)
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then
local aux_batt_lvl = powerd:getAuxCapacity()
if powerd:isAuxCharging() then
batt_pre = "[\u{21AF}"
batt_pre = "[\u{21AF}" -- ↯-symbol
end
-- Sum both batteries for the actual text
batt_lvl = batt_lvl + aux_batt_lvl
else
if powerd:isCharging() then
batt_pre = "[\u{21AF}"
batt_pre = "[\u{21AF}" -- ↯-symbol
end
end
batt_val = string.format("%2d%%", batt_lvl)
@@ -300,15 +319,30 @@ end
ReaderCoptListener.onCloseDocument = ReaderCoptListener.unscheduleHeaderRefresh
ReaderCoptListener.onSuspend = ReaderCoptListener.unscheduleHeaderRefresh
function ReaderCoptListener:addAdditionalHeaderContent(content_func)
table.insert(self.additional_header_content, content_func)
end
function ReaderCoptListener:removeAdditionalHeaderContent(content_func)
for i, v in ipairs(self.additional_header_content) do
if v == content_func then
table.remove(self.additional_header_content, i)
return true
end
end
end
function ReaderCoptListener:setAndSave(setting, property, value)
self.document._document:setIntProperty(property, value)
G_reader_settings:saveSetting(setting, value)
self:onUpdateHeader()
end
function ReaderCoptListener:onUpdateHeader()
self.page_info_override = self.page_number == 1 or self.page_count == 1 or self.reading_percent == 1
if self.page_info_override then
self:updatePageInfoOverride()
else
self.document:setPageInfoOverride("") -- Don't forget to restore CRE default behaviour.
end
or (self.battery == 1 and self.battery_percent == 1) -- don't forget a sole battery
self:updatePageInfoOverride()
-- Have crengine redraw it (even if hidden by the menu at this time)
self.ui.rolling:updateBatteryState()
self:updateHeader()

View File

@@ -341,10 +341,10 @@ local footerTextGeneratorMap = {
prefix .. " ", left)
end,
mem_usage = function(footer)
local symbol_type = footer.settings.item_prefix
local prefix = symbol_prefix[symbol_type].mem_usage
local statm = io.open("/proc/self/statm", "r")
if statm then
local symbol_type = footer.settings.item_prefix
local prefix = symbol_prefix[symbol_type].mem_usage
local dummy, rss = statm:read("*number", "*number")
statm:close()
-- we got the nb of 4Kb-pages used, that we convert to MiB
@@ -516,6 +516,8 @@ ReaderFooter.default_settings = {
function ReaderFooter:init()
self.settings = G_reader_settings:readSetting("footer", self.default_settings)
self.additional_footer_content = {} -- place, where additional header content can be inserted.
-- Remove items not supported by the current device
if not Device:hasFastWifiStatusQuery() then
MODE.wifi_status = nil
@@ -1981,6 +1983,19 @@ function ReaderFooter:genAlignmentMenuItems(value)
}
end
function ReaderFooter:addAdditionalFooterContent(content_func)
table.insert(self.additional_footer_content, content_func)
end
function ReaderFooter:removeAdditionalFooterContent(content_func)
for i, v in ipairs(self.additional_footer_content) do
if v == content_func then
table.remove(self.additional_footer_content, i)
return true
end
end
end
-- this method will be updated at runtime based on user setting
function ReaderFooter:genFooterText() end
@@ -2153,6 +2168,13 @@ function ReaderFooter:_updateFooterText(force_repaint, full_repaint)
return
end
local text = self:genFooterText()
for dummy, v in ipairs(self.additional_footer_content) do
local value = v()
if value and value ~= "" then
text = value .. " " .. self:get_separator_symbol() .. " " .. text
end
end
if not text then text = "" end
self.footer_text:setText(text)
if self.settings.disable_progress_bar then