|
|
|
@ -1,11 +1,15 @@
|
|
|
|
|
local BD = require("ui/bidi")
|
|
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
|
|
|
|
local CheckButton = require("ui/widget/checkbutton")
|
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
|
local InputDialog = require("ui/widget/inputdialog")
|
|
|
|
|
local Menu = require("ui/widget/menu")
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
|
local Screen = require("device").screen
|
|
|
|
|
local Utf8Proc = require("ffi/utf8proc")
|
|
|
|
|
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
|
|
|
|
local util = require("util")
|
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
local C_ = _.pgettext
|
|
|
|
|
local T = require("ffi/util").template
|
|
|
|
@ -15,12 +19,12 @@ local FileManagerHistory = WidgetContainer:extend{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
local filter_text = {
|
|
|
|
|
all = C_("Book status filter", "All"),
|
|
|
|
|
reading = C_("Book status filter", "Reading"),
|
|
|
|
|
all = C_("Book status filter", "All"),
|
|
|
|
|
reading = C_("Book status filter", "Reading"),
|
|
|
|
|
abandoned = C_("Book status filter", "On hold"),
|
|
|
|
|
complete = C_("Book status filter", "Finished"),
|
|
|
|
|
deleted = C_("Book status filter", "Deleted"),
|
|
|
|
|
new = C_("Book status filter", "New"),
|
|
|
|
|
complete = C_("Book status filter", "Finished"),
|
|
|
|
|
deleted = C_("Book status filter", "Deleted"),
|
|
|
|
|
new = C_("Book status filter", "New"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:init()
|
|
|
|
@ -64,7 +68,7 @@ function FileManagerHistory:updateItemTable()
|
|
|
|
|
reading = 0, abandoned = 0, complete = 0, deleted = 0, new = 0, }
|
|
|
|
|
local item_table = {}
|
|
|
|
|
for _, v in ipairs(require("readhistory").hist) do
|
|
|
|
|
if self.filter == "all" or v.status == self.filter then
|
|
|
|
|
if self:isItemMatch(v) then
|
|
|
|
|
if self.is_frozen and v.status == "complete" then
|
|
|
|
|
v.mandatory_dim = true
|
|
|
|
|
end
|
|
|
|
@ -75,18 +79,50 @@ function FileManagerHistory:updateItemTable()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
local title = self.hist_menu_title
|
|
|
|
|
if self.filter ~= "all" then
|
|
|
|
|
title = title .. " (" .. filter_text[self.filter] .. ": " .. self.count[self.filter] .. ")"
|
|
|
|
|
local filter_title
|
|
|
|
|
if self.search_string then
|
|
|
|
|
filter_title = _("search results")
|
|
|
|
|
elseif self.filter ~= "all" then
|
|
|
|
|
filter_title = filter_text[self.filter]:lower()
|
|
|
|
|
end
|
|
|
|
|
if filter_title then
|
|
|
|
|
title = title .. T(" (%1: %2)", filter_title, #item_table)
|
|
|
|
|
end
|
|
|
|
|
self.hist_menu:switchItemTable(title, item_table, select_number)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:isItemMatch(item)
|
|
|
|
|
if self.search_string then
|
|
|
|
|
local filename = self.case_sensitive and item.text or Utf8Proc.lowercase(util.fixUtf8(item.text, "?"))
|
|
|
|
|
if not filename:find(self.search_string) then
|
|
|
|
|
local book_props
|
|
|
|
|
if self.ui.coverbrowser then
|
|
|
|
|
book_props = self.ui.coverbrowser:getBookInfo(item.file)
|
|
|
|
|
end
|
|
|
|
|
if not book_props then
|
|
|
|
|
book_props = self.ui.bookinfo.getDocProps(item.file, nil, true) -- do not open the document
|
|
|
|
|
end
|
|
|
|
|
if not self.ui.bookinfo:findInProps(book_props, self.search_string, self.case_sensitive) then
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
return self.filter == "all" or item.status == self.filter
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:onSetDimensions(dimen)
|
|
|
|
|
self.dimen = dimen
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:onMenuChoice(item)
|
|
|
|
|
require("apps/reader/readerui"):showReader(item.file)
|
|
|
|
|
if self.ui.document then
|
|
|
|
|
if self.ui.document.file ~= item.file then
|
|
|
|
|
self.ui:switchDocument(item.file)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
|
ReaderUI:showReader(item.file)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:onMenuHold(item)
|
|
|
|
@ -153,7 +189,7 @@ function FileManagerHistory:onMenuHold(item)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
self.histfile_dialog = ButtonDialog:new{
|
|
|
|
|
title = BD.filename(item.text:match("([^/]+)$")),
|
|
|
|
|
title = BD.filename(item.text),
|
|
|
|
|
title_align = "center",
|
|
|
|
|
buttons = buttons,
|
|
|
|
|
}
|
|
|
|
@ -178,7 +214,7 @@ function FileManagerHistory:MenuSetRotationModeHandler(rotation)
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:onShowHist()
|
|
|
|
|
function FileManagerHistory:onShowHist(search_info)
|
|
|
|
|
self.hist_menu = Menu:new{
|
|
|
|
|
ui = self.ui,
|
|
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
|
|
|
@ -192,6 +228,12 @@ function FileManagerHistory:onShowHist()
|
|
|
|
|
_manager = self,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if search_info then
|
|
|
|
|
self.search_string = search_info.search_string
|
|
|
|
|
self.case_sensitive = search_info.case_sensitive
|
|
|
|
|
else
|
|
|
|
|
self.search_string = nil
|
|
|
|
|
end
|
|
|
|
|
self.filter = G_reader_settings:readSetting("history_filter", "all")
|
|
|
|
|
self.is_frozen = G_reader_settings:isTrue("history_freeze_finished_books")
|
|
|
|
|
if self.filter ~= "all" or self.is_frozen then
|
|
|
|
@ -200,14 +242,14 @@ function FileManagerHistory:onShowHist()
|
|
|
|
|
self:updateItemTable()
|
|
|
|
|
self.hist_menu.close_callback = function()
|
|
|
|
|
if self.files_updated then -- refresh Filemanager list of files
|
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
|
if FileManager.instance then
|
|
|
|
|
FileManager.instance:onRefresh()
|
|
|
|
|
if self.ui.file_chooser then
|
|
|
|
|
self.ui.file_chooser:refreshPath()
|
|
|
|
|
end
|
|
|
|
|
self.files_updated = nil
|
|
|
|
|
end
|
|
|
|
|
self.statuses_fetched = nil
|
|
|
|
|
UIManager:close(self.hist_menu)
|
|
|
|
|
self.hist_menu = nil
|
|
|
|
|
G_reader_settings:saveSetting("history_filter", self.filter)
|
|
|
|
|
end
|
|
|
|
|
UIManager:show(self.hist_menu)
|
|
|
|
@ -227,6 +269,9 @@ function FileManagerHistory:showHistDialog()
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:close(hist_dialog)
|
|
|
|
|
self.filter = filter
|
|
|
|
|
if filter == "all" then -- reset all filters
|
|
|
|
|
self.search_string = nil
|
|
|
|
|
end
|
|
|
|
|
self:updateItemTable()
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
@ -241,6 +286,15 @@ function FileManagerHistory:showHistDialog()
|
|
|
|
|
genFilterButton("abandoned"),
|
|
|
|
|
genFilterButton("complete"),
|
|
|
|
|
})
|
|
|
|
|
table.insert(buttons, {
|
|
|
|
|
{
|
|
|
|
|
text = _("Search in filename and book metadata"),
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:close(hist_dialog)
|
|
|
|
|
self:onSearchHistory()
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
if self.count.deleted > 0 then
|
|
|
|
|
table.insert(buttons, {}) -- separator
|
|
|
|
|
table.insert(buttons, {
|
|
|
|
@ -269,6 +323,57 @@ function FileManagerHistory:showHistDialog()
|
|
|
|
|
UIManager:show(hist_dialog)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:onSearchHistory()
|
|
|
|
|
local search_dialog, check_button_case
|
|
|
|
|
search_dialog = InputDialog:new{
|
|
|
|
|
title = _("Enter text to search history for"),
|
|
|
|
|
input = self.search_string,
|
|
|
|
|
buttons = {
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
text = _("Cancel"),
|
|
|
|
|
id = "close",
|
|
|
|
|
callback = function()
|
|
|
|
|
UIManager:close(search_dialog)
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = _("Search"),
|
|
|
|
|
is_enter_default = true,
|
|
|
|
|
callback = function()
|
|
|
|
|
local search_string = search_dialog:getInputText()
|
|
|
|
|
if search_string ~= "" then
|
|
|
|
|
UIManager:close(search_dialog)
|
|
|
|
|
self.search_string = self.case_sensitive and search_string or search_string:lower()
|
|
|
|
|
if self.hist_menu then -- called from History
|
|
|
|
|
self:updateItemTable()
|
|
|
|
|
else -- called by Dispatcher
|
|
|
|
|
local search_info = {
|
|
|
|
|
search_string = self.search_string,
|
|
|
|
|
case_sensitive = self.case_sensitive,
|
|
|
|
|
}
|
|
|
|
|
self:onShowHist(search_info)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
check_button_case = CheckButton:new{
|
|
|
|
|
text = _("Case sensitive"),
|
|
|
|
|
checked = self.case_sensitive,
|
|
|
|
|
parent = search_dialog,
|
|
|
|
|
callback = function()
|
|
|
|
|
self.case_sensitive = check_button_case.checked
|
|
|
|
|
end,
|
|
|
|
|
}
|
|
|
|
|
search_dialog:addWidget(check_button_case)
|
|
|
|
|
UIManager:show(search_dialog)
|
|
|
|
|
search_dialog:onShowKeyboard()
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function FileManagerHistory:onBookMetadataChanged()
|
|
|
|
|
if self.hist_menu then
|
|
|
|
|
self.hist_menu:updateItems()
|
|
|
|
|