|
|
|
local BD = require("ui/bidi")
|
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
|
|
local Menu = require("ui/widget/menu")
|
|
|
|
local UIManager = require("ui/uimanager")
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2 years ago
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
|
|
|
local Screen = require("device").screen
|
|
|
|
local filemanagerutil = require("apps/filemanager/filemanagerutil")
|
|
|
|
local _ = require("gettext")
|
|
|
|
local C_ = _.pgettext
|
|
|
|
local T = require("ffi/util").template
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2 years ago
|
|
|
local FileManagerHistory = WidgetContainer:extend{
|
|
|
|
hist_menu_title = _("History"),
|
|
|
|
}
|
|
|
|
|
|
|
|
local filter_text = {
|
|
|
|
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"),
|
|
|
|
}
|
|
|
|
|
|
|
|
function FileManagerHistory:init()
|
|
|
|
self.ui.menu:registerToMainMenu(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:addToMainMenu(menu_items)
|
|
|
|
menu_items.history = {
|
|
|
|
text = self.hist_menu_title,
|
|
|
|
callback = function()
|
|
|
|
self:onShowHist()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:fetchStatuses(count)
|
|
|
|
for _, v in ipairs(require("readhistory").hist) do
|
|
|
|
local status
|
|
|
|
if v.dim then -- deleted file
|
|
|
|
status = "deleted"
|
|
|
|
elseif v.file == (self.ui.document and self.ui.document.file) then -- currently opened file
|
|
|
|
status = self.ui.doc_settings:readSetting("summary").status
|
|
|
|
else
|
|
|
|
status = filemanagerutil.getStatus(v.file)
|
|
|
|
end
|
|
|
|
if count then
|
|
|
|
self.count[status] = self.count[status] + 1
|
|
|
|
end
|
|
|
|
v.status = status
|
|
|
|
end
|
|
|
|
self.statuses_fetched = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:updateItemTable()
|
|
|
|
-- try to stay on current page
|
|
|
|
local select_number = nil
|
|
|
|
if self.hist_menu.page and self.hist_menu.perpage and self.hist_menu.page > 0 then
|
|
|
|
select_number = (self.hist_menu.page - 1) * self.hist_menu.perpage + 1
|
|
|
|
end
|
|
|
|
self.count = { all = #require("readhistory").hist,
|
|
|
|
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.is_frozen and v.status == "complete" then
|
|
|
|
v.mandatory_dim = true
|
|
|
|
end
|
|
|
|
table.insert(item_table, v)
|
|
|
|
end
|
|
|
|
if self.statuses_fetched then
|
|
|
|
self.count[v.status] = self.count[v.status] + 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local title = self.hist_menu_title
|
|
|
|
if self.filter ~= "all" then
|
|
|
|
title = title .. " (" .. filter_text[self.filter] .. ": " .. self.count[self.filter] .. ")"
|
|
|
|
end
|
|
|
|
self.hist_menu:switchItemTable(title, item_table, select_number)
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:onSetDimensions(dimen)
|
|
|
|
self.dimen = dimen
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:onMenuChoice(item)
|
|
|
|
require("apps/reader/readerui"):showReader(item.file)
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:onMenuHold(item)
|
|
|
|
self.histfile_dialog = nil
|
|
|
|
local function close_dialog_callback()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
end
|
|
|
|
local function close_dialog_menu_callback()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
self._manager.hist_menu.close_callback()
|
|
|
|
end
|
|
|
|
local function status_button_callback()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
if self._manager.filter ~= "all" then
|
|
|
|
self._manager:fetchStatuses(false)
|
|
|
|
else
|
|
|
|
self._manager.statuses_fetched = false
|
|
|
|
end
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
self._manager.files_updated = true -- sidecar folder may be created/deleted
|
|
|
|
end
|
|
|
|
local is_currently_opened = item.file == (self.ui.document and self.ui.document.file)
|
|
|
|
|
|
|
|
local buttons = {}
|
|
|
|
if not item.dim then
|
|
|
|
local doc_settings_or_file = is_currently_opened and self.ui.doc_settings or item.file
|
|
|
|
table.insert(buttons, filemanagerutil.genStatusButtonsRow(doc_settings_or_file, status_button_callback))
|
|
|
|
table.insert(buttons, {}) -- separator
|
|
|
|
end
|
|
|
|
table.insert(buttons, {
|
|
|
|
filemanagerutil.genResetSettingsButton(item.file, status_button_callback, is_currently_opened),
|
|
|
|
filemanagerutil.genAddRemoveFavoritesButton(item.file, close_dialog_callback, item.dim),
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
{
|
|
|
|
text = _("Delete"),
|
|
|
|
enabled = not (item.dim or is_currently_opened),
|
|
|
|
callback = function()
|
|
|
|
local function post_delete_callback()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
self._manager.files_updated = true
|
|
|
|
end
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
FileManager:showDeleteFileDialog(item.file, post_delete_callback)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Remove from history"),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(self.histfile_dialog)
|
|
|
|
require("readhistory"):removeItem(item)
|
|
|
|
self._manager:updateItemTable()
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
filemanagerutil.genShowFolderButton(item.file, close_dialog_menu_callback, item.dim),
|
|
|
|
filemanagerutil.genBookInformationButton(item.file, close_dialog_callback, item.dim),
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
filemanagerutil.genBookCoverButton(item.file, close_dialog_callback, item.dim),
|
|
|
|
filemanagerutil.genBookDescriptionButton(item.file, close_dialog_callback, item.dim),
|
|
|
|
})
|
|
|
|
|
|
|
|
self.histfile_dialog = ButtonDialog:new{
|
|
|
|
title = BD.filename(item.text:match("([^/]+)$")),
|
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
|
|
|
UIManager:show(self.histfile_dialog)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Can't *actually* name it onSetRotationMode, or it also fires in FM itself ;).
|
|
|
|
function FileManagerHistory:MenuSetRotationModeHandler(rotation)
|
|
|
|
if rotation ~= nil and rotation ~= Screen:getRotationMode() then
|
|
|
|
UIManager:close(self._manager.hist_menu)
|
|
|
|
-- Also re-layout ReaderView or FileManager itself
|
|
|
|
if self._manager.ui.view and self._manager.ui.view.onSetRotationMode then
|
|
|
|
self._manager.ui.view:onSetRotationMode(rotation)
|
|
|
|
elseif self._manager.ui.onSetRotationMode then
|
|
|
|
self._manager.ui:onSetRotationMode(rotation)
|
|
|
|
else
|
|
|
|
Screen:setRotationMode(rotation)
|
|
|
|
end
|
|
|
|
self._manager:onShowHist()
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:onShowHist()
|
|
|
|
self.hist_menu = Menu:new{
|
|
|
|
ui = self.ui,
|
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
|
|
|
is_borderless = true,
|
|
|
|
is_popout = false,
|
|
|
|
title_bar_left_icon = "appbar.menu",
|
|
|
|
onLeftButtonTap = function() self:showHistDialog() end,
|
|
|
|
onMenuChoice = self.onMenuChoice,
|
|
|
|
onMenuHold = self.onMenuHold,
|
|
|
|
onSetRotationMode = self.MenuSetRotationModeHandler,
|
|
|
|
_manager = self,
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
self:fetchStatuses(false)
|
|
|
|
end
|
|
|
|
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()
|
|
|
|
end
|
|
|
|
self.files_updated = nil
|
|
|
|
end
|
|
|
|
self.statuses_fetched = nil
|
ReaderUI: Saner FM/RD lifecycle
* Ensure that going from one to the other tears down the former and
its plugins before instantiating the latter and its plugins.
UIManager: Unify Event sending & broadcasting
* Make the two behave the same way (walk the widget stack from top to
bottom), and properly handle the window stack shrinking shrinking
*and* growing.
Previously, broadcasting happened bottom-to-top and didn't really
handle the list shrinking/growing, while sending only handled the list
shrinking by a single element, and hopefully that element being the one
the event was just sent to.
These two items combined allowed us to optimize suboptimal
refresh behavior with Menu and other Menu classes when
opening/closing a document.
e.g., the "opening document" Notification is now properly regional,
and the "open last doc" option no longer flashes like a crazy person
anymore.
Plugins: Allow optimizing Menu refresh with custom menus, too.
Requires moving Menu's close_callback *after* onMenuSelect, which, eh,
probably makes sense, and is probably harmless in the grand scheme of
things.
3 years ago
|
|
|
UIManager:close(self.hist_menu)
|
|
|
|
G_reader_settings:saveSetting("history_filter", self.filter)
|
|
|
|
end
|
|
|
|
UIManager:show(self.hist_menu)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:showHistDialog()
|
|
|
|
if not self.statuses_fetched then
|
|
|
|
self:fetchStatuses(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
local hist_dialog
|
|
|
|
local buttons = {}
|
|
|
|
local function genFilterButton(filter)
|
|
|
|
return {
|
|
|
|
text = T(_("%1 (%2)"), filter_text[filter], self.count[filter]),
|
|
|
|
callback = function()
|
|
|
|
UIManager:close(hist_dialog)
|
|
|
|
self.filter = filter
|
|
|
|
self:updateItemTable()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
table.insert(buttons, {
|
|
|
|
genFilterButton("all"),
|
|
|
|
genFilterButton("new"),
|
|
|
|
genFilterButton("deleted"),
|
|
|
|
})
|
|
|
|
table.insert(buttons, {
|
|
|
|
genFilterButton("reading"),
|
|
|
|
genFilterButton("abandoned"),
|
|
|
|
genFilterButton("complete"),
|
|
|
|
})
|
|
|
|
if self.count.deleted > 0 then
|
|
|
|
table.insert(buttons, {}) -- separator
|
|
|
|
table.insert(buttons, {
|
|
|
|
{
|
|
|
|
text = _("Clear history of deleted files"),
|
|
|
|
callback = function()
|
|
|
|
local confirmbox = ConfirmBox:new{
|
|
|
|
text = _("Clear history of deleted files?"),
|
|
|
|
ok_text = _("Clear"),
|
|
|
|
ok_callback = function()
|
|
|
|
UIManager:close(hist_dialog)
|
|
|
|
require("readhistory"):clearMissing()
|
|
|
|
self:updateItemTable()
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
UIManager:show(confirmbox)
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
end
|
|
|
|
hist_dialog = ButtonDialog:new{
|
|
|
|
title = _("Filter by book status"),
|
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
|
|
|
UIManager:show(hist_dialog)
|
|
|
|
end
|
|
|
|
|
|
|
|
function FileManagerHistory:onBookMetadataChanged()
|
|
|
|
if self.hist_menu then
|
|
|
|
self.hist_menu:updateItems()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return FileManagerHistory
|