2020-01-04 00:18:51 +00:00
|
|
|
local BD = require("ui/bidi")
|
2017-04-29 14:30:16 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2014-09-05 13:02:13 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
2021-02-06 18:09:31 +00:00
|
|
|
local OPDSBrowser = require("opdsbrowser")
|
2014-09-05 13:02:13 +00:00
|
|
|
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.
2022-10-06 00:14:48 +00:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2014-09-05 13:02:13 +00:00
|
|
|
local _ = require("gettext")
|
2017-04-29 14:30:16 +00:00
|
|
|
local Screen = require("device").screen
|
2016-11-27 15:06:24 +00:00
|
|
|
local T = require("ffi/util").template
|
2017-04-29 14:30:16 +00:00
|
|
|
|
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.
2022-10-06 00:14:48 +00:00
|
|
|
local OPDSCatalog = WidgetContainer:extend{
|
2014-09-05 13:02:13 +00:00
|
|
|
title = _("OPDS Catalog"),
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2016-11-27 15:06:24 +00:00
|
|
|
file_downloaded_callback = function(downloaded_file)
|
|
|
|
UIManager:show(ConfirmBox:new{
|
2019-09-17 12:27:51 +00:00
|
|
|
text = T(_("File saved to:\n%1\nWould you like to read the downloaded book now?"),
|
2020-01-04 00:18:51 +00:00
|
|
|
BD.filepath(downloaded_file)),
|
2017-10-01 12:27:02 +00:00
|
|
|
ok_text = _("Read now"),
|
|
|
|
cancel_text = _("Read later"),
|
2016-11-27 15:06:24 +00:00
|
|
|
ok_callback = function()
|
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.
2021-05-01 16:53:04 +00:00
|
|
|
local Event = require("ui/event")
|
|
|
|
UIManager:broadcastEvent(Event:new("SetupShowReader"))
|
|
|
|
|
2016-11-27 15:06:24 +00:00
|
|
|
self:onClose()
|
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.
2021-05-01 16:53:04 +00:00
|
|
|
|
2021-05-10 22:49:35 +00:00
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
2016-11-27 15:06:24 +00:00
|
|
|
ReaderUI:showReader(downloaded_file)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
end,
|
2014-09-05 13:02:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
padding = 0,
|
|
|
|
bordersize = 0,
|
2014-10-22 13:34:11 +00:00
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
2014-09-05 13:02:13 +00:00
|
|
|
opds_browser,
|
|
|
|
}
|
2014-12-01 14:39:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function OPDSCatalog:onShow()
|
|
|
|
UIManager:setDirty(self, function()
|
2015-04-26 18:07:17 +00:00
|
|
|
return "ui", self[1].dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
|
|
|
end
|
2014-09-05 13:02:13 +00:00
|
|
|
|
2014-12-01 14:39:41 +00:00
|
|
|
function OPDSCatalog:onCloseWidget()
|
|
|
|
UIManager:setDirty(nil, function()
|
Tame some ButtonTable users into re-using Buttontable instances if possible (#7166)
* QuickDictLookup, ImageViewer, NumberPicker: Smarter `update` that will re-use most of the widget's layout instead of re-instantiating all the things.
* SpinWidget/DoubleSpinWidget: The NumberPicker change above renders a hack to preserve alpha on these widgets almost unnecessary. Also fixed said hack to also apply to the center, value button.
* Button: Don't re-instantiate the frame in setText/setIcon when unnecessary (e.g., no change at all, or no layout change).
* Button: Add a refresh method that repaints and refreshes a *specific* Button (provided it's been painted once) all on its lonesome.
* ConfigDialog: Free everything that's going to be re-instatiated on update
* A few more post #7118 fixes:
* SkimTo: Always flag the chapter nav buttons as vsync
* Button: Fix the highlight on rounded buttons when vsync is enabled (e.g., it's now entirely visible, instead of showing a weird inverted corner glitch).
* Some more heuristic tweaks in Menu/TouchMenu/Button/IconButton
* ButtonTable: fix the annoying rounding issue I'd noticed in #7054 ;).
* Enable dithering in TextBoxWidget (e.g., in the Wikipedia full view). This involved moving the HW dithering align fixup to base, where it always ought to have been ;).
* Switch a few widgets that were using "partial" on close to "ui", or, more rarely, "flashui". The intent being to limit "partial" purely to the Reader, because it has a latency cost when mixed with other refreshes, which happens often enough in UI ;).
* Minor documentation tweaks around UIManager's `setDirty` to reflect that change.
* ReaderFooter: Force a footer repaint on resume if it is visible (otherwise, just update it).
* ReaderBookmark: In the same vein, don't repaint an invisible footer on bookmark count changes.
2021-01-28 23:20:15 +00:00
|
|
|
return "ui", self[1].dimen
|
2014-12-01 14:39:41 +00:00
|
|
|
end)
|
2014-09-05 13:02:13 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function OPDSCatalog:showCatalog()
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("show OPDS catalog")
|
2014-09-05 13:02:13 +00:00
|
|
|
UIManager:show(OPDSCatalog:new{
|
|
|
|
dimen = Screen:getSize(),
|
2018-03-17 22:02:32 +00:00
|
|
|
covers_fullscreen = true, -- hint for UIManager:_repaint()
|
2014-09-05 13:02:13 +00:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
function OPDSCatalog:onClose()
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("close OPDS catalog")
|
2014-09-05 13:02:13 +00:00
|
|
|
UIManager:close(self)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return OPDSCatalog
|