From eb299c300d015203bc67792b37219648cb1760d1 Mon Sep 17 00:00:00 2001 From: hius07 <62179190+hius07@users.noreply.github.com> Date: Mon, 3 Jul 2023 08:24:28 +0300 Subject: [PATCH] FileChooser: Sort by date (#10627) --- frontend/apps/filemanager/filemanagermenu.lua | 4 +--- frontend/ui/data/onetime_migration.lua | 11 ++++++++++- frontend/ui/widget/filechooser.lua | 19 ++++--------------- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index 507ac7a29..de3aa20e3 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -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" }, diff --git a/frontend/ui/data/onetime_migration.lua b/frontend/ui/data/onetime_migration.lua index a0865f16c..5707efa50 100644 --- a/frontend/ui/data/onetime_migration.lua +++ b/frontend/ui/data/onetime_migration.lua @@ -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) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index ea5bff7c9..e65046d28 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -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