From 8d281647ae9d50fc5acd8640bc5684b0eca18443 Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Sun, 27 Oct 2019 05:22:17 +0100 Subject: [PATCH] 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 ;). --- frontend/apps/reader/modules/readerfooter.lua | 39 +++++++++++++++++-- frontend/ui/font.lua | 5 ++- frontend/ui/widget/touchmenu.lua | 33 ++++++++++++++-- resources/fonts | 2 +- spec/unit/document_spec.lua | 1 + spec/unit/readerfooter_spec.lua | 26 ++++++------- 6 files changed, 83 insertions(+), 23 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index 1de8012fa..b00da32c8 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -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" diff --git a/frontend/ui/font.lua b/frontend/ui/font.lua index 146905791..460e9287a 100644 --- a/frontend/ui/font.lua +++ b/frontend/ui/font.lua @@ -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 diff --git a/frontend/ui/widget/touchmenu.lua b/frontend/ui/widget/touchmenu.lua index 556a43601..dd74eefb5 100644 --- a/frontend/ui/widget/touchmenu.lua +++ b/frontend/ui/widget/touchmenu.lua @@ -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 diff --git a/resources/fonts b/resources/fonts index b17660e3d..fa96f653b 160000 --- a/resources/fonts +++ b/resources/fonts @@ -1 +1 @@ -Subproject commit b17660e3dcf639f0edd30c09ba7e2db2e4c2b3a2 +Subproject commit fa96f653b0ffc11a2402a97b66e27819cb524e9d diff --git a/spec/unit/document_spec.lua b/spec/unit/document_spec.lua index 05db6b1cc..86bb0e964 100644 --- a/spec/unit/document_spec.lua +++ b/spec/unit/document_spec.lua @@ -76,6 +76,7 @@ describe("EPUB document module", function() "FreeSans", "FreeSerif", "Noto Sans", + "Noto Sans Arabic UI", "Noto Sans CJK SC", "Noto Serif", } diff --git a/spec/unit/readerfooter_spec.lua b/spec/unit/readerfooter_spec.lua index 1c3b51740..2a09d825a 100644 --- a/spec/unit/readerfooter_spec.lua +++ b/spec/unit/readerfooter_spec.lua @@ -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()