mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
* 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.
86 lines
2.4 KiB
Lua
86 lines
2.4 KiB
Lua
local BD = require("ui/bidi")
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
local OPDSBrowser = require("opdsbrowser")
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
local UIManager = require("ui/uimanager")
|
|
local logger = require("logger")
|
|
local _ = require("gettext")
|
|
local Screen = require("device").screen
|
|
local T = require("ffi/util").template
|
|
|
|
local OPDSCatalog = InputContainer:extend{
|
|
title = _("OPDS Catalog"),
|
|
onExit = function() end,
|
|
}
|
|
|
|
function OPDSCatalog:init()
|
|
local opds_browser = OPDSBrowser:new{
|
|
title = self.title,
|
|
show_parent = self,
|
|
is_popout = false,
|
|
is_borderless = true,
|
|
has_close_button = true,
|
|
close_callback = function() return self:onClose() end,
|
|
file_downloaded_callback = function(downloaded_file)
|
|
UIManager:show(ConfirmBox:new{
|
|
text = T(_("File saved to:\n%1\nWould you like to read the downloaded book now?"),
|
|
BD.filepath(downloaded_file)),
|
|
ok_text = _("Read now"),
|
|
cancel_text = _("Read later"),
|
|
ok_callback = function()
|
|
local Event = require("ui/event")
|
|
UIManager:broadcastEvent(Event:new("SetupShowReader"))
|
|
|
|
self:onClose()
|
|
|
|
ReaderUI:showReader(downloaded_file)
|
|
end
|
|
})
|
|
end,
|
|
}
|
|
|
|
self[1] = FrameContainer:new{
|
|
padding = 0,
|
|
bordersize = 0,
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
opds_browser,
|
|
}
|
|
end
|
|
|
|
function OPDSCatalog:onShow()
|
|
UIManager:setDirty(self, function()
|
|
return "ui", self[1].dimen
|
|
end)
|
|
end
|
|
|
|
function OPDSCatalog:onCloseWidget()
|
|
UIManager:setDirty(nil, function()
|
|
return "ui", self[1].dimen
|
|
end)
|
|
end
|
|
|
|
function OPDSCatalog:showCatalog()
|
|
logger.dbg("show OPDS catalog")
|
|
UIManager:show(OPDSCatalog:new{
|
|
dimen = Screen:getSize(),
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
|
onExit = function()
|
|
--UIManager:quit()
|
|
end
|
|
})
|
|
end
|
|
|
|
function OPDSCatalog:onClose()
|
|
logger.dbg("close OPDS catalog")
|
|
UIManager:close(self)
|
|
if self.onExit then
|
|
self:onExit()
|
|
end
|
|
return true
|
|
end
|
|
|
|
return OPDSCatalog
|