diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index 641d0cac9..c7f9e3aa8 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -1,4 +1,5 @@ local BD = require("ui/bidi") +local BookList = require("ui/widget/booklist") local CenterContainer = require("ui/widget/container/centercontainer") local ConfirmBox = require("ui/widget/confirmbox") local Device = require("device") @@ -155,11 +156,6 @@ function FileManagerMenu:setUpdateItemTable() self.menu_items.filebrowser_settings = { text = _("Settings"), sub_item_table = { - { - text = _("Show finished books"), - checked_func = function() return FileChooser.show_finished end, - callback = function() FileChooser:toggleShowFilesMode("show_finished") end, - }, { text = _("Show hidden files"), checked_func = function() return FileChooser.show_hidden end, @@ -453,6 +449,7 @@ To: end end + self.menu_items.show_filter = self:getShowFilterMenuTable() self.menu_items.sort_by = self:getSortingMenuTable() self.menu_items.reverse_sorting = { text = _("Reverse sorting"), @@ -884,6 +881,64 @@ dbg:guard(FileManagerMenu, 'setUpdateItemTable', end end) +function FileManagerMenu:getShowFilterMenuTable() + local FileChooser = require("ui/widget/filechooser") + local statuses = { "new", "reading", "abandoned", "complete" } + local sub_item_table = { + { + text = BookList.getBookStatusString("all"):lower(), + checked_func = function() + return FileChooser.show_filter.status == nil + end, + radio = true, + callback = function() + FileChooser.show_filter.status = nil + self.ui.file_chooser:refreshPath() + end, + separator = true, + }, + } + for _, v in ipairs(statuses) do + table.insert(sub_item_table, { + text = BookList.getBookStatusString(v):lower(), + checked_func = function() + return FileChooser.show_filter.status and FileChooser.show_filter.status[v] + end, + callback = function() + FileChooser.show_filter.status = FileChooser.show_filter.status or {} + FileChooser.show_filter.status[v] = not FileChooser.show_filter.status[v] or nil + local statuses_nb = util.tableSize(FileChooser.show_filter.status) + if statuses_nb == 0 or statuses_nb == #statuses then + FileChooser.show_filter.status = nil + end + self.ui.file_chooser:refreshPath() + end, + }) + end + return { + text_func = function() + local text + if FileChooser.show_filter.status == nil then + text = BookList.getBookStatusString("all"):lower() + else + for _, v in ipairs(statuses) do + if FileChooser.show_filter.status[v] then + local status_string = BookList.getBookStatusString(v):lower() + text = text and text .. ", " .. status_string or status_string + end + end + end + return T(_("Book status: %1"), text) + end, + sub_item_table = sub_item_table, + hold_callback = function(touchmenu_instance) + FileChooser.show_filter.status = nil + self.ui.file_chooser:refreshPath() + touchmenu_instance:updateItems() + end, + } +end + function FileManagerMenu:getSortingMenuTable() local sub_item_table = { max_per_page = 9, -- metadata collates in page 2 diff --git a/frontend/ui/data/onetime_migration.lua b/frontend/ui/data/onetime_migration.lua index 661c84df0..01958ec64 100644 --- a/frontend/ui/data/onetime_migration.lua +++ b/frontend/ui/data/onetime_migration.lua @@ -12,7 +12,7 @@ local util = require("util") local _ = require("gettext") -- Date at which the last migration snippet was added -local CURRENT_MIGRATION_DATE = 20250318 +local CURRENT_MIGRATION_DATE = 20250405 -- Retrieve the date of the previous migration, if any local last_migration_date = G_reader_settings:readSetting("last_migration_date", 0) @@ -869,5 +869,22 @@ if last_migration_date < 20250318 then end end +-- 20250405, Modify file browser show_finished setting to show_filter table. +-- https://github.com/koreader/koreader/pull/13503 +if last_migration_date < 20250405 then + logger.info("Performing one-time migration for 20250405") + + if G_reader_settings:isFalse("show_finished") then + G_reader_settings:saveSetting("show_filter", { + status = { + new = true, + reading = true, + abandoned = true, + }, + }) + end + G_reader_settings:delSetting("show_finished") +end + -- We're done, store the current migration date G_reader_settings:saveSetting("last_migration_date", CURRENT_MIGRATION_DATE) diff --git a/frontend/ui/elements/filemanager_menu_order.lua b/frontend/ui/elements/filemanager_menu_order.lua index e78dd019b..338deb238 100644 --- a/frontend/ui/elements/filemanager_menu_order.lua +++ b/frontend/ui/elements/filemanager_menu_order.lua @@ -13,6 +13,7 @@ local order = { "filemanager_display_mode", "filebrowser_settings", "----------------------------", + "show_filter", "sort_by", "reverse_sorting", "sort_mixed", diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 62001e58d..e50efac27 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -20,7 +20,7 @@ local FileChooser = BookList:extend{ path = lfs.currentdir(), show_path = true, parent = nil, - show_finished = G_reader_settings:readSetting("show_finished", true), -- books marked as finished + show_filter = G_reader_settings:readSetting("show_filter", {}), show_hidden = G_reader_settings:readSetting("show_hidden", false), -- folders/files starting with "." show_unsupported = G_reader_settings:readSetting("show_unsupported", false), -- set to true to ignore file_filter file_filter = nil, -- function defined in the caller, returns true for files to be shown @@ -92,7 +92,8 @@ function FileChooser:show_file(filename, fullpath) if filename:match(pattern) then return false end end if not self.show_unsupported and self.file_filter ~= nil and not self.file_filter(filename) then return false end - if not FileChooser.show_finished and fullpath ~= nil and BookList.getBookStatus(fullpath) == "complete" then return false end + if FileChooser.show_filter.status and fullpath ~= nil + and not FileChooser.show_filter.status[BookList.getBookStatus(fullpath)] then return false end return true end @@ -397,7 +398,7 @@ function FileChooser:changePageToPath(path) end function FileChooser:toggleShowFilesMode(mode) - -- modes: "show_finished", "show_hidden", "show_unsupported" + -- modes: "show_hidden", "show_unsupported" FileChooser[mode] = not FileChooser[mode] G_reader_settings:saveSetting(mode, FileChooser[mode]) self:refreshPath() @@ -429,11 +430,11 @@ function FileChooser:onFileHold(item) end function FileChooser:getNextOrPreviousFileInFolder(curr_file, prev) - local show_finished = FileChooser.show_finished - FileChooser.show_finished = true + local show_filter = FileChooser.show_filter + FileChooser.show_filter = {} local curr_path = curr_file:match(".*/"):gsub("/$", "") local item_table = self:genItemTableFromPath(curr_path) - FileChooser.show_finished = show_finished + FileChooser.show_filter = show_filter local top_i, step, is_curr_file_found if prev then top_i = #item_table + 1