From 16ece06d4550e8fa3f75e25df4657f1b6c0597cc Mon Sep 17 00:00:00 2001 From: smartscripts-nl Date: Sat, 5 Sep 2020 14:54:53 +0200 Subject: [PATCH] [UX] Add bookmark count as footer item (#6629) Optionally display number of bookmarks in footer. If no bookmarks defined, don't show this item --- .../apps/reader/modules/readerbookmark.lua | 4 ++++ frontend/apps/reader/modules/readerfooter.lua | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/frontend/apps/reader/modules/readerbookmark.lua b/frontend/apps/reader/modules/readerbookmark.lua index 238bf0c10..b583549d6 100644 --- a/frontend/apps/reader/modules/readerbookmark.lua +++ b/frontend/apps/reader/modules/readerbookmark.lua @@ -681,6 +681,10 @@ function ReaderBookmark:hasBookmarks() return self.bookmarks and #self.bookmarks > 0 end +function ReaderBookmark:getNumberOfBookmarks() + return self.bookmarks and #self.bookmarks or 0 +end + function ReaderBookmark:getNumberOfHighlightsAndNotes() local highlights = 0 local notes = 0 diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index e0f4d7648..551da9f7e 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -39,6 +39,7 @@ local MODE = { wifi_status = 10, book_title = 11, book_chapter = 12, + bookmark_count = 13, } local symbol_prefix = { @@ -47,6 +48,8 @@ local symbol_prefix = { pages_left = "=>", -- @translators This is the footer letter prefix for battery % remaining. battery = C_("FooterLetterPrefix", "B:"), + -- @translators This is the footer letter prefix for the number of bookmarks (bookmark count). + bookmark_count = C_("FooterLetterPrefix", "BM:"), -- @translators This is the footer letter prefix for percentage read. percentage = C_("FooterLetterPrefix", "R:"), -- @translators This is the footer letter prefix for book time to read. @@ -64,6 +67,7 @@ local symbol_prefix = { time = "⌚", pages_left = BD.mirroredUILayout() and "⇐" or "⇒", battery = "", + bookmark_count = "☆", percentage = BD.mirroredUILayout() and "⤟" or "⤠", book_time_to_read = "⏳", chapter_time_to_read = BD.mirroredUILayout() and "⥖" or "⤻", @@ -155,6 +159,17 @@ local footerTextGeneratorMap = { return BD.wrap(prefix) .. " " .. (powerd:isCharging() and "+" or "") .. batt_lvl .. "%" end end, + bookmark_count = function(footer) + local symbol_type = footer.settings.item_prefix or "icons" + local prefix = symbol_prefix[symbol_type].bookmark_count + --retrieve bookmark count: + local bookmark_count = footer.ui.bookmark:getNumberOfBookmarks() + -- if no bookmarks defined, don't show icon: + if bookmark_count == 0 then + return "" + end + return prefix .. " " .. tostring(bookmark_count) + end, time = function(footer) local symbol_type = footer.settings.item_prefix or "icons" local prefix = symbol_prefix[symbol_type].time @@ -300,6 +315,7 @@ function ReaderFooter:init() reclaim_height = false, toc_markers = true, battery = Device:hasBattery(), + bookmark_count = true, time = true, page_progress = true, pages_left = true, @@ -692,6 +708,7 @@ function ReaderFooter:textOptionTitles(option) local option_titles = { all_at_once = _("Show all at once"), reclaim_height = _("Reclaim bar height from bottom margin"), + bookmark_count = T("Bookmark count (%1)", symbol_prefix[symbol].bookmark_count), page_progress = T(_("Current page (%1)"), "/"), time = symbol_prefix[symbol].time and T(_("Current time (%1)"), symbol_prefix[symbol].time) or _("Current time"), @@ -1603,6 +1620,7 @@ function ReaderFooter:addToMainMenu(menu_items) if Device:hasBattery() then table.insert(sub_items, getMinibarOption("battery")) end + table.insert(sub_items, getMinibarOption("bookmark_count")) table.insert(sub_items, getMinibarOption("percentage")) table.insert(sub_items, getMinibarOption("book_time_to_read")) table.insert(sub_items, getMinibarOption("chapter_time_to_read")) @@ -1855,6 +1873,7 @@ function ReaderFooter:applyFooterMode(mode) -- 10 for Wi-Fi status -- 11 for book title -- 12 for current chapter + -- 13 for bookmark count if mode ~= nil then self.mode = mode end local prev_visible_state = self.view.footer_visible