mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Filemanager - sort by percent of book (#3614)
This commit is contained in:
@@ -689,6 +689,8 @@ function FileManager:getSortingMenuTable()
|
||||
modification = {_("date modified"), _("Sort by date modified")},
|
||||
size = {_("size"), _("Sort by size")},
|
||||
type = {_("type"), _("Sort by type")},
|
||||
percent_unopened_first = {_("percent - unopened first"), _("Sort by percent - unopened first")},
|
||||
percent_unopened_last = {_("percent - unopened last"), _("Sort by percent - unopened last")},
|
||||
}
|
||||
local set_collate_table = function(collate)
|
||||
return {
|
||||
@@ -713,6 +715,8 @@ function FileManager:getSortingMenuTable()
|
||||
set_collate_table("modification"),
|
||||
set_collate_table("size"),
|
||||
set_collate_table("type"),
|
||||
set_collate_table("percent_unopened_first"),
|
||||
set_collate_table("percent_unopened_last"),
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -64,10 +64,19 @@ function FileChooser:init()
|
||||
end
|
||||
elseif attributes.mode == "file" then
|
||||
if self.file_filter == nil or self.file_filter(filename) then
|
||||
local percent_finished = 0
|
||||
if DocSettings:hasSidecarFile(filename) then
|
||||
local docinfo = DocSettings:open(filename)
|
||||
percent_finished = docinfo.data.percent_finished
|
||||
if percent_finished == nil then
|
||||
percent_finished = 0
|
||||
end
|
||||
end
|
||||
table.insert(files, {name = f,
|
||||
suffix = getFileNameSuffix(f),
|
||||
fullpath = filename,
|
||||
attr = attributes})
|
||||
attr = attributes,
|
||||
percent_finished = percent_finished })
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -145,6 +154,31 @@ function FileChooser:genItemTableFromPath(path)
|
||||
return self.strcoll(a.suffix, b.suffix)
|
||||
end
|
||||
end
|
||||
elseif self.collate == "percent_unopened_first" or self.collate == "percent_unopened_last" then
|
||||
sorting = function(a, b)
|
||||
if DocSettings:hasSidecarFile(a.fullpath) and not DocSettings:hasSidecarFile(b.fullpath) then
|
||||
if self.collate == "percent_unopened_first" then
|
||||
return false
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
if not DocSettings:hasSidecarFile(a.fullpath) and DocSettings:hasSidecarFile(b.fullpath) then
|
||||
if self.collate == "percent_unopened_first" then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
if not DocSettings:hasSidecarFile(a.fullpath) and not DocSettings:hasSidecarFile(b.fullpath) then
|
||||
return a.name < b.name
|
||||
end
|
||||
|
||||
if a.attr.mode == "directory" then return a.name < b.name end
|
||||
if b.attr.mode == "directory" then return a.name < b.name end
|
||||
|
||||
return a.percent_finished < b.percent_finished
|
||||
end
|
||||
else
|
||||
sorting = function(a, b)
|
||||
return a.name < b.name
|
||||
|
||||
Reference in New Issue
Block a user