2016-03-06 21:38:20 -08:00
|
|
|
local BookStatusWidget = require("ui/widget/bookstatuswidget")
|
2024-08-19 08:05:19 +03:00
|
|
|
local ButtonDialog = require("ui/widget/buttondialog")
|
2019-09-29 15:42:05 +02:00
|
|
|
local Device = require("device")
|
2018-05-13 13:07:23 +02:00
|
|
|
local InfoMessage = require("ui/widget/infomessage")
|
2016-02-02 19:38:14 +02: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 02:14:48 +02:00
|
|
|
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
2021-08-11 03:54:44 -04:00
|
|
|
local util = require("util")
|
2016-02-02 19:38:14 +02: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 02:14:48 +02:00
|
|
|
local ReaderStatus = WidgetContainer:extend{
|
2016-02-02 19:38:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ReaderStatus:init()
|
2024-08-19 08:05:19 +03:00
|
|
|
self.ui.menu:registerToMainMenu(self)
|
2016-02-02 19:38:14 +02:00
|
|
|
end
|
|
|
|
|
|
2017-03-04 14:46:38 +01:00
|
|
|
function ReaderStatus:addToMainMenu(menu_items)
|
|
|
|
|
menu_items.book_status = {
|
2016-03-06 21:52:53 -08:00
|
|
|
text = _("Book status"),
|
2016-02-02 19:38:14 +02:00
|
|
|
callback = function()
|
2019-03-06 18:50:32 +01:00
|
|
|
self:onShowBookStatus()
|
2016-02-02 19:38:14 +02:00
|
|
|
end,
|
2017-02-28 22:46:32 +01:00
|
|
|
}
|
2016-02-02 19:38:14 +02:00
|
|
|
end
|
|
|
|
|
|
2025-01-26 13:51:34 +02:00
|
|
|
function ReaderStatus:onShowBookStatus(close_callback)
|
2024-08-19 08:05:19 +03:00
|
|
|
local status_page = BookStatusWidget:new{
|
|
|
|
|
ui = self.ui,
|
2025-01-26 13:51:34 +02:00
|
|
|
close_callback = close_callback,
|
2024-08-19 08:05:19 +03:00
|
|
|
}
|
|
|
|
|
UIManager:show(status_page, "full")
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
-- End of book
|
|
|
|
|
|
2018-01-30 12:12:52 +01:00
|
|
|
function ReaderStatus:onEndOfBook()
|
2019-09-29 15:42:05 +02:00
|
|
|
Device:performHapticFeedback("CONTEXT_CLICK")
|
2018-06-13 21:43:50 +02:00
|
|
|
local QuickStart = require("ui/quickstart")
|
|
|
|
|
local last_file = G_reader_settings:readSetting("lastfile")
|
2023-02-17 23:06:55 +02:00
|
|
|
if last_file == QuickStart.quickstart_filename then
|
2025-03-18 18:46:22 +02:00
|
|
|
-- Like onOpenNextOrPreviousFileInFolder, delay this so as not to break instance lifecycle
|
2024-01-14 23:52:18 +01:00
|
|
|
UIManager:nextTick(function()
|
|
|
|
|
self:openFileBrowser()
|
|
|
|
|
end)
|
2018-06-13 21:43:50 +02:00
|
|
|
return
|
|
|
|
|
end
|
2020-06-11 11:37:14 +02:00
|
|
|
|
2023-02-28 09:19:17 +02:00
|
|
|
-- Should we start by marking the book as finished?
|
2020-06-11 11:37:14 +02:00
|
|
|
if G_reader_settings:isTrue("end_document_auto_mark") then
|
2024-08-19 08:05:19 +03:00
|
|
|
self:markBook(true)
|
2020-06-11 11:37:14 +02:00
|
|
|
end
|
|
|
|
|
|
2024-08-19 08:05:19 +03:00
|
|
|
local collate = G_reader_settings:readSetting("collate")
|
|
|
|
|
local next_file_enabled = collate ~= "access" and collate ~= "date"
|
|
|
|
|
local settings = G_reader_settings:readSetting("end_document_action") or "pop-up"
|
2023-02-17 23:06:55 +02:00
|
|
|
local top_widget = UIManager:getTopmostVisibleWidget() or {}
|
2024-08-19 08:05:19 +03:00
|
|
|
if settings == "pop-up" and top_widget.name ~= "end_document" then
|
2023-02-17 23:06:55 +02:00
|
|
|
local button_dialog
|
2018-05-13 13:07:23 +02:00
|
|
|
local buttons = {
|
|
|
|
|
{
|
|
|
|
|
{
|
2019-11-16 14:51:21 +01:00
|
|
|
text_func = function()
|
2024-08-19 08:05:19 +03:00
|
|
|
local status = self.ui.doc_settings:readSetting("summary").status
|
|
|
|
|
return status == "complete" and _("Mark as reading") or _("Mark as finished")
|
2019-11-16 14:51:21 +01:00
|
|
|
end,
|
2018-05-13 13:07:23 +02:00
|
|
|
callback = function()
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:close(button_dialog)
|
2024-08-19 08:05:19 +03:00
|
|
|
self:markBook()
|
2018-05-13 13:07:23 +02:00
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
text = _("Book status"),
|
|
|
|
|
callback = function()
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:close(button_dialog)
|
2024-01-14 23:52:18 +01:00
|
|
|
self:onShowBookStatus()
|
2018-05-13 13:07:23 +02:00
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
{
|
2019-07-05 10:35:23 +02:00
|
|
|
{
|
2020-02-05 02:19:35 -05:00
|
|
|
text = _("Go to beginning"),
|
2019-07-05 10:35:23 +02:00
|
|
|
callback = function()
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:close(button_dialog)
|
2024-08-19 08:05:19 +03:00
|
|
|
self.ui.gotopage:onGoToBeginning()
|
2019-07-05 10:35:23 +02:00
|
|
|
end,
|
|
|
|
|
},
|
2018-05-13 13:07:23 +02:00
|
|
|
{
|
|
|
|
|
text = _("Open next file"),
|
2023-02-17 23:06:55 +02:00
|
|
|
enabled = next_file_enabled,
|
2018-05-13 13:07:23 +02:00
|
|
|
callback = function()
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:close(button_dialog)
|
2025-03-18 18:46:22 +02:00
|
|
|
self:onOpenNextOrPreviousFileInFolder()
|
2018-05-13 13:07:23 +02:00
|
|
|
end,
|
|
|
|
|
},
|
2019-07-05 10:35:23 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-11-16 14:51:21 +01:00
|
|
|
{
|
2020-02-05 02:19:35 -05:00
|
|
|
text = _("Delete file"),
|
2019-11-16 14:51:21 +01:00
|
|
|
callback = function()
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:close(button_dialog)
|
2024-01-14 23:52:18 +01:00
|
|
|
self:deleteFile()
|
2019-11-16 14:51:21 +01:00
|
|
|
end,
|
|
|
|
|
},
|
2018-05-13 13:07:23 +02:00
|
|
|
{
|
|
|
|
|
text = _("File browser"),
|
|
|
|
|
callback = function()
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:close(button_dialog)
|
2024-01-14 23:52:18 +01:00
|
|
|
-- Ditto
|
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
|
self:openFileBrowser()
|
|
|
|
|
end)
|
2020-02-05 02:19:35 -05:00
|
|
|
end,
|
|
|
|
|
},
|
|
|
|
|
},
|
2018-05-13 13:07:23 +02:00
|
|
|
}
|
2024-08-19 08:05:19 +03:00
|
|
|
button_dialog = ButtonDialog:new{
|
2020-12-23 00:16:56 -05:00
|
|
|
name = "end_document",
|
2018-05-13 13:07:23 +02:00
|
|
|
title = _("You've reached the end of the document.\nWhat would you like to do?"),
|
|
|
|
|
title_align = "center",
|
|
|
|
|
buttons = buttons,
|
|
|
|
|
}
|
2023-02-17 23:06:55 +02:00
|
|
|
UIManager:show(button_dialog)
|
2018-05-13 13:07:23 +02:00
|
|
|
elseif settings == "book_status" then
|
2019-03-07 16:35:05 +01:00
|
|
|
self:onShowBookStatus()
|
2018-05-13 13:07:23 +02:00
|
|
|
elseif settings == "next_file" then
|
2023-02-17 23:06:55 +02:00
|
|
|
if next_file_enabled then
|
2018-05-13 13:07:23 +02:00
|
|
|
local info = InfoMessage:new{
|
|
|
|
|
text = _("Searching next file…"),
|
|
|
|
|
}
|
|
|
|
|
UIManager:show(info)
|
|
|
|
|
UIManager:forceRePaint()
|
|
|
|
|
UIManager:close(info)
|
2025-03-18 18:46:22 +02:00
|
|
|
self:onOpenNextOrPreviousFileInFolder()
|
2018-05-13 13:07:23 +02:00
|
|
|
else
|
|
|
|
|
UIManager:show(InfoMessage:new{
|
2024-08-19 08:05:19 +03:00
|
|
|
text = _("Could not open next file. Sort by date does not support this feature."),
|
2018-05-13 13:07:23 +02:00
|
|
|
})
|
|
|
|
|
end
|
2020-02-05 02:19:35 -05:00
|
|
|
elseif settings == "goto_beginning" then
|
2024-08-19 08:05:19 +03:00
|
|
|
self.ui.gotopage:onGoToBeginning()
|
2018-05-13 13:07:23 +02:00
|
|
|
elseif settings == "file_browser" then
|
2021-05-22 04:46:41 +02:00
|
|
|
-- Ditto
|
|
|
|
|
UIManager:nextTick(function()
|
|
|
|
|
self:openFileBrowser()
|
|
|
|
|
end)
|
2019-11-16 14:51:21 +01:00
|
|
|
elseif settings == "mark_read" then
|
2024-08-19 08:05:19 +03:00
|
|
|
self:markBook(true)
|
2019-11-16 14:51:21 +01:00
|
|
|
UIManager:show(InfoMessage:new{
|
2023-02-28 09:19:17 +02:00
|
|
|
text = _("You've reached the end of the document.\nThe current book is marked as finished."),
|
2019-11-16 14:51:21 +01:00
|
|
|
timeout = 3
|
|
|
|
|
})
|
2018-05-13 13:07:23 +02:00
|
|
|
elseif settings == "book_status_file_browser" then
|
2021-05-22 04:46:41 +02:00
|
|
|
-- Ditto
|
|
|
|
|
UIManager:nextTick(function()
|
2025-01-26 13:51:34 +02:00
|
|
|
local book_status_close_callback = function() self:openFileBrowser() end
|
|
|
|
|
self:onShowBookStatus(book_status_close_callback)
|
2021-05-22 04:46:41 +02:00
|
|
|
end)
|
2019-07-05 10:35:23 +02:00
|
|
|
elseif settings == "delete_file" then
|
2021-05-22 04:46:41 +02:00
|
|
|
-- Ditto
|
|
|
|
|
UIManager:nextTick(function()
|
2023-02-17 23:06:55 +02:00
|
|
|
self:deleteFile()
|
2021-05-22 04:46:41 +02:00
|
|
|
end)
|
2018-01-30 12:12:52 +01:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2018-05-13 13:07:23 +02:00
|
|
|
function ReaderStatus:openFileBrowser()
|
2024-08-19 08:05:19 +03:00
|
|
|
local file = self.document.file
|
2019-06-09 15:19:38 +02:00
|
|
|
self.ui:onClose()
|
2025-01-26 13:51:34 +02:00
|
|
|
self.ui:showFileManager(file)
|
2018-05-13 13:07:23 +02:00
|
|
|
end
|
|
|
|
|
|
2025-03-18 07:50:48 +02:00
|
|
|
function ReaderStatus:onOpenNextOrPreviousFileInFolder(prev)
|
|
|
|
|
local collate = G_reader_settings:readSetting("collate")
|
|
|
|
|
if collate == "access" or collate == "date" then return true end
|
2023-12-27 08:45:52 +02:00
|
|
|
local FileChooser = require("ui/widget/filechooser")
|
2025-04-18 19:21:06 +03:00
|
|
|
local fc = FileChooser:new{ ui = self.ui }
|
|
|
|
|
local file = fc:getNextOrPreviousFileInFolder(self.document.file, prev)
|
2025-03-18 07:50:48 +02:00
|
|
|
if file then
|
2024-01-14 23:52:18 +01: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...
|
|
|
|
|
UIManager:nextTick(function()
|
2025-03-18 07:50:48 +02:00
|
|
|
self.ui:switchDocument(file)
|
2024-01-14 23:52:18 +01:00
|
|
|
end)
|
2018-05-13 13:07:23 +02:00
|
|
|
else
|
|
|
|
|
UIManager:show(InfoMessage:new{
|
2025-03-18 07:50:48 +02:00
|
|
|
text = prev and _("This is the first file in the folder. No previous file to open.")
|
|
|
|
|
or _("This is the last file in the folder. No next file to open."),
|
2018-05-13 13:07:23 +02:00
|
|
|
})
|
|
|
|
|
end
|
2025-03-18 07:50:48 +02:00
|
|
|
return true
|
2018-05-13 13:07:23 +02:00
|
|
|
end
|
|
|
|
|
|
2023-02-17 23:06:55 +02:00
|
|
|
function ReaderStatus:deleteFile()
|
2024-08-19 08:05:19 +03:00
|
|
|
self.ui.doc_settings:flush() -- enable additional warning text for newly opened file
|
2023-02-17 23:06:55 +02:00
|
|
|
local FileManager = require("apps/filemanager/filemanager")
|
|
|
|
|
local function pre_delete_callback()
|
|
|
|
|
self.ui:onClose()
|
2019-07-05 10:35:23 +02:00
|
|
|
end
|
2023-02-17 23:06:55 +02: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 10:35:23 +02:00
|
|
|
end
|
|
|
|
|
|
2023-02-17 23:06:55 +02: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.
|
2024-08-19 08:05:19 +03:00
|
|
|
function ReaderStatus:markBook(mark_read)
|
|
|
|
|
local summary = self.ui.doc_settings:readSetting("summary")
|
|
|
|
|
summary.status = (not mark_read and summary.status == "complete") and "reading" or "complete"
|
|
|
|
|
summary.modified = os.date("%Y-%m-%d", os.time())
|
|
|
|
|
-- If History is called over Reader, it will read the file to get the book status, so flush
|
|
|
|
|
self.ui.doc_settings:flush()
|
2016-02-02 19:38:14 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return ReaderStatus
|