2016-03-07 05:38:20 +00:00
|
|
|
local BookStatusWidget = require("ui/widget/bookstatuswidget")
|
2018-05-13 11:07:23 +00:00
|
|
|
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
2019-09-29 13:42:05 +00:00
|
|
|
local Device = require("device")
|
2020-02-05 07:19:35 +00:00
|
|
|
local Event = require("ui/event")
|
2023-05-03 12:43:05 +00:00
|
|
|
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
|
2018-05-13 11:07:23 +00:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2016-02-02 17:38:14 +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")
|
2021-08-11 07:54:44 +00:00
|
|
|
local util = require("util")
|
2016-02-02 17:38:14 +00:00
|
|
|
local _ = require("gettext")
|
|
|
|
|
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 ReaderStatus = WidgetContainer:extend{
|
2016-02-02 17:38:14 +00:00
|
|
|
document = nil,
|
|
|
|
enabled = true,
|
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
|
|
|
total_pages = 0,
|
2016-02-02 17:38:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function ReaderStatus:init()
|
2016-07-15 14:58:41 +00:00
|
|
|
if self.ui.document.is_pic then
|
2016-02-02 17:38:14 +00:00
|
|
|
self.enabled = false
|
2016-03-07 05:52:53 +00:00
|
|
|
else
|
|
|
|
self.total_pages = self.document:getPageCount()
|
2016-02-10 07:17:53 +00:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2016-03-07 05:52:53 +00:00
|
|
|
end
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
2017-03-04 13:46:38 +00:00
|
|
|
function ReaderStatus:addToMainMenu(menu_items)
|
|
|
|
menu_items.book_status = {
|
2016-03-07 05:52:53 +00:00
|
|
|
text = _("Book status"),
|
2016-02-02 17:38:14 +00:00
|
|
|
callback = function()
|
2019-03-06 17:50:32 +00:00
|
|
|
self:onShowBookStatus()
|
2016-02-02 17:38:14 +00:00
|
|
|
end,
|
2017-02-28 21:46:32 +00:00
|
|
|
}
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
2018-01-30 11:12:52 +00:00
|
|
|
function ReaderStatus:onEndOfBook()
|
2019-09-29 13:42:05 +00:00
|
|
|
Device:performHapticFeedback("CONTEXT_CLICK")
|
2018-06-13 19:43:50 +00:00
|
|
|
local QuickStart = require("ui/quickstart")
|
|
|
|
local last_file = G_reader_settings:readSetting("lastfile")
|
2023-02-17 21:06:55 +00:00
|
|
|
if last_file == QuickStart.quickstart_filename then
|
2018-06-13 19:43:50 +00:00
|
|
|
self:openFileBrowser()
|
|
|
|
return
|
|
|
|
end
|
2020-06-11 09:37:14 +00:00
|
|
|
|
2023-02-28 07:19:17 +00:00
|
|
|
-- Should we start by marking the book as finished?
|
2020-06-11 09:37:14 +00:00
|
|
|
if G_reader_settings:isTrue("end_document_auto_mark") then
|
|
|
|
self:onMarkBook(true)
|
|
|
|
end
|
|
|
|
|
2023-02-17 21:06:55 +00:00
|
|
|
local next_file_enabled = G_reader_settings:readSetting("collate") ~= "access"
|
|
|
|
local settings = G_reader_settings:readSetting("end_document_action")
|
|
|
|
local top_widget = UIManager:getTopmostVisibleWidget() or {}
|
|
|
|
if (settings == "pop-up" or settings == nil) and top_widget.name ~= "end_document" then
|
|
|
|
local button_dialog
|
2018-05-13 11:07:23 +00:00
|
|
|
local buttons = {
|
|
|
|
{
|
|
|
|
{
|
2019-11-16 13:51:21 +00:00
|
|
|
text_func = function()
|
2023-02-17 21:06:55 +00:00
|
|
|
return self.summary.status == "complete" and _("Mark as reading") or _("Mark as finished")
|
2019-11-16 13:51:21 +00:00
|
|
|
end,
|
2018-05-13 11:07:23 +00:00
|
|
|
callback = function()
|
2019-11-16 13:51:21 +00:00
|
|
|
self:onMarkBook()
|
2023-02-17 21:06:55 +00:00
|
|
|
UIManager:close(button_dialog)
|
2018-05-13 11:07:23 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
text = _("Book status"),
|
|
|
|
callback = function()
|
2019-03-07 15:35:05 +00:00
|
|
|
self:onShowBookStatus()
|
2023-02-17 21:06:55 +00:00
|
|
|
UIManager:close(button_dialog)
|
2018-05-13 11:07:23 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
|
|
|
|
},
|
|
|
|
{
|
2019-07-05 08:35:23 +00:00
|
|
|
{
|
2020-02-05 07:19:35 +00:00
|
|
|
text = _("Go to beginning"),
|
2019-07-05 08:35:23 +00:00
|
|
|
callback = function()
|
2020-02-05 07:19:35 +00:00
|
|
|
self.ui:handleEvent(Event:new("GoToBeginning"))
|
2023-02-17 21:06:55 +00:00
|
|
|
UIManager:close(button_dialog)
|
2019-07-05 08:35:23 +00:00
|
|
|
end,
|
|
|
|
},
|
2018-05-13 11:07:23 +00:00
|
|
|
{
|
|
|
|
text = _("Open next file"),
|
2023-02-17 21:06:55 +00:00
|
|
|
enabled = next_file_enabled,
|
2018-05-13 11:07:23 +00:00
|
|
|
callback = function()
|
2022-12-14 19:40:24 +00:00
|
|
|
self:onOpenNextDocumentInFolder()
|
2023-02-17 21:06:55 +00:00
|
|
|
UIManager:close(button_dialog)
|
2018-05-13 11:07:23 +00:00
|
|
|
end,
|
|
|
|
},
|
2019-07-05 08:35:23 +00:00
|
|
|
},
|
|
|
|
{
|
2019-11-16 13:51:21 +00:00
|
|
|
{
|
2020-02-05 07:19:35 +00:00
|
|
|
text = _("Delete file"),
|
2019-11-16 13:51:21 +00:00
|
|
|
callback = function()
|
2023-02-17 21:06:55 +00:00
|
|
|
self:deleteFile()
|
|
|
|
UIManager:close(button_dialog)
|
2019-11-16 13:51:21 +00:00
|
|
|
end,
|
|
|
|
},
|
2018-05-13 11:07:23 +00:00
|
|
|
{
|
|
|
|
text = _("File browser"),
|
|
|
|
callback = function()
|
|
|
|
self:openFileBrowser()
|
2023-02-17 21:06:55 +00:00
|
|
|
UIManager:close(button_dialog)
|
2020-02-05 07:19:35 +00:00
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
2018-05-13 11:07:23 +00:00
|
|
|
}
|
2023-02-17 21:06:55 +00:00
|
|
|
button_dialog = ButtonDialogTitle:new{
|
2020-12-23 05:16:56 +00:00
|
|
|
name = "end_document",
|
2018-05-13 11:07:23 +00:00
|
|
|
title = _("You've reached the end of the document.\nWhat would you like to do?"),
|
|
|
|
title_align = "center",
|
|
|
|
buttons = buttons,
|
|
|
|
}
|
2023-02-17 21:06:55 +00:00
|
|
|
UIManager:show(button_dialog)
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "book_status" then
|
2019-03-07 15:35:05 +00:00
|
|
|
self:onShowBookStatus()
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "next_file" then
|
2023-02-17 21:06:55 +00:00
|
|
|
if next_file_enabled then
|
2018-05-13 11:07:23 +00:00
|
|
|
local info = InfoMessage:new{
|
|
|
|
text = _("Searching next file…"),
|
|
|
|
}
|
|
|
|
UIManager:show(info)
|
|
|
|
UIManager:forceRePaint()
|
|
|
|
UIManager:close(info)
|
2023-02-17 21:06:55 +00:00
|
|
|
-- Delay until the next tick, as this will destroy the Document instance,
|
|
|
|
-- but we may not be the final Event caught by said Document...
|
2021-05-22 02:46:41 +00:00
|
|
|
UIManager:nextTick(function()
|
2022-12-14 19:40:24 +00:00
|
|
|
self:onOpenNextDocumentInFolder()
|
2021-05-22 02:46:41 +00:00
|
|
|
end)
|
2018-05-13 11:07:23 +00:00
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("Could not open next file. Sort by last read date does not support this feature."),
|
|
|
|
})
|
|
|
|
end
|
2020-02-05 07:19:35 +00:00
|
|
|
elseif settings == "goto_beginning" then
|
|
|
|
self.ui:handleEvent(Event:new("GoToBeginning"))
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "file_browser" then
|
2021-05-22 02:46:41 +00:00
|
|
|
-- Ditto
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
self:openFileBrowser()
|
|
|
|
end)
|
2019-11-16 13:51:21 +00:00
|
|
|
elseif settings == "mark_read" then
|
|
|
|
self:onMarkBook(true)
|
|
|
|
UIManager:show(InfoMessage:new{
|
2023-02-28 07:19:17 +00:00
|
|
|
text = _("You've reached the end of the document.\nThe current book is marked as finished."),
|
2019-11-16 13:51:21 +00:00
|
|
|
timeout = 3
|
|
|
|
})
|
2018-05-13 11:07:23 +00:00
|
|
|
elseif settings == "book_status_file_browser" then
|
2021-05-22 02:46:41 +00:00
|
|
|
-- Ditto
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
local before_show_callback = function() self:openFileBrowser() end
|
|
|
|
self:onShowBookStatus(before_show_callback)
|
|
|
|
end)
|
2019-07-05 08:35:23 +00:00
|
|
|
elseif settings == "delete_file" then
|
2021-05-22 02:46:41 +00:00
|
|
|
-- Ditto
|
|
|
|
UIManager:nextTick(function()
|
2023-02-17 21:06:55 +00:00
|
|
|
self:deleteFile()
|
2021-05-22 02:46:41 +00:00
|
|
|
end)
|
2018-01-30 11:12:52 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-13 11:07:23 +00:00
|
|
|
function ReaderStatus:openFileBrowser()
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
2019-06-09 13:19:38 +00:00
|
|
|
self.ui:onClose()
|
2018-05-13 11:07:23 +00:00
|
|
|
if not FileManager.instance then
|
|
|
|
self.ui:showFileManager()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-12-14 19:40:24 +00:00
|
|
|
function ReaderStatus:onOpenNextDocumentInFolder()
|
2023-12-27 06:45:52 +00:00
|
|
|
local FileChooser = require("ui/widget/filechooser")
|
|
|
|
local next_file = FileChooser:getNextFile(self.document.file)
|
2018-05-13 11:07:23 +00:00
|
|
|
if next_file then
|
2018-07-11 16:05:30 +00:00
|
|
|
self.ui:switchDocument(next_file)
|
2018-05-13 11:07:23 +00:00
|
|
|
else
|
|
|
|
UIManager:show(InfoMessage:new{
|
|
|
|
text = _("This is the last file in the current folder. No next file to open."),
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-02-17 21:06:55 +00:00
|
|
|
function ReaderStatus:deleteFile()
|
|
|
|
self.settings:flush() -- enable additional warning text for newly opened file
|
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
local function pre_delete_callback()
|
|
|
|
self.ui:onClose()
|
2019-07-05 08:35:23 +00:00
|
|
|
end
|
2023-02-17 21:06:55 +00:00
|
|
|
local function post_delete_callback()
|
|
|
|
local path = util.splitFilePathName(self.document.file)
|
|
|
|
FileManager:showFiles(path)
|
|
|
|
end
|
|
|
|
FileManager:showDeleteFileDialog(self.document.file, post_delete_callback, pre_delete_callback)
|
2019-07-05 08:35:23 +00:00
|
|
|
end
|
|
|
|
|
2019-03-06 17:50:32 +00:00
|
|
|
function ReaderStatus:onShowBookStatus(before_show_callback)
|
2016-03-07 05:38:20 +00:00
|
|
|
local status_page = BookStatusWidget:new {
|
2023-05-03 12:43:05 +00:00
|
|
|
thumbnail = FileManagerBookInfo:getCoverImage(self.document),
|
2023-08-30 04:53:59 +00:00
|
|
|
props = self.ui.doc_props,
|
2016-02-02 17:38:14 +00:00
|
|
|
document = self.document,
|
|
|
|
settings = self.settings,
|
2021-10-10 09:55:32 +00:00
|
|
|
ui = self.ui,
|
2016-02-02 17:38:14 +00:00
|
|
|
}
|
2018-05-13 11:07:23 +00:00
|
|
|
if before_show_callback then
|
|
|
|
before_show_callback()
|
|
|
|
end
|
Enable HW dithering in a few key places (#4541)
* Enable HW dithering on supported devices (Clara HD, Forma; Oasis 2, PW4)
* FileManager and co. (where appropriate, i.e., when covers are shown)
* Book Status
* Reader, where appropriate:
* CRe: on pages whith image content (for over 7.5% of the screen area, should hopefully leave stuff like bullet points or small scene breaks alone).
* Other engines: on user-request (in the gear tab of the bottom menu), via the new "Dithering" knob (will only appear on supported devices).
* ScreenSaver
* ImageViewer
* Minimize repaints when flash_ui is enabled (by, almost everywhere, only repainting the flashing element, and not the toplevel window which hosts it).
(The first pass of this involved fixing a few Button instances whose show_parent was wrong, in particular, chevrons in the FM & TopMenu).
* Hunted down a few redundant repaints (unneeded setDirty("all") calls),
either by switching the widget to nil when only a refresh was needed, and not a repaint,
or by passing the appropritate widget to setDirty.
(Note to self: Enable *verbose* debugging to catch broken setDirty calls via its post guard).
There were also a few instances of 'em right behind a widget close.
* Don't repaint the underlying widget when initially showing TopMenu & ConfigDialog.
We unfortunately do need to do it when switching tabs, because of their variable heights.
* On Kobo, disabled the extra and completely useless full refresh before suspend/reboot/poweroff, as well as on resume. No more double refreshes!
* Fix another debug guard in Kobo sysfs_light
* Switch ImageWidget & ImageViewer mostly to "ui" updates, which will be better suited to image content pretty much everywhere, REAGL or not.
PS: (Almost :100: commits! :D)
2019-02-07 00:14:37 +00:00
|
|
|
status_page.dithered = true
|
|
|
|
UIManager:show(status_page, "full")
|
2019-03-06 17:50:32 +00:00
|
|
|
return true
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
2023-02-17 21:06:55 +00:00
|
|
|
-- If mark_read is true then we change status only from reading/abandoned to complete.
|
|
|
|
-- Otherwise we change status from reading/abandoned to complete or from complete to reading.
|
2019-11-16 13:51:21 +00:00
|
|
|
function ReaderStatus:onMarkBook(mark_read)
|
2023-02-17 21:06:55 +00:00
|
|
|
self.summary.status = (not mark_read and self.summary.status == "complete") and "reading" or "complete"
|
2022-10-10 21:52:47 +00:00
|
|
|
-- If History is called over Reader, it will read the file to get the book status, so save and flush
|
2023-02-17 21:06:55 +00:00
|
|
|
self.settings:saveSetting("summary", self.summary)
|
2022-10-10 21:52:47 +00:00
|
|
|
self.settings:flush()
|
2019-11-16 13:51:21 +00:00
|
|
|
end
|
|
|
|
|
2016-02-02 17:38:14 +00:00
|
|
|
function ReaderStatus:onReadSettings(config)
|
|
|
|
self.settings = config
|
2023-02-17 21:06:55 +00:00
|
|
|
self.summary = config:readSetting("summary") or {}
|
2016-02-02 17:38:14 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
return ReaderStatus
|