ReaderFooter: Take the PowerCover into account in the battery level

widget

Since we only use a single icon, we have to take a few shortcuts:

* The icon itself is computed based on the average of both batteries.
* The actual value is the sum of both batteries.
* Much like everywhere else, charging means the *aux* battery charging
  (i.e., connected to a power source).

Re #8741, which does the same for ReaderHeader.
reviewable/pr8766/r1
NiLuJe 2 years ago
parent 5518a8109b
commit 0408816a54

@ -176,46 +176,43 @@ local footerTextGeneratorMap = {
local symbol_type = footer.settings.item_prefix
local prefix = symbol_prefix[symbol_type].battery
local powerd = Device:getPowerDevice()
local batt_lvl = powerd:getCapacity()
local batt_lvl = 0
local is_charging = false
if Device:hasBattery() then
local main_batt_lvl = powerd:getCapacity()
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then
local aux_batt_lvl = powerd:getAuxCapacity()
is_charging = powerd:isAuxCharging()
-- Sum both batteries for the actual text
batt_lvl = main_batt_lvl + aux_batt_lvl
-- But average 'em to compute the icon...
if symbol_type == "icons" or symbol_type == "compact_items" then
prefix = powerd:getBatterySymbol(is_charging, batt_lvl / 2)
end
else
is_charging = powerd:isCharging()
batt_lvl = main_batt_lvl
if symbol_type == "icons" or symbol_type == "compact_items" then
prefix = powerd:getBatterySymbol(is_charging, main_batt_lvl)
end
end
end
if footer.settings.all_at_once and batt_lvl > footer.settings.battery_hide_threshold then
return ""
end
-- If we're using icons, use fancy variable icons
-- If we're using icons, use the fancy variable icon from powerd:getBatterySymbol
if symbol_type == "icons" or symbol_type == "compact_items" then
if powerd:isCharging() then
prefix = ""
else
if batt_lvl >= 100 then
prefix = ""
elseif batt_lvl >= 90 then
prefix = ""
elseif batt_lvl >= 80 then
prefix = ""
elseif batt_lvl >= 70 then
prefix = ""
elseif batt_lvl >= 60 then
prefix = ""
elseif batt_lvl >= 50 then
prefix = ""
elseif batt_lvl >= 40 then
prefix = ""
elseif batt_lvl >= 30 then
prefix = ""
elseif batt_lvl >= 20 then
prefix = ""
elseif batt_lvl >= 10 then
prefix = ""
else
prefix = ""
end
end
if symbol_type == "compact_items" then
return BD.wrap(prefix)
else
return BD.wrap(prefix) .. batt_lvl .. "%"
end
else
return BD.wrap(prefix) .. " " .. (powerd:isCharging() and "+" or "") .. batt_lvl .. "%"
return BD.wrap(prefix) .. " " .. (is_charging and "+" or "") .. batt_lvl .. "%"
end
end,
bookmark_count = function(footer)
@ -1582,7 +1579,7 @@ With this enabled, the current page is included, so the count goes from n to 1 i
local battery_threshold = SpinWidget:new{
value = self.settings.battery_hide_threshold,
value_min = 0,
value_max = 100,
value_max = Device:hasAuxBattery() and 200 or 100,
default_value = 100,
value_hold_step = 10,
title_text = _("Hide battery threshold"),

@ -215,4 +215,35 @@ function BasePowerD:stateChanged()
end
end
-- Silly helper to avoid code duplication ;).
function BasePowerD:getBatterySymbol(is_charging, capacity)
if is_charging then
return ""
else
if capacity >= 100 then
return ""
elseif capacity >= 90 then
return ""
elseif capacity >= 80 then
return ""
elseif capacity >= 70 then
return ""
elseif capacity >= 60 then
return ""
elseif capacity >= 50 then
return ""
elseif capacity >= 40 then
return ""
elseif capacity >= 30 then
return ""
elseif capacity >= 20 then
return ""
elseif capacity >= 10 then
return ""
else
return ""
end
end
end
return BasePowerD

@ -646,36 +646,6 @@ function TouchMenu:_recalculatePageLayout()
self.page_num = math.ceil(#self.item_table / self.perpage)
end
local function getBatterySymbol(is_charging, capacity)
if is_charging then
return ""
else
if capacity >= 100 then
return ""
elseif capacity >= 90 then
return ""
elseif capacity >= 80 then
return ""
elseif capacity >= 70 then
return ""
elseif capacity >= 60 then
return ""
elseif capacity >= 50 then
return ""
elseif capacity >= 40 then
return ""
elseif capacity >= 30 then
return ""
elseif capacity >= 20 then
return ""
elseif capacity >= 10 then
return ""
else
return ""
end
end
end
function TouchMenu:updateItems()
local old_dimen = self.dimen and self.dimen:copy()
self:_recalculatePageLayout()
@ -729,12 +699,12 @@ function TouchMenu:updateItems()
local powerd = Device:getPowerDevice()
if Device:hasBattery() then
local batt_lvl = powerd:getCapacity()
local batt_symbol = getBatterySymbol(powerd:isCharging(), batt_lvl)
local batt_symbol = powerd:getBatterySymbol(powerd:isCharging(), batt_lvl)
time_info_txt = BD.wrap(time_info_txt) .. " " .. BD.wrap("") .. BD.wrap(batt_symbol) .. BD.wrap(batt_lvl .. "%")
if Device:hasAuxBattery() and powerd:isAuxBatteryConnected() then
local aux_batt_lvl = powerd:getAuxCapacity()
local aux_batt_symbol = getBatterySymbol(powerd:isAuxCharging(), aux_batt_lvl)
local aux_batt_symbol = powerd:getBatterySymbol(powerd:isAuxCharging(), aux_batt_lvl)
time_info_txt = time_info_txt .. " " .. BD.wrap("+") .. BD.wrap(aux_batt_symbol) .. BD.wrap(aux_batt_lvl .. "%")
end
end

Loading…
Cancel
Save