mirror of
https://github.com/koreader/koreader.git
synced 2025-12-18 12:02:09 +01:00
FileChooser: Sort by date (#10627)
This commit is contained in:
@@ -844,9 +844,7 @@ function FileManagerMenu:getSortingMenuTable()
|
|||||||
local collates = {
|
local collates = {
|
||||||
{ _("name"), "strcoll" },
|
{ _("name"), "strcoll" },
|
||||||
{ _("name (natural sorting)"), "natural" },
|
{ _("name (natural sorting)"), "natural" },
|
||||||
{ _("last read date"), "access" },
|
{ _("date modified"), "date" },
|
||||||
{ _("date added"), "change" },
|
|
||||||
{ _("date modified"), "modification" },
|
|
||||||
{ _("size"), "size" },
|
{ _("size"), "size" },
|
||||||
{ _("type"), "type" },
|
{ _("type"), "type" },
|
||||||
{ _("percent – unopened first"), "percent_unopened_first" },
|
{ _("percent – unopened first"), "percent_unopened_first" },
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ local lfs = require("libs/libkoreader-lfs")
|
|||||||
local logger = require("logger")
|
local logger = require("logger")
|
||||||
|
|
||||||
-- Date at which the last migration snippet was added
|
-- 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
|
-- Retrieve the date of the previous migration, if any
|
||||||
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
|
local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0)
|
||||||
@@ -557,5 +557,14 @@ if last_migration_date < 20230627 then
|
|||||||
end
|
end
|
||||||
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
|
-- We're done, store the current migration date
|
||||||
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)
|
G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local BD = require("ui/bidi")
|
local BD = require("ui/bidi")
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
|
local datetime = require("datetime")
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
local DocSettings = require("docsettings")
|
local DocSettings = require("docsettings")
|
||||||
local DocumentRegistry = require("document/documentregistry")
|
local DocumentRegistry = require("document/documentregistry")
|
||||||
@@ -192,15 +193,7 @@ function FileChooser:getSortingFunction(collate, reverse_collate)
|
|||||||
sorting = function(a, b)
|
sorting = function(a, b)
|
||||||
return natsort(a.text, b.text)
|
return natsort(a.text, b.text)
|
||||||
end
|
end
|
||||||
elseif collate == "access" then
|
elseif collate == "date" 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
|
|
||||||
sorting = function(a, b)
|
sorting = function(a, b)
|
||||||
return a.attr.modification > b.attr.modification
|
return a.attr.modification > b.attr.modification
|
||||||
end
|
end
|
||||||
@@ -347,12 +340,8 @@ function FileChooser:getMenuItemMandatory(item, collate)
|
|||||||
local text
|
local text
|
||||||
if collate then -- file
|
if collate then -- file
|
||||||
-- display the sorting parameter in mandatory
|
-- display the sorting parameter in mandatory
|
||||||
if collate == "access" then
|
if collate == "date" then
|
||||||
text = os.date("%Y-%m-%d %H:%M", item.attr.access)
|
text = datetime.secondsToDateTime(item.attr.modification)
|
||||||
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)
|
|
||||||
elseif collate == "percent_unopened_first" or collate == "percent_unopened_last" then
|
elseif collate == "percent_unopened_first" or collate == "percent_unopened_last" then
|
||||||
text = item.opened and string.format("%d %%", 100 * item.percent_finished) or "–"
|
text = item.opened and string.format("%d %%", 100 * item.percent_finished) or "–"
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user