mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
ReaderStatus, Book status widget: cleanup (#12343)
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
local BookStatusWidget = require("ui/widget/bookstatuswidget")
|
||||
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
||||
local ButtonDialog = require("ui/widget/buttondialog")
|
||||
local Device = require("device")
|
||||
local Event = require("ui/event")
|
||||
local FileManagerBookInfo = require("apps/filemanager/filemanagerbookinfo")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
@@ -10,18 +8,10 @@ local util = require("util")
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderStatus = WidgetContainer:extend{
|
||||
document = nil,
|
||||
enabled = true,
|
||||
total_pages = 0,
|
||||
}
|
||||
|
||||
function ReaderStatus:init()
|
||||
if self.ui.document.is_pic then
|
||||
self.enabled = false
|
||||
else
|
||||
self.total_pages = self.document:getPageCount()
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
function ReaderStatus:addToMainMenu(menu_items)
|
||||
@@ -33,6 +23,20 @@ function ReaderStatus:addToMainMenu(menu_items)
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderStatus:onShowBookStatus(before_show_callback)
|
||||
local status_page = BookStatusWidget:new{
|
||||
ui = self.ui,
|
||||
}
|
||||
if before_show_callback then
|
||||
before_show_callback()
|
||||
end
|
||||
status_page.dithered = true
|
||||
UIManager:show(status_page, "full")
|
||||
return true
|
||||
end
|
||||
|
||||
-- End of book
|
||||
|
||||
function ReaderStatus:onEndOfBook()
|
||||
Device:performHapticFeedback("CONTEXT_CLICK")
|
||||
local QuickStart = require("ui/quickstart")
|
||||
@@ -47,23 +51,25 @@ function ReaderStatus:onEndOfBook()
|
||||
|
||||
-- Should we start by marking the book as finished?
|
||||
if G_reader_settings:isTrue("end_document_auto_mark") then
|
||||
self:onMarkBook(true)
|
||||
self:markBook(true)
|
||||
end
|
||||
|
||||
local next_file_enabled = G_reader_settings:readSetting("collate") ~= "access"
|
||||
local settings = G_reader_settings:readSetting("end_document_action")
|
||||
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"
|
||||
local top_widget = UIManager:getTopmostVisibleWidget() or {}
|
||||
if (settings == "pop-up" or settings == nil) and top_widget.name ~= "end_document" then
|
||||
if settings == "pop-up" and top_widget.name ~= "end_document" then
|
||||
local button_dialog
|
||||
local buttons = {
|
||||
{
|
||||
{
|
||||
text_func = function()
|
||||
return self.summary.status == "complete" and _("Mark as reading") or _("Mark as finished")
|
||||
local status = self.ui.doc_settings:readSetting("summary").status
|
||||
return status == "complete" and _("Mark as reading") or _("Mark as finished")
|
||||
end,
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
self:onMarkBook()
|
||||
self:markBook()
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -80,7 +86,7 @@ function ReaderStatus:onEndOfBook()
|
||||
text = _("Go to beginning"),
|
||||
callback = function()
|
||||
UIManager:close(button_dialog)
|
||||
self.ui:handleEvent(Event:new("GoToBeginning"))
|
||||
self.ui.gotopage:onGoToBeginning()
|
||||
end,
|
||||
},
|
||||
{
|
||||
@@ -112,7 +118,7 @@ function ReaderStatus:onEndOfBook()
|
||||
},
|
||||
},
|
||||
}
|
||||
button_dialog = ButtonDialogTitle:new{
|
||||
button_dialog = ButtonDialog:new{
|
||||
name = "end_document",
|
||||
title = _("You've reached the end of the document.\nWhat would you like to do?"),
|
||||
title_align = "center",
|
||||
@@ -132,18 +138,18 @@ function ReaderStatus:onEndOfBook()
|
||||
self:onOpenNextDocumentInFolder()
|
||||
else
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Could not open next file. Sort by last read date does not support this feature."),
|
||||
text = _("Could not open next file. Sort by date does not support this feature."),
|
||||
})
|
||||
end
|
||||
elseif settings == "goto_beginning" then
|
||||
self.ui:handleEvent(Event:new("GoToBeginning"))
|
||||
self.ui.gotopage:onGoToBeginning()
|
||||
elseif settings == "file_browser" then
|
||||
-- Ditto
|
||||
UIManager:nextTick(function()
|
||||
self:openFileBrowser()
|
||||
end)
|
||||
elseif settings == "mark_read" then
|
||||
self:onMarkBook(true)
|
||||
self:markBook(true)
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("You've reached the end of the document.\nThe current book is marked as finished."),
|
||||
timeout = 3
|
||||
@@ -164,7 +170,7 @@ end
|
||||
|
||||
function ReaderStatus:openFileBrowser()
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
local file = self.ui.document.file
|
||||
local file = self.document.file
|
||||
self.ui:onClose()
|
||||
if not FileManager.instance then
|
||||
self.ui:showFileManager(file)
|
||||
@@ -188,7 +194,7 @@ function ReaderStatus:onOpenNextDocumentInFolder()
|
||||
end
|
||||
|
||||
function ReaderStatus:deleteFile()
|
||||
self.settings:flush() -- enable additional warning text for newly opened file
|
||||
self.ui.doc_settings:flush() -- enable additional warning text for newly opened file
|
||||
local FileManager = require("apps/filemanager/filemanager")
|
||||
local function pre_delete_callback()
|
||||
self.ui:onClose()
|
||||
@@ -200,35 +206,14 @@ function ReaderStatus:deleteFile()
|
||||
FileManager:showDeleteFileDialog(self.document.file, post_delete_callback, pre_delete_callback)
|
||||
end
|
||||
|
||||
function ReaderStatus:onShowBookStatus(before_show_callback)
|
||||
local status_page = BookStatusWidget:new {
|
||||
thumbnail = FileManagerBookInfo:getCoverImage(self.document),
|
||||
props = self.ui.doc_props,
|
||||
document = self.document,
|
||||
settings = self.settings,
|
||||
ui = self.ui,
|
||||
}
|
||||
if before_show_callback then
|
||||
before_show_callback()
|
||||
end
|
||||
status_page.dithered = true
|
||||
UIManager:show(status_page, "full")
|
||||
return true
|
||||
end
|
||||
|
||||
-- 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.
|
||||
function ReaderStatus:onMarkBook(mark_read)
|
||||
self.summary.status = (not mark_read and self.summary.status == "complete") and "reading" or "complete"
|
||||
self.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 save and flush
|
||||
self.settings:saveSetting("summary", self.summary)
|
||||
self.settings:flush()
|
||||
end
|
||||
|
||||
function ReaderStatus:onReadSettings(config)
|
||||
self.settings = config
|
||||
self.summary = config:readSetting("summary") or {}
|
||||
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()
|
||||
end
|
||||
|
||||
return ReaderStatus
|
||||
|
||||
Reference in New Issue
Block a user