CoverBrowser: do not call lfs on every item (#11449)

reviewable/pr11456/r1
hius07 3 months ago committed by GitHub
parent b8090c641c
commit 50fcc04725
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -27,7 +27,6 @@ local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan") local VerticalSpan = require("ui/widget/verticalspan")
local WidgetContainer = require("ui/widget/container/widgetcontainer") local WidgetContainer = require("ui/widget/container/widgetcontainer")
local filemanagerutil = require("apps/filemanager/filemanagerutil") local filemanagerutil = require("apps/filemanager/filemanagerutil")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger") local logger = require("logger")
local util = require("util") local util = require("util")
local _ = require("gettext") local _ = require("gettext")
@ -115,7 +114,7 @@ local ListMenuItem = InputContainer:extend{
} }
function ListMenuItem:init() function ListMenuItem:init()
-- filepath may be provided as 'file' (history) or 'path' (filechooser) -- filepath may be provided as 'file' (history, collection) or 'path' (filechooser)
-- store it as attribute so we can use it elsewhere -- store it as attribute so we can use it elsewhere
self.filepath = self.entry.file or self.entry.path self.filepath = self.entry.file or self.entry.path
@ -224,9 +223,8 @@ function ListMenuItem:update()
self.menu.cover_specs = false self.menu.cover_specs = false
end end
local file_mode = lfs.attributes(self.filepath, "mode") self.is_directory = not (self.entry.is_file or self.entry.file)
if file_mode == "directory" then if self.is_directory then
self.is_directory = true
-- nb items on the right, directory name on the left -- nb items on the right, directory name on the left
local wright = TextWidget:new{ local wright = TextWidget:new{
text = self.mandatory or "", text = self.mandatory or "",
@ -261,13 +259,9 @@ function ListMenuItem:update()
}, },
}, },
} }
else else -- file
local is_file_selected = self.menu.filemanager and self.menu.filemanager.selected_files self.file_deleted = self.entry.dim -- entry with deleted file from History or selected file from FM
and self.menu.filemanager.selected_files[self.filepath] local fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil
if file_mode ~= "file" or is_file_selected then
self.file_deleted = true -- dim file
end
-- File
local bookinfo = BookInfoManager:getBookInfo(self.filepath, self.do_cover_image) local bookinfo = BookInfoManager:getBookInfo(self.filepath, self.do_cover_image)
@ -437,7 +431,7 @@ function ListMenuItem:update()
local wfileinfo = TextWidget:new{ local wfileinfo = TextWidget:new{
text = fileinfo_str, text = fileinfo_str,
face = Font:getFace("cfont", fontsize_info), face = Font:getFace("cfont", fontsize_info),
fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil, fgcolor = fgcolor,
} }
table.insert(wright_items, wfileinfo) table.insert(wright_items, wfileinfo)
end end
@ -446,7 +440,7 @@ function ListMenuItem:update()
local wpageinfo = TextWidget:new{ local wpageinfo = TextWidget:new{
text = pages_str, text = pages_str,
face = Font:getFace("cfont", fontsize_info), face = Font:getFace("cfont", fontsize_info),
fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil, fgcolor = fgcolor,
} }
table.insert(wright_items, wpageinfo) table.insert(wright_items, wpageinfo)
end end
@ -584,7 +578,7 @@ function ListMenuItem:update()
height_overflow_show_ellipsis = true, height_overflow_show_ellipsis = true,
alignment = "left", alignment = "left",
bold = true, bold = true,
fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil, fgcolor = fgcolor,
} }
end end
local build_authors = function(height) local build_authors = function(height)
@ -601,7 +595,7 @@ function ListMenuItem:update()
height_adjust = true, height_adjust = true,
height_overflow_show_ellipsis = true, height_overflow_show_ellipsis = true,
alignment = "left", alignment = "left",
fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil, fgcolor = fgcolor,
} }
end end
while true do while true do
@ -727,7 +721,7 @@ function ListMenuItem:update()
local wfileinfo = TextWidget:new{ local wfileinfo = TextWidget:new{
text = fileinfo_str, text = fileinfo_str,
face = Font:getFace("cfont", fontsize_info), face = Font:getFace("cfont", fontsize_info),
fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil, fgcolor = fgcolor,
} }
local wpageinfo = TextWidget:new{ -- Empty but needed for similar positionning local wpageinfo = TextWidget:new{ -- Empty but needed for similar positionning
text = "", text = "",
@ -762,7 +756,7 @@ function ListMenuItem:update()
face = Font:getFace("cfont", fontsize_no_bookinfo), face = Font:getFace("cfont", fontsize_no_bookinfo),
width = dimen.w - 2 * Screen:scaleBySize(10) - wright_width - wright_right_padding, width = dimen.w - 2 * Screen:scaleBySize(10) - wright_width - wright_right_padding,
alignment = "left", alignment = "left",
fgcolor = self.file_deleted and Blitbuffer.COLOR_DARK_GRAY or nil, fgcolor = fgcolor,
} }
-- reduce font size for next loop, in case text widget is too large to fit into ListMenuItem -- reduce font size for next loop, in case text widget is too large to fit into ListMenuItem
fontsize_no_bookinfo = fontsize_no_bookinfo - fontsize_dec_step fontsize_no_bookinfo = fontsize_no_bookinfo - fontsize_dec_step

@ -25,7 +25,6 @@ local UnderlineContainer = require("ui/widget/container/underlinecontainer")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan") local VerticalSpan = require("ui/widget/verticalspan")
local WidgetContainer = require("ui/widget/container/widgetcontainer") local WidgetContainer = require("ui/widget/container/widgetcontainer")
local lfs = require("libs/libkoreader-lfs")
local logger = require("logger") local logger = require("logger")
local util = require("util") local util = require("util")
local _ = require("gettext") local _ = require("gettext")
@ -462,9 +461,8 @@ function MosaicMenuItem:update()
self.menu.cover_specs = false self.menu.cover_specs = false
end end
local file_mode = lfs.attributes(self.filepath, "mode") self.is_directory = not (self.entry.is_file or self.entry.file)
if file_mode == "directory" then if self.is_directory then
self.is_directory = true
-- Directory : rounded corners -- Directory : rounded corners
local margin = Screen:scaleBySize(5) -- make directories less wide local margin = Screen:scaleBySize(5) -- make directories less wide
local padding = Screen:scaleBySize(5) local padding = Screen:scaleBySize(5)
@ -528,13 +526,8 @@ function MosaicMenuItem:update()
BottomContainer:new{ dimen = dimen_in, nbitems}, BottomContainer:new{ dimen = dimen_in, nbitems},
}, },
} }
else else -- file
local is_file_selected = self.menu.filemanager and self.menu.filemanager.selected_files self.file_deleted = self.entry.dim -- entry with deleted file from History or selected file from FM
and self.menu.filemanager.selected_files[self.filepath]
if file_mode ~= "file" or is_file_selected then
self.file_deleted = true -- dim file
end
-- File : various appearances
if self.do_hint_opened and DocSettings:hasSidecarFile(self.filepath) then if self.do_hint_opened and DocSettings:hasSidecarFile(self.filepath) then
self.been_opened = true self.been_opened = true

Loading…
Cancel
Save