From 424fa9b6fd37ac09de80ff9ebbc96c33ed0da1d7 Mon Sep 17 00:00:00 2001 From: hugleo Date: Sun, 17 Mar 2024 08:13:04 -0300 Subject: [PATCH 01/12] ReaderView: ensure that the pan zoom direction is not nil (#11557) Fix gif and web files not opening: https://github.com/koreader/koreader/pull/11425#issuecomment-2002164851 --- frontend/apps/reader/modules/readerview.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 4e872edd2..7c8279434 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -695,7 +695,8 @@ function ReaderView:recalculate() -- start from right of page_area self.visible_area.x = self.page_area.x + self.page_area.w - self.visible_area.w end - if self.document.configurable.zoom_direction >= 2 and self.document.configurable.zoom_direction <= 5 then -- zoom_bottom_to_top + -- Check if we are in zoom_bottom_to_top + if self.document.configurable.zoom_direction and self.document.configurable.zoom_direction >= 2 and self.document.configurable.zoom_direction <= 5 then -- starts from bottom of page_area self.visible_area.y = self.page_area.y + self.page_area.h - self.visible_area.h else From bb98cbf612e31b71ad361c42cf24ca517d7a0b1d Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Mon, 18 Mar 2024 18:35:35 +0200 Subject: [PATCH 02/12] ReaderStatus: update status modification time (#11568) In the "End of the book" action. Closes #11564 (No idea how we got a book without modification time but the time stamp must be updated in any case) --- frontend/apps/reader/modules/readerstatus.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/apps/reader/modules/readerstatus.lua b/frontend/apps/reader/modules/readerstatus.lua index 56ea1ec69..1d4e984c0 100644 --- a/frontend/apps/reader/modules/readerstatus.lua +++ b/frontend/apps/reader/modules/readerstatus.lua @@ -219,6 +219,7 @@ end -- Otherwise we change status from reading/abandoned to complete or from complete to reading. function ReaderStatus:onMarkBook(mark_read) self.summary.status = (not mark_read and self.summary.status == "complete") and "reading" or "complete" + self.summary.modified = os.date("%Y-%m-%d", os.time()) -- If History is called over Reader, it will read the file to get the book status, so save and flush self.settings:saveSetting("summary", self.summary) self.settings:flush() From 9387fcd2d0af29a0b915b53b598f561372522e88 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Mon, 18 Mar 2024 17:36:01 +0100 Subject: [PATCH 03/12] [fix] ReaderLink: fix copy link (#11569) Fixes #11567. --- frontend/apps/reader/modules/readerlink.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/apps/reader/modules/readerlink.lua b/frontend/apps/reader/modules/readerlink.lua index a28a5e182..1c8b52174 100644 --- a/frontend/apps/reader/modules/readerlink.lua +++ b/frontend/apps/reader/modules/readerlink.lua @@ -142,6 +142,7 @@ function ReaderLink:init() return { text = _("Copy"), callback = function() + Device.input.setClipboardText(link_url) UIManager:close(this.external_link_dialog) end, } From c8c4e0301a19ea7f1fe016ef49e5b1244682dc91 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Wed, 20 Mar 2024 11:02:01 +0200 Subject: [PATCH 04/12] covermenu: fix file dialog (#11576) --- plugins/coverbrowser.koplugin/covermenu.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/coverbrowser.koplugin/covermenu.lua b/plugins/coverbrowser.koplugin/covermenu.lua index 579c74b4c..1a2b868be 100644 --- a/plugins/coverbrowser.koplugin/covermenu.lua +++ b/plugins/coverbrowser.koplugin/covermenu.lua @@ -232,7 +232,9 @@ function CoverMenu:updateItems(select_number) -- we replace it by ours. -- (FileManager may replace file_chooser.showFileDialog after we've been called once, so we need -- to replace it again if it is not ours) - if self.showFileDialog and self.showFileDialog ~= self.showFileDialog_ours then + if self.path -- FileManager only + and (not self.showFileDialog_ours -- never replaced + or self.showFileDialog ~= self.showFileDialog_ours) then -- it is no more ours -- We need to do it at nextTick, once FileManager has instantiated -- its FileChooser completely UIManager:nextTick(function() From 67cd647d1a6a36c95d512b1ee461b7a7faf484c4 Mon Sep 17 00:00:00 2001 From: poire-z Date: Wed, 20 Mar 2024 10:09:44 +0100 Subject: [PATCH 05/12] ReaderToc: add option to show chapter lengths (#11546) --- frontend/apps/reader/modules/readertoc.lua | 55 +++++++++++++++++++++- frontend/ui/elements/reader_menu_order.lua | 1 + frontend/ui/widget/menu.lua | 28 +++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readertoc.lua b/frontend/apps/reader/modules/readertoc.lua index a70ced5d1..a77619e49 100644 --- a/frontend/apps/reader/modules/readertoc.lua +++ b/frontend/apps/reader/modules/readertoc.lua @@ -104,6 +104,7 @@ end function ReaderToc:resetToc() self.toc = nil + self.toc_menu_items_built = false self.toc_depth = nil self.ticks = nil self.ticks_flattened = nil @@ -314,6 +315,37 @@ function ReaderToc:validateAndFixToc() self.toc_depth = max_depth end +function ReaderToc:completeTocWithChapterLengths() + local toc = self.toc + local first = 1 + local last = #toc + if last == 0 then + return + end + local prev_item_by_level = {} + for i = first, last do + local item = toc[i] + local page = item.page + local depth = item.depth + for j=#prev_item_by_level, depth, -1 do + local prev_item = prev_item_by_level[j] + if prev_item then + prev_item.chapter_length = page - prev_item.page + end + prev_item_by_level[j] = nil + end + prev_item_by_level[depth] = item + end + -- Set the length of the last ones + local page = self.ui.document:getPageCount() + for j=#prev_item_by_level, 0, -1 do + local prev_item = prev_item_by_level[j] + if prev_item then + prev_item.chapter_length = page - prev_item.page + end + end +end + function ReaderToc:getTocIndexByPage(pn_or_xp, skip_ignored_ticks) self:fillToc() if #self.toc == 0 then return end @@ -661,11 +693,16 @@ function ReaderToc:onShowToc() local items_per_page = G_reader_settings:readSetting("toc_items_per_page") or self.toc_items_per_page_default local items_font_size = G_reader_settings:readSetting("toc_items_font_size") or Menu.getItemFontSize(items_per_page) + local items_show_chapter_length = G_reader_settings:isTrue("toc_items_show_chapter_length") local items_with_dots = G_reader_settings:nilOrTrue("toc_items_with_dots") self:fillToc() -- build menu items - if #self.toc > 0 and not self.toc[1].text then + if #self.toc > 0 and not self.toc_menu_items_built then + self.toc_menu_items_built = true + if items_show_chapter_length then + self:completeTocWithChapterLengths() + end -- Have the width of 4 spaces be the unit of indentation local tmp = TextWidget:new{ text = " ", @@ -679,6 +716,11 @@ function ReaderToc:onShowToc() v.index = k v.indent = toc_indent * (v.depth-1) v.text = self:cleanUpTocTitle(v.title, true) + if items_show_chapter_length then + v.post_text = T("(%1)", v.chapter_length) + else + v.post_text = nil + end v.bidi_wrap_func = BD.auto v.mandatory = v.page if has_hidden_flows then @@ -1147,6 +1189,17 @@ Enabling this option will restrict display to the chapter titles of progress bar UIManager:show(items_font) end, } + menu_items.toc_items_show_chapter_length = { + text = _("Show chapter length"), + keep_menu_open = true, + checked_func = function() + return not G_reader_settings:nilOrFalse("toc_items_show_chapter_length") + end, + callback = function() + G_reader_settings:flipNilOrFalse("toc_items_show_chapter_length") + self.toc_menu_items_built = false + end + } menu_items.toc_items_with_dots = { text = _("With dots"), keep_menu_open = true, diff --git a/frontend/ui/elements/reader_menu_order.lua b/frontend/ui/elements/reader_menu_order.lua index ca48996bf..d64d5f0e6 100644 --- a/frontend/ui/elements/reader_menu_order.lua +++ b/frontend/ui/elements/reader_menu_order.lua @@ -35,6 +35,7 @@ local order = { "----------------------------", "toc_items_per_page", "toc_items_font_size", + "toc_items_show_chapter_length", "toc_items_with_dots", "----------------------------", "toc_alt_toc", diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 46e3b4386..ee2392d38 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -184,6 +184,12 @@ function MenuItem:init() self.face = Font:getFace(self.font, self.font_size) -- Font for "mandatory" on the right self.info_face = Font:getFace(self.infont, self.infont_size) + -- Font for post_text if any: for now, this is only used with TOC, showing + -- the chapter length: if feels best to use the face of the main text, but + -- with the size of the mandatory font (which shows some number too). + if self.post_text then + self.post_text_face = Font:getFace(self.font, self.infont_size) + end -- "mandatory" is the text on the right: file size, page number... -- Padding before mandatory @@ -219,10 +225,23 @@ function MenuItem:init() text = self.bidi_wrap_func(text) end + -- Note: support for post_text is currently implemented only when single_line=true + local post_text_widget + local post_text_left_padding = Size.padding.large + local post_text_right_padding = self.with_dots and 0 or Size.padding.large local dots_widget local dots_left_padding = Size.padding.small local dots_right_padding = Size.padding.small if self.single_line then -- items only in single line + if self.post_text then + post_text_widget = TextWidget:new{ + text = self.post_text, + face = self.post_text_face, + bold = self.bold, + fgcolor = self.dim and Blitbuffer.COLOR_DARK_GRAY or nil, + } + available_width = available_width - post_text_widget:getWidth() - post_text_left_padding - post_text_right_padding + end -- No font size change: text will be truncated if it overflows item_name = TextWidget:new{ text = text, @@ -271,6 +290,9 @@ function MenuItem:init() if dots_widget then dots_widget.forced_height = self.dimen.h end + if post_text_widget then + post_text_widget.forced_height = self.dimen.h + end -- And adjust their baselines for proper centering and alignment -- (We made sure the font sizes wouldn't exceed self.dimen.h, so we -- get only non-negative pad_top here, and we're moving them down.) @@ -289,6 +311,9 @@ function MenuItem:init() if dots_widget then dots_widget.forced_baseline = mdtr_baseline end + if post_text_widget then + post_text_widget.forced_baseline = mdtr_baseline + end end elseif self.multilines_show_more_text then @@ -374,6 +399,8 @@ function MenuItem:init() width = state_width, }, item_name, + post_text_widget and HorizontalSpan:new{ width = post_text_left_padding }, + post_text_widget, } } @@ -1083,6 +1110,7 @@ function Menu:updateItems(select_number) state_w = self.state_w or 0, text = Menu.getMenuText(self.item_table[i]), bidi_wrap_func = self.item_table[i].bidi_wrap_func, + post_text = self.item_table[i].post_text, mandatory = self.item_table[i].mandatory, mandatory_func = self.item_table[i].mandatory_func, mandatory_dim = self.item_table[i].mandatory_dim or self.item_table[i].dim, From 86cb5cbd4c209d83c7f1fe211a5fdd9602ad927c Mon Sep 17 00:00:00 2001 From: poire-z Date: Wed, 20 Mar 2024 22:44:07 +0100 Subject: [PATCH 06/12] bump crengine: various fixes, improved Russian typography (#11578) Includes: - In-page footnotes: avoid with '-cr-hint: noteref-ignore' - In-page footnotes: ensure they don't cross "flows" - Tables: fix rendering when negative text-indent - FB2 cover drawing: ensure _invertImages flag - EPUB: fallback to look for a cover in the first fragment - TextLang: Russian: add typography rules Also update to libunibreak 6.1. --- base | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/base b/base index 64f30427a..da9280238 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit 64f30427a338f75902c3e099ffbc21759cb701df +Subproject commit da9280238cd088fff9b100357a0155ac60e40197 From f4a85145455650a39b09a970ee79a4674c47cf9b Mon Sep 17 00:00:00 2001 From: Denis Malinovsky Date: Wed, 20 Mar 2024 15:24:49 -0700 Subject: [PATCH 07/12] ReaderTypography: update menu features symbols for Russian (#11570) --- frontend/apps/reader/modules/readertypography.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/apps/reader/modules/readertypography.lua b/frontend/apps/reader/modules/readertypography.lua index 50c1ad9d6..8d0c99ab2 100644 --- a/frontend/apps/reader/modules/readertypography.lua +++ b/frontend/apps/reader/modules/readertypography.lua @@ -84,9 +84,9 @@ local LANGUAGES = { { "pt-BR", {}, "HB ", _("Portuguese (BR)"), "Portuguese_BR.pattern" }, { "rm", {"roh"}, "H ", _("Romansh"), "Romansh.pattern" }, { "ro", {"ron"}, "H ", _("Romanian"), "Romanian.pattern" }, - { "ru", {"rus"}, "Hb ", _("Russian"), "Russian.pattern" }, - { "ru-GB", {}, "Hb ", _("Russian + English (UK)"), "Russian_EnGB.pattern" }, - { "ru-US", {}, "Hb ", _("Russian + English (US)"), "Russian_EnUS.pattern" }, + { "ru", {"rus"}, "HB ", _("Russian"), "Russian.pattern" }, + { "ru-GB", {}, "HB ", _("Russian + English (UK)"), "Russian_EnGB.pattern" }, + { "ru-US", {}, "HB ", _("Russian + English (US)"), "Russian_EnUS.pattern" }, { "sr", {"srp"}, "HB ", _("Serbian"), "Serbian.pattern" }, { "sk", {"slk"}, "HB ", _("Slovak"), "Slovak.pattern" }, { "sl", {"slv"}, "H ", _("Slovenian"), "Slovenian.pattern" }, From ca8e9352ba962e48843cd1d86812e42bdade7708 Mon Sep 17 00:00:00 2001 From: Frans de Jonge Date: Wed, 20 Mar 2024 23:41:32 +0100 Subject: [PATCH 08/12] [i18n] Add en-GB and Romanian translation to UI (#11577) * Add en_GB translation to UI Follow-up to https://github.com/koreader/koreader-translations/pull/167 * Uncomment Romanian --- frontend/ui/language.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/ui/language.lua b/frontend/ui/language.lua index 25f30003d..00ea575f1 100644 --- a/frontend/ui/language.lua +++ b/frontend/ui/language.lua @@ -6,6 +6,7 @@ local Language = { language_names = { C = "English", en = "English", + en_GB = "English (United Kingdom)", ca = "Catalá", cs = "Čeština", da = "Dansk", @@ -118,6 +119,7 @@ function Language:getLangMenuTable() -- NOTE: language with no translation are commented out for now sub_item_table = { self:genLanguageSubItem("C"), + self:genLanguageSubItem("en_GB"), self:genLanguageSubItem("ca"), self:genLanguageSubItem("cs"), self:genLanguageSubItem("de"), @@ -138,7 +140,7 @@ function Language:getLangMenuTable() --self:genLanguageSubItem("pl_PL"), self:genLanguageSubItem("pt_PT"), self:genLanguageSubItem("pt_BR"), - --self:genLanguageSubItem("ro"), + self:genLanguageSubItem("ro"), self:genLanguageSubItem("ro_MD"), self:genLanguageSubItem("sk"), self:genLanguageSubItem("sv"), From ee7c3ab551f320ff0095c276bdadfac77beeee69 Mon Sep 17 00:00:00 2001 From: dkabot <1316469+dkabot@users.noreply.github.com> Date: Tue, 26 Mar 2024 09:49:17 -0400 Subject: [PATCH 09/12] ReaderPaging: enable Kindle page-turn animations (#11424) Fixes #11423. --- frontend/apps/reader/modules/readerpaging.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/apps/reader/modules/readerpaging.lua b/frontend/apps/reader/modules/readerpaging.lua index 3bf67199e..431e4e982 100644 --- a/frontend/apps/reader/modules/readerpaging.lua +++ b/frontend/apps/reader/modules/readerpaging.lua @@ -565,7 +565,7 @@ function ReaderPaging:onGotoPercent(percent) if dest > self.number_of_pages then dest = self.number_of_pages end - self:_gotoPage(dest) + self:onGotoPage(dest) return true end @@ -575,6 +575,7 @@ function ReaderPaging:onGotoViewRel(diff) else self:onGotoPageRel(diff) end + self.ui:handleEvent(Event:new("PageChangeAnimation", diff > 0)) self:setPagePosition(self:getTopPage(), self:getTopPosition()) return true end @@ -1127,8 +1128,11 @@ function ReaderPaging:_gotoPage(number, orig_mode) end function ReaderPaging:onGotoPage(number, pos) + local same_page = number == self.current_page; + local animation_direction = number > self.current_page; self:setPagePosition(number, 0) self:_gotoPage(number) + self.ui:handleEvent(Event:new("PageChangeAnimation", animation_direction)) if pos then local rect_p = Geom:new{ x = pos.x or 0, y = pos.y or 0 } local rect_s = Geom:new(rect_p):copy() @@ -1138,7 +1142,7 @@ function ReaderPaging:onGotoPage(number, pos) else self.view:PanningUpdate(rect_s.x - self.view.visible_area.x, rect_s.y - self.view.visible_area.y) end - elseif number == self.current_page then + elseif same_page then -- gotoPage emits this event only if the page changes self.ui:handleEvent(Event:new("PageUpdate", self.current_page)) end @@ -1157,14 +1161,14 @@ function ReaderPaging:onGotoRelativePage(number) end new_page = test_page end - self:_gotoPage(new_page) + self:onGotoPage(new_page) return true end function ReaderPaging:onGotoPercentage(percentage) if percentage < 0 then percentage = 0 end if percentage > 1 then percentage = 1 end - self:_gotoPage(math.floor(percentage*self.number_of_pages)) + self:onGotoPage(math.floor(percentage*self.number_of_pages)) return true end From 501cba6ebe696fe23128226000e75bde123a3e7f Mon Sep 17 00:00:00 2001 From: Denis Malinovsky Date: Fri, 29 Mar 2024 04:36:53 -0400 Subject: [PATCH 10/12] PocketBook: remove unused `color_saturation` parameter (#11597) Bumps base for https://github.com/koreader/koreader-base/pull/1751 Includes several build system improvements as well --- base | 2 +- frontend/device/pocketbook/device.lua | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/base b/base index da9280238..366d9c9ca 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit da9280238cd088fff9b100357a0155ac60e40197 +Subproject commit 366d9c9ca842748be76eaf948cc8719c9e51e494 diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index 21b35940b..3f212d878 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -598,7 +598,6 @@ local PocketBook632 = PocketBook:extend{ local PocketBook633 = PocketBook:extend{ model = "PBColor", display_dpi = 300, - color_saturation = 1.5, hasColorScreen = yes, canHWDither = yes, -- Adjust color saturation with inkview canUseCBB = no, -- 24bpp @@ -672,7 +671,6 @@ local PocketBook740_2 = PocketBook:extend{ local PocketBook741 = PocketBook:extend{ model = "PBInkPadColor", display_dpi = 300, - color_saturation = 1.5, hasColorScreen = yes, canHWDither = yes, -- Adjust color saturation with inkview canUseCBB = no, -- 24bpp @@ -689,7 +687,6 @@ end local PocketBook743C = PocketBook:extend{ model = "PBInkPadColor2", display_dpi = 300, - color_saturation = 1.5, hasColorScreen = yes, canHWDither = yes, -- Adjust color saturation with inkview canUseCBB = no, -- 24bpp @@ -708,7 +705,6 @@ local PocketBook743K3 = PocketBook:extend{ model = "PBInkPadColor3", display_dpi = 300, viewport = Geom:new{x=3, y=2, w=1395, h=1864}, - color_saturation = 1.5, hasColorScreen = yes, canHWDither = yes, -- Adjust color saturation with inkview canUseCBB = no, -- 24bpp @@ -735,7 +731,6 @@ local PocketBook743G = PocketBook:extend{ local PocketBookColorLux = PocketBook:extend{ model = "PBColorLux", display_dpi = 125, - color_saturation = 1.5, hasColorScreen = yes, canHWDither = yes, -- Adjust color saturation with inkview canUseCBB = no, -- 24bpp From fbd3e822feb1f7671fe2032f2a04cfe6c44a7004 Mon Sep 17 00:00:00 2001 From: SomeGuy <97603719+Commodore64user@users.noreply.github.com> Date: Fri, 29 Mar 2024 08:38:31 +0000 Subject: [PATCH 11/12] ReaderView: increase underline thickness (#11586) Closes #11581. --- frontend/apps/reader/modules/readerview.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/apps/reader/modules/readerview.lua b/frontend/apps/reader/modules/readerview.lua index 7c8279434..5ae97354c 100644 --- a/frontend/apps/reader/modules/readerview.lua +++ b/frontend/apps/reader/modules/readerview.lua @@ -632,7 +632,7 @@ function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark) if drawer == "lighten" then bb:lightenRect(x, y, w, h, self.highlight.lighten_factor) elseif drawer == "underscore" then - bb:paintRect(x, y + h - 1, w, Size.line.medium, Blitbuffer.COLOR_GRAY) + bb:paintRect(x, y + h - 1, w, Size.line.thick, Blitbuffer.COLOR_GRAY_4) elseif drawer == "strikeout" then local line_y = y + math.floor(h / 2) + 1 if self.ui.paging then From 42c93a7623c6d04a2001f943ddc5b0b0638e3a24 Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sat, 30 Mar 2024 14:04:43 +0100 Subject: [PATCH 12/12] FileChooser collates: use "item.sort_percent" for sorting + extra `on-hold` handling (#11592) re https://github.com/koreader/koreader/pull/11524#issuecomment-1984110990 re https://github.com/koreader/koreader/pull/11542#issuecomment-2018164346 re #11592 --- frontend/ui/widget/filechooser.lua | 31 ++++++++++++++++++------------ frontend/util.lua | 8 ++++++++ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 7bbfd03d4..592f867f5 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -172,7 +172,9 @@ local FileChooser = Menu:extend{ local doc_settings = DocSettings:open(item.path) percent_finished = doc_settings:readSetting("percent_finished") end - item.percent_finished = percent_finished or 0 + + -- smooth 2 decimal points (0.00) instead of 16 decimal points + item.percent_finished = util.round_decimal(percent_finished or 0, 2) end, mandatory_func = function(item) return item.opened and string.format("%d %%", 100 * item.percent_finished) or "–" @@ -200,14 +202,16 @@ local FileChooser = Menu:extend{ local doc_settings = DocSettings:open(item.path) percent_finished = doc_settings:readSetting("percent_finished") end - item.percent_finished = percent_finished or 0 + + -- smooth 2 decimal points (0.00) instead of 16 decimal points + item.percent_finished = util.round_decimal(percent_finished or 0, 2) end, mandatory_func = function(item) return item.opened and string.format("%d %%", 100 * item.percent_finished) or "–" end, }, percent_natural = { - -- sort 90% > 50% > 0% > unopened > 100% or finished + -- sort 90% > 50% > 0% or on hold > unopened > 100% or finished text = _("percent - unopened - finished last"), menu_order = 90, can_collate_mixed = false, @@ -215,14 +219,14 @@ local FileChooser = Menu:extend{ local natsort natsort, cache = sort.natsort_cmp(cache) local sortfunc = function(a, b) - if a.percent_finished == b.percent_finished then + if a.sort_percent == b.sort_percent then return natsort(a.text, b.text) - elseif a.percent_finished == 1 then + elseif a.sort_percent == 1 then return false - elseif b.percent_finished == 1 then + elseif b.sort_percent == 1 then return true else - return a.percent_finished > b.percent_finished + return a.sort_percent > b.sort_percent end end @@ -230,21 +234,24 @@ local FileChooser = Menu:extend{ end, item_func = function(item) local percent_finished + local sort_percent item.opened = DocSettings:hasSidecarFile(item.path) if item.opened then local doc_settings = DocSettings:open(item.path) local summary = doc_settings:readSetting("summary") - -- books marked as "finished" should be considered the same as 100% + -- books marked as "finished" or "on hold" should be considered the same as 100% and 0% respectively if summary and summary.status == "complete" then - item.percent_finished = 1.0 - return + sort_percent = 1.0 + elseif summary and summary.status == "abandoned" then + sort_percent = 0 end percent_finished = doc_settings:readSetting("percent_finished") end - -- smooth 2 decimal points (0.00) instead of 16 decimal numbers - item.percent_finished = math.floor((percent_finished or -1) * 100) / 100 + -- smooth 2 decimal points (0.00) instead of 16 decimal points + item.sort_percent = sort_percent or util.round_decimal(percent_finished or -1, 2) + item.percent_finished = percent_finished or 0 end, mandatory_func = function(item) return item.opened and string.format("%d %%", 100 * item.percent_finished) or "–" diff --git a/frontend/util.lua b/frontend/util.lua index 817b0b740..62c4cfd83 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -1537,4 +1537,12 @@ function util.wrapMethod(target_table, target_field_name, new_func, before_callb return wrapped end +-- Round a given "num" to the decimal points of "points" +-- (i.e. `round_decimal(0.000000001, 2)` will yield `0.00`) +function util.round_decimal(num, points) + local op = 10 ^ points + + return math.floor(num * op) / op +end + return util