FileChooser: Sort by date (#10627)

reviewable/pr10637/r1
hius07 10 months ago committed by GitHub
parent adfbbd9903
commit eb299c300d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -844,9 +844,7 @@ function FileManagerMenu:getSortingMenuTable()
local collates = {
{ _("name"), "strcoll" },
{ _("name (natural sorting)"), "natural" },
{ _("last read date"), "access" },
{ _("date added"), "change" },
{ _("date modified"), "modification" },
{ _("date modified"), "date" },
{ _("size"), "size" },
{ _("type"), "type" },
{ _("percent unopened first"), "percent_unopened_first" },

@ -7,7 +7,7 @@ local lfs = require("libs/libkoreader-lfs")
local logger = require("logger")
-- Date at which the last migration snippet was added
local CURRENT_MIGRATION_DATE = 20230627
local CURRENT_MIGRATION_DATE = 20230703
-- Retrieve the date of the previous migration, if any
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
@ -557,5 +557,14 @@ if last_migration_date < 20230627 then
end
end
-- 20230703, FileChooser Sort by: "date modified" only
if last_migration_date < 20230703 then
logger.info("Performing one-time migration for 20230703")
local collate = G_reader_settings:readSetting("collate")
if collate == "modification" or collate == "access" or collate == "change" then
G_reader_settings:saveSetting("collate", "date")
end
end
-- We're done, store the current migration date
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)

@ -1,5 +1,6 @@
local BD = require("ui/bidi")
local ConfirmBox = require("ui/widget/confirmbox")
local datetime = require("datetime")
local Device = require("device")
local DocSettings = require("docsettings")
local DocumentRegistry = require("document/documentregistry")
@ -192,15 +193,7 @@ function FileChooser:getSortingFunction(collate, reverse_collate)
sorting = function(a, b)
return natsort(a.text, b.text)
end
elseif collate == "access" then
sorting = function(a, b)
return a.attr.access > b.attr.access
end
elseif collate == "change" then
sorting = function(a, b)
return a.attr.change > b.attr.change
end
elseif collate == "modification" then
elseif collate == "date" then
sorting = function(a, b)
return a.attr.modification > b.attr.modification
end
@ -347,12 +340,8 @@ function FileChooser:getMenuItemMandatory(item, collate)
local text
if collate then -- file
-- display the sorting parameter in mandatory
if collate == "access" then
text = os.date("%Y-%m-%d %H:%M", item.attr.access)
elseif collate == "change" then
text = os.date("%Y-%m-%d %H:%M", item.attr.change)
elseif collate == "modification" then
text = os.date("%Y-%m-%d %H:%M", item.attr.modification)
if collate == "date" then
text = datetime.secondsToDateTime(item.attr.modification)
elseif collate == "percent_unopened_first" or collate == "percent_unopened_last" then
text = item.opened and string.format("%d %%", 100 * item.percent_finished) or ""
else

Loading…
Cancel
Save