Unify battery meters look'n feel (#5537)

* Unify battery meters look'n feel

Switch to proper (vertical) battery icons (one per 10% steps).

Fix #5535

* Bump fonts (https://github.com/koreader/koreader-fonts/pull/7)

Because we need the new symbols from nerdfonts ;).
pull/5540/head
NiLuJe 5 years ago committed by GitHub
parent 9f7bc356ba
commit 8d281647ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,13 +52,13 @@ local symbol_prefix = {
icons = {
time = "",
pages_left = "",
battery = "",
battery = "",
percentage = "",
book_time_to_read = "",
chapter_time_to_read = "",
frontlight = "",
mem_usage = "",
wifi_status = "",
mem_usage = "",
wifi_status = "",
}
}
local PROGRESS_BAR_STYLE_THICK_DEFAULT_HEIGHT = 7
@ -85,7 +85,38 @@ local footerTextGeneratorMap = {
local symbol_type = footer.settings.item_prefix or "icons"
local prefix = symbol_prefix[symbol_type].battery
local powerd = Device:getPowerDevice()
return prefix .. " " .. (powerd:isCharging() and "+" or "") .. powerd:getCapacity() .. "%"
local batt_lvl = powerd:getCapacity()
-- If we're using icons, use fancy variable icons
if symbol_type == "icons" 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
end
return prefix .. (symbol_type == "icons" and "" or " ") .. batt_lvl .. "%"
end,
time = function(footer)
local symbol_type = footer.settings.item_prefix or "icons"

@ -79,8 +79,9 @@ local Font = {
fallbacks = {
[1] = "NotoSans-Regular.ttf",
[2] = "NotoSansCJKsc-Regular.otf",
[3] = "freefont/FreeSans.ttf",
[4] = "freefont/FreeSerif.ttf",
[3] = "nerdfonts/symbols.ttf",
[4] = "freefont/FreeSans.ttf",
[5] = "freefont/FreeSerif.ttf",
},
-- face table

@ -607,10 +607,37 @@ function TouchMenu:updateItems()
else
time_info_txt = os.date("%H:%M")
end
time_info_txt = time_info_txt .. " " .. Device:getPowerDevice():getCapacity() .. "%"
if Device:getPowerDevice():isCharging() then
time_info_txt = time_info_txt .. ""
local powerd = Device:getPowerDevice()
local batt_lvl = powerd:getCapacity()
time_info_txt = time_info_txt .. ""
if powerd:isCharging() then
time_info_txt = time_info_txt .. ""
else
if batt_lvl >= 100 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 90 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 80 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 70 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 60 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 50 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 40 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 30 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 20 then
time_info_txt = time_info_txt .. ""
elseif batt_lvl >= 10 then
time_info_txt = time_info_txt .. ""
else
time_info_txt = time_info_txt .. ""
end
end
time_info_txt = time_info_txt .. batt_lvl .. "%"
self.time_info:setText(time_info_txt)
-- recalculate dimen based on new layout

@ -1 +1 @@
Subproject commit b17660e3dcf639f0edd30c09ba7e2db2e4c2b3a2
Subproject commit fa96f653b0ffc11a2402a97b66e27819cb524e9d

@ -76,6 +76,7 @@ describe("EPUB document module", function()
"FreeSans",
"FreeSerif",
"Noto Sans",
"Noto Sans Arabic UI",
"Noto Sans CJK SC",
"Noto Serif",
}

@ -164,7 +164,7 @@ describe("Readerfooter module", function()
local timeinfo = footer.textGeneratorMap.time(footer)
local page_count = readerui.document:getPageCount()
-- stats has not been initialized here, so we get na TB and TC
assert.are.same('1 / '..page_count..' | '..timeinfo..' | ⇒ 0 | 0% | ⤠ 0% | ⏳ na | ⤻ na',
assert.are.same('1 / '..page_count..' | '..timeinfo..' | ⇒ 0 | 0% | ⤠ 0% | ⏳ na | ⤻ na',
footer.footer_text.text)
end)
@ -179,7 +179,7 @@ describe("Readerfooter module", function()
local footer = readerui.view.footer
readerui.view.footer:updateFooter()
local timeinfo = readerui.view.footer.textGeneratorMap.time(footer)
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
readerui.view.footer.footer_text.text)
end)
@ -197,7 +197,7 @@ describe("Readerfooter module", function()
footer:resetLayout()
footer:updateFooter()
local timeinfo = footer.textGeneratorMap.time(footer)
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
footer.footer_text.text)
-- disable show all at once, page progress should be on the first
@ -214,10 +214,10 @@ describe("Readerfooter module", function()
-- disable page left, battery should follow
tapFooterMenu(fake_menu, "Pages left in chapter".." (⇒)")
assert.are.same('0%', footer.footer_text.text)
assert.are.same('0%', footer.footer_text.text)
-- disable battery, percentage should follow
tapFooterMenu(fake_menu, "Battery status".." ()")
tapFooterMenu(fake_menu, "Battery status".." ()")
assert.are.same('⤠ 50%', footer.footer_text.text)
-- disable percentage, book time to read should follow
@ -286,20 +286,20 @@ describe("Readerfooter module", function()
local footer = readerui.view.footer
local horizontal_margin = Screen:scaleBySize(10)*2
footer:updateFooter()
assert.is.same(352, footer.text_width)
assert.is.same(351, footer.text_width)
assert.is.same(600, footer.progress_bar.width
+ footer.text_width
+ horizontal_margin)
assert.is.same(228, footer.progress_bar.width)
assert.is.same(229, footer.progress_bar.width)
local old_screen_getwidth = Screen.getWidth
Screen.getWidth = function() return 900 end
footer:resetLayout()
assert.is.same(352, footer.text_width)
assert.is.same(351, footer.text_width)
assert.is.same(900, footer.progress_bar.width
+ footer.text_width
+ horizontal_margin)
assert.is.same(528, footer.progress_bar.width)
assert.is.same(529, footer.progress_bar.width)
Screen.getWidth = old_screen_getwidth
end)
@ -313,12 +313,12 @@ describe("Readerfooter module", function()
}
local footer = readerui.view.footer
footer:onPageUpdate(1)
assert.are.same(220, footer.progress_bar.width)
assert.are.same(360, footer.text_width)
assert.are.same(221, footer.progress_bar.width)
assert.are.same(359, footer.text_width)
footer:onPageUpdate(100)
assert.are.same(188, footer.progress_bar.width)
assert.are.same(392, footer.text_width)
assert.are.same(189, footer.progress_bar.width)
assert.are.same(391, footer.text_width)
end)
it("should support chapter markers", function()

Loading…
Cancel
Save