From efa0d06df94529d823134750240ccc4db48a35ea Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 17 Dec 2017 18:27:24 +0100 Subject: [PATCH] Add new options to screensaver (#3535) * Prevent open screensaver more than one in the same time * Add option to enable/disable background in message screensaver * fallback to random images if this book cover is excluded feature + fix Disabled (leave screen/page as it is) * Autostretch disable by default, more fallback options, leave screen as it is --- frontend/apps/filemanager/filemanagermenu.lua | 55 +-- frontend/apps/reader/modules/readermenu.lua | 81 +++-- frontend/device/generic/device.lua | 2 +- frontend/device/kindle/device.lua | 6 +- frontend/ui/elements/screensaver_menu.lua | 194 +++++++++++ frontend/ui/screensaver.lua | 326 ++++++++++++------ frontend/ui/widget/bookstatuswidget.lua | 28 +- frontend/ui/widget/button.lua | 4 +- frontend/ui/widget/infomessage.lua | 8 +- frontend/ui/widget/inputtext.lua | 6 +- frontend/ui/widget/screensaverwidget.lua | 92 +++++ frontend/ui/widget/toggleswitch.lua | 8 +- plugins/statistics.koplugin/main.lua | 19 + .../statistics.koplugin/readerprogress.lua | 6 +- 14 files changed, 633 insertions(+), 202 deletions(-) create mode 100644 frontend/ui/elements/screensaver_menu.lua create mode 100644 frontend/ui/widget/screensaverwidget.lua diff --git a/frontend/apps/filemanager/filemanagermenu.lua b/frontend/apps/filemanager/filemanagermenu.lua index 8e235986f..b4b90a9f6 100644 --- a/frontend/apps/filemanager/filemanagermenu.lua +++ b/frontend/apps/filemanager/filemanagermenu.lua @@ -4,8 +4,6 @@ local ConfirmBox = require("ui/widget/confirmbox") local Device = require("device") local FileSearcher = require("apps/filemanager/filemanagerfilesearcher") local InputContainer = require("ui/widget/container/inputcontainer") -local InputDialog = require("ui/widget/inputdialog") -local Screensaver = require("ui/screensaver") local Search = require("apps/filemanager/filemanagersearch") local SetDefaults = require("apps/filemanager/filemanagersetdefaults") local UIManager = require("ui/uimanager") @@ -103,58 +101,7 @@ function FileManagerMenu:setUpdateItemTable() if Device:supportsScreensaver() then self.menu_items.screensaver = { text = _("Screensaver"), - sub_item_table = { - { - text = _("Use last book's cover as screensaver"), - checked_func = Screensaver.isUsingBookCover, - callback = function() - if Screensaver:isUsingBookCover() then - G_reader_settings:saveSetting( - "use_lastfile_as_screensaver", false) - else - G_reader_settings:delSetting( - "use_lastfile_as_screensaver") - end - G_reader_settings:flush() - end - }, - { - text = _("Screensaver folder"), - callback = function() - local ss_folder_path_input - local function save_folder_path() - G_reader_settings:saveSetting( - "screensaver_folder", ss_folder_path_input:getInputText()) - G_reader_settings:flush() - UIManager:close(ss_folder_path_input) - end - local curr_path = G_reader_settings:readSetting("screensaver_folder") - ss_folder_path_input = InputDialog:new{ - title = _("Screensaver folder"), - input = curr_path, - input_hint = "/mnt/onboard/screensaver", - input_type = "text", - buttons = { - { - { - text = _("Cancel"), - callback = function() - UIManager:close(ss_folder_path_input) - end, - }, - { - text = _("Save"), - is_enter_default = true, - callback = save_folder_path, - }, - } - }, - } - ss_folder_path_input:onShowKeyboard() - UIManager:show(ss_folder_path_input) - end, - }, - } + sub_item_table = require("ui/elements/screensaver_menu"), } end -- insert common settings diff --git a/frontend/apps/reader/modules/readermenu.lua b/frontend/apps/reader/modules/readermenu.lua index 5748b9600..52ea915bf 100644 --- a/frontend/apps/reader/modules/readermenu.lua +++ b/frontend/apps/reader/modules/readermenu.lua @@ -127,36 +127,21 @@ function ReaderMenu:setUpdateItemTable() end if Device:supportsScreensaver() then - local excluded = function() - return self.ui.doc_settings:readSetting("exclude_screensaver") or false - end - local proportional = function() - return self.ui.doc_settings:readSetting("proportional_screensaver") or false - end - self.menu_items.screensaver = { - text = _("Screensaver"), + local ss_book_settings = { + text = _("Current book cover settings"), + enabled_func = function() + return not (self.ui == nil or self.ui.document == nil) + and G_reader_settings:readSetting('screensaver_type') == "cover" + end, sub_item_table = { - { - text = _("Use last book's cover as screensaver"), - checked_func = Screensaver.isUsingBookCover, - callback = function() - if Screensaver:isUsingBookCover() then - G_reader_settings:saveSetting( - "use_lastfile_as_screensaver", false) - else - G_reader_settings:delSetting( - "use_lastfile_as_screensaver") - end - G_reader_settings:flush() - end - }, { text = _("Exclude this book's cover from screensaver"), - checked_func = excluded, - enabled_func = Screensaver.isUsingBookCover, + checked_func = function() + return self.ui.doc_settings:readSetting("exclude_screensaver") == true + end, callback = function() - if excluded() then - self.ui.doc_settings:delSetting("exclude_screensaver") + if Screensaver:excluded() then + self.ui.doc_settings:saveSetting("exclude_screensaver", false) else self.ui.doc_settings:saveSetting("exclude_screensaver", true) end @@ -164,21 +149,45 @@ function ReaderMenu:setUpdateItemTable() end }, { - text = _("Auto stretch this book's cover image in screensaver"), - checked_func = proportional, - enabled_func = Screensaver.isUsingBookCover, - callback = function() - if proportional() then - self.ui.doc_settings:delSetting("proportional_screensaver") + text = _("Stretch book cover to fit screen"), + checked_func = function() + local settings_stretch_cover = self.ui.doc_settings:readSetting("stretch_cover") + if settings_stretch_cover == nil and G_reader_settings:readSetting("stretch_cover_default") then + return true else - self.ui.doc_settings:saveSetting( - "proportional_screensaver", not proportional()) + return self.ui.doc_settings:readSetting("stretch_cover") == true end + end, + callback = function() + self.ui.doc_settings:saveSetting("stretch_cover", not Screensaver:stretchCover()) self.ui:saveSettings() - end - } + end, + hold_callback = function() + local ConfirmBox = require("ui/widget/confirmbox") + UIManager:show(ConfirmBox:new { + text = _("Stretch all book covers to fit screen?"), + cancel_text = _("Don't stretch"), + cancel_callback = function() + G_reader_settings:delSetting("stretch_cover_default") + return + end, + ok_text = _("Stretch"), + ok_callback = function() + G_reader_settings:saveSetting("stretch_cover_default", true) + return + end, + }) + end, + }, } } + + self.menu_items.screensaver = { + text = _("Screensaver"), + sub_item_table = require("ui/elements/screensaver_menu"), + } + table.remove(self.menu_items.screensaver.sub_item_table, 8) + table.insert(self.menu_items.screensaver.sub_item_table, ss_book_settings) end -- main menu tab -- insert common info diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 29281e573..2289563c9 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -137,7 +137,7 @@ function Device:onPowerEvent(ev) -- always suspend in portrait mode self.orig_rotation_mode = self.screen:getRotationMode() self.screen:setRotationMode(0) - require("ui/screensaver"):show("suspend", _("Sleeping")) + require("ui/screensaver"):show() self.screen:refreshFull() self.screen_saver_mode = true UIManager:scheduleIn(0.1, function() diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 487666756..eebe3eee3 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -94,8 +94,8 @@ end function Kindle:intoScreenSaver() local Screensaver = require("ui/screensaver") - if self:supportsScreensaver() and Screensaver:isUsingBookCover() then - Screensaver:show("suspend") + if self:supportsScreensaver() then + Screensaver:show() end self.powerd:beforeSuspend() if self.charging_mode == false and self.screen_saver_mode == false then @@ -114,7 +114,7 @@ function Kindle:outofScreenSaver() os.execute("killall -stop awesome") end local Screensaver = require("ui/screensaver") - if self:supportsScreensaver() and Screensaver.isUsingBookCover() then + if self:supportsScreensaver() then Screensaver:close() end local UIManager = require("ui/uimanager") diff --git a/frontend/ui/elements/screensaver_menu.lua b/frontend/ui/elements/screensaver_menu.lua new file mode 100644 index 000000000..1a223c677 --- /dev/null +++ b/frontend/ui/elements/screensaver_menu.lua @@ -0,0 +1,194 @@ +local Screensaver = require("ui/screensaver") +local _ = require("gettext") + +local function screensaverType() return G_reader_settings:readSetting("screensaver_type") end +local function screensaverDelay() return G_reader_settings:readSetting("screensaver_delay") end +local function lastFile() + local lfs = require("libs/libkoreader-lfs") + local last_file = G_reader_settings:readSetting("lastfile") + if last_file and lfs.attributes(last_file, "mode") == "file" then + return last_file + end +end +local function messageBackground() return G_reader_settings:isTrue("message_background") end + +return { + { + text = _("Use last book's cover as screensaver"), + enabled_func = function() return lastFile() ~= nil end, + checked_func = function() + if screensaverType() == "cover" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_type", "cover") + end + }, + { + text = _("Use book status as screensaver"), + enabled_func = function() return lastFile() ~= nil end, + checked_func = function() + if screensaverType() == "bookstatus" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_type", "bookstatus") + end + }, + { + text = _("Use random image from folder as screensaver"), + checked_func = function() + if screensaverType() == "random_image" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_type", "random_image") + end + }, + { + text = _("Use reading progress as screensaver"), + enabled_func = function() return Screensaver.getReaderProgress ~= nil and lastFile() ~= nil end, + checked_func = function() + if screensaverType() == "readingprogress" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_type", "readingprogress") + end + }, + { + text = _("Use message as screensaver"), + checked_func = function() + if screensaverType() == "message" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_type", "message") + end + }, + { + text = _("Leave screen as it is"), + checked_func = function() + if screensaverType() == nil or screensaverType() == "disable" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_type", "disable") + end + }, + { + text = _("Settings"), + sub_item_table = { + { + text = _("Screensaver folder"), + callback = function() + Screensaver:chooseFolder() + end, + }, + { + text = _("Screensaver message"), + callback = function() + Screensaver:setMessage() + end, + }, + { + text = _("White background in message"), + checked_func = function() + return messageBackground() + end, + callback = function() + G_reader_settings:saveSetting("message_background", not messageBackground()) + end, + separator = true, + }, + { + text = _("Delay when exit from screensaver"), + sub_item_table = { + { + text = _("Disable"), + checked_func = function() + if screensaverDelay() == nil or screensaverDelay() == "disable" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_delay", "disable") + end + }, + { + text = _("1 second"), + checked_func = function() + if screensaverDelay() == "1" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_delay", "1") + end + }, + { + text = _("3 seconds"), + checked_func = function() + if screensaverDelay() == "3" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_delay", "3") + end + }, + { + text = _("5 seconds"), + checked_func = function() + if screensaverDelay() == "5" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_delay", "5") + end + }, + { + text = _("Tap to exit screensaver"), + checked_func = function() + if screensaverDelay() == "tap" then + return true + else + return false + end + end, + callback = function() + G_reader_settings:saveSetting("screensaver_delay", "tap") + end + }, + } + } + } + } +} diff --git a/frontend/ui/screensaver.lua b/frontend/ui/screensaver.lua index d1da7b0c3..7ab268833 100644 --- a/frontend/ui/screensaver.lua +++ b/frontend/ui/screensaver.lua @@ -1,42 +1,21 @@ +local Blitbuffer = require("ffi/blitbuffer") +local ButtonDialogTitle = require("ui/widget/buttondialogtitle") +local BookStatusWidget = require("ui/widget/bookstatuswidget") local Device = require("device") local DocSettings = require("docsettings") local DocumentRegistry = require("document/documentregistry") +local InfoMessage = require("ui/widget/infomessage") +local ImageWidget = require("ui/widget/imagewidget") +local ScreenSaverWidget = require("ui/widget/screensaverwidget") local UIManager = require("ui/uimanager") +local lfs = require("libs/libkoreader-lfs") local logger = require("logger") +local _ = require("gettext") local Screen = Device.screen +local T = require("ffi/util").template -local Screensaver = { -} - -local function createWidgetFromImage(image_widget) - if image_widget then - local AlphaContainer = require("ui/widget/container/alphacontainer") - local CenterContainer = require("ui/widget/container/centercontainer") - return AlphaContainer:new{ - alpha = 1, - height = Screen:getHeight(), - width = Screen:getWidth(), - CenterContainer:new{ - dimen = Screen:getSize(), - image_widget, - } - } - end -end - -local function createWidgetFromFile(file) - if lfs.attributes(file, "mode") == "file" then - local ImageWidget = require("ui/widget/imagewidget") - return createWidgetFromImage( - ImageWidget:new{ - file = file, - file_do_cache = false, - height = Screen:getHeight(), - width = Screen:getWidth(), - scale_factor = 0, -- scale to fit height/width - }) - end -end +local default_screensaver_message = _("Sleeping") +local Screensaver = {} local function getRandomImage(dir) if string.sub(dir, string.len(dir)) ~= "/" then @@ -60,82 +39,219 @@ local function getRandomImage(dir) if i == 0 then return nil end - return createWidgetFromFile(dir .. pics[math.random(i)]) + return dir .. pics[math.random(i)] end -function Screensaver:isUsingBookCover() - -- this setting is on by default - return G_reader_settings:readSetting('use_lastfile_as_screensaver') ~= false -end - -function Screensaver:getCoverImage(file) - local ImageWidget = require("ui/widget/imagewidget") - local doc = DocumentRegistry:openDocument(file) - if not doc then return end - - local image = doc:getCoverPageImage() - doc:close() - local lastfile = G_reader_settings:readSetting("lastfile") - local doc_settings = DocSettings:open(lastfile) - if image then - local img_widget = ImageWidget:new{ - image = image, - height = Screen:getHeight(), - width = Screen:getWidth(), - scale_factor = doc_settings:readSetting("proportional_screensaver") and 0 or nil, +function Screensaver:chooseFolder() + local buttons = {} + table.insert(buttons, { + { + text = _("Choose screensaver directory by long-pressing"), + callback = function() + UIManager:close(self.choose_dialog) + require("ui/downloadmgr"):new{ + title = _("Choose screensaver directory"), + onConfirm = function(path) + logger.dbg("set screensaver directory to", path) + G_reader_settings:saveSetting("screensaver_dir", path) + UIManager:show(InfoMessage:new{ + text = T(_("Screensaver directory set to:\n%1"), path), + timeout = 3, + }) + end, + }:chooseDir() + end, } - return createWidgetFromImage(img_widget) + }) + table.insert(buttons, { + { + text = _("Close"), + callback = function() + UIManager:close(self.choose_dialog) + end, + } + }) + local screensaver_dir = G_reader_settings:readSetting("screensaver_dir") + if screensaver_dir == nil then + local DataStorage = require("datastorage") + screensaver_dir = DataStorage:getDataDir() .. "/screenshots/" end + self.choose_dialog = ButtonDialogTitle:new{ + title = T(_("Current screensaver image directory:\n %1"), screensaver_dir), + buttons = buttons + } + UIManager:show(self.choose_dialog) end -function Screensaver:show(kind, default_msg) - logger.dbg("show screensaver") - local InfoMessage = require("ui/widget/infomessage") - local screensaver_settings = G_reader_settings:readSetting(kind .. "_screensaver") or {} - -- first check book cover image, on by default - local screensaver_last_book = screensaver_settings.use_last_file or - G_reader_settings:readSetting("use_lastfile_as_screensaver") - if screensaver_last_book == nil or screensaver_last_book then +function Screensaver:stretchCover() + local lastfile = G_reader_settings:readSetting("lastfile") + if DocSettings:hasSidecarFile(lastfile) then + local doc_settings = DocSettings:open(lastfile) + local stretch_cover_ss = doc_settings:readSetting("stretch_cover") + doc_settings:close() + if stretch_cover_ss ~= nil then + return stretch_cover_ss + end + end + return G_reader_settings:readSetting("stretch_cover_default") or false +end + +function Screensaver:excluded() + local lastfile = G_reader_settings:readSetting("lastfile") + local exclude_ss = false -- consider it not excluded if there's no docsetting + if DocSettings:hasSidecarFile(lastfile) then + local doc_settings = DocSettings:open(lastfile) + exclude_ss = doc_settings:readSetting("exclude_screensaver") + doc_settings:close() + end + return exclude_ss or false +end + +function Screensaver:setMessage() + local InputDialog = require("ui/widget/inputdialog") + local screensaver_message = G_reader_settings:readSetting("screensaver_message") + if screensaver_message == nil then + screensaver_message = default_screensaver_message + end + self.input_dialog = InputDialog:new{ + title = "Screensaver message", + input = screensaver_message, + buttons = { + { + { + text = _("Cancel"), + callback = function() + UIManager:close(self.input_dialog) + end, + }, + { + text = _("Set message"), + is_enter_default = true, + callback = function() + G_reader_settings:saveSetting("screensaver_message", self.input_dialog:getInputText()) + UIManager:close(self.input_dialog) + end, + }, + }, + }, + } + self.input_dialog:onShowKeyboard() + UIManager:show(self.input_dialog) +end + +function Screensaver:show() + if self.left_msg then + UIManager:close(self.left_msg) + self.left_msg = nil + end + local screensaver_type = G_reader_settings:readSetting("screensaver_type") + local widget = nil + local background = Blitbuffer.COLOR_WHITE + if screensaver_type == "disable" or screensaver_type == nil then + return + end + if screensaver_type == "cover" then local lastfile = G_reader_settings:readSetting("lastfile") - if lastfile then + local exclude = false -- consider it not excluded if there's no docsetting + if DocSettings:hasSidecarFile(lastfile) then local doc_settings = DocSettings:open(lastfile) - local exclude = doc_settings:readSetting("exclude_screensaver") - if not exclude then - self.left_msg = self:getCoverImage(lastfile) - end + exclude = doc_settings:readSetting("exclude_screensaver") + doc_settings:close() end - end - -- then screensaver directory or file image - if not self.left_msg then - -- FIXME: rename screensaver_folder to screensaver_path - local screensaver_path = screensaver_settings.path or - G_reader_settings:readSetting("screensaver_folder") - if screensaver_path == nil - and Device.internal_storage_mount_point ~= nil then - screensaver_path = - Device.internal_storage_mount_point .. "screensaver" - end - if screensaver_path then - local mode = lfs.attributes(screensaver_path, "mode") - if mode ~= nil then - if mode == "directory" then - self.left_msg = getRandomImage(screensaver_path) + if exclude ~= true then + background = Blitbuffer.COLOR_BLACK + if lfs.attributes(lastfile, "mode") == "file" then + local doc = DocumentRegistry:openDocument(lastfile) + local image = doc:getCoverPageImage() + doc:close() + if image ~= nil then + widget = ImageWidget:new{ + image = image, + image_disposable = true, + alpha = true, + height = Screen:getHeight(), + width = Screen:getWidth(), + scale_factor = not self:stretchCover() and 0 or nil, + } else - self.left_msg = createWidgetFromFile(screensaver_path) + screensaver_type = "random_image" end + else + screensaver_type = "random_image" end + else --fallback to random images if this book cover is excluded + screensaver_type = "random_image" end end - -- fallback to message box - if not self.left_msg then - local msg = screensaver_settings.message or default_msg - if msg then - self.left_msg = InfoMessage:new{ text = msg } - UIManager:show(self.left_msg) + if screensaver_type == "bookstatus" then + local lastfile = G_reader_settings:readSetting("lastfile") + if lfs.attributes(lastfile, "mode") == "file" then + local doc = DocumentRegistry:openDocument(lastfile) + local doc_settings = DocSettings:open(lastfile) + local instance = require("apps/reader/readerui"):_getRunningInstance() + if instance ~= nil then + widget = BookStatusWidget:new { + thumbnail = doc:getCoverPageImage(), + props = doc:getProps(), + document = doc, + settings = doc_settings, + view = instance.view, + readonly = true, + } + else + screensaver_type = "message" + end + doc:close() + doc_settings:close() + else + screensaver_type = "message" end - else - -- set modal to put screensaver on top of everything else - -- NB InfoMessage (in case of no image) defaults to modal + end + if screensaver_type == "random_image" then + local screensaver_dir = G_reader_settings:readSetting("screensaver_dir") + if screensaver_dir == nil then + local DataStorage = require("datastorage") + screensaver_dir = DataStorage:getDataDir() .. "/screenshots/" + end + local image_file = getRandomImage(screensaver_dir) + if image_file == nil then + screensaver_type = "message" + else + widget = ImageWidget:new{ + file = image_file, + alpha = true, + height = Screen:getHeight(), + width = Screen:getWidth(), + scale_factor = 0, + } + end + end + if screensaver_type == "readingprogress" then + if Screensaver.getReaderProgress ~= nil then + widget = Screensaver.getReaderProgress() + else + screensaver_type = "message" + end + end + if screensaver_type == "message" then + local screensaver_message = G_reader_settings:readSetting("screensaver_message") + if G_reader_settings:nilOrFalse("message_background") then + background = nil + end + if screensaver_message == nil then + screensaver_message = default_screensaver_message + end + widget = InfoMessage:new{ + text = screensaver_message, + readonly = true, + } + end + + if widget then + self.left_msg = ScreenSaverWidget:new{ + widget = widget, + background = background, + } self.left_msg.modal = true -- refresh whole screen for other types UIManager:show(self.left_msg, "full") @@ -143,10 +259,26 @@ function Screensaver:show(kind, default_msg) end function Screensaver:close() - logger.dbg("close screensaver") - if self.left_msg then - UIManager:close(self.left_msg) - self.left_msg = nil + if self.left_msg == nil then return end + local screensaver_delay = G_reader_settings:readSetting("screensaver_delay") + local screensaver_delay_number = tonumber(screensaver_delay) + if screensaver_delay_number then + UIManager:scheduleIn(screensaver_delay_number, function() + logger.dbg("close screensaver") + if self.left_msg then + UIManager:close(self.left_msg) + UIManager:setDirty("all", "full") + self.left_msg = nil + end + end) + elseif screensaver_delay == "disable" or screensaver_delay == nil then + logger.dbg("close screensaver") + if self.left_msg then + UIManager:close(self.left_msg) + self.left_msg = nil + end + else + logger.dbg("tap to exit from screensaver") end end diff --git a/frontend/ui/widget/bookstatuswidget.lua b/frontend/ui/widget/bookstatuswidget.lua index d7503c0d7..daf63835e 100644 --- a/frontend/ui/widget/bookstatuswidget.lua +++ b/frontend/ui/widget/bookstatuswidget.lua @@ -68,13 +68,19 @@ function BookStatusWidget:init() self.medium_font_face = Font:getFace("ffont") self.large_font_face = Font:getFace("largeffont") + local button_enabled = true + if self.readonly then + button_enabled = false + end + self.star = Button:new{ icon = "resources/icons/stats.star.empty.png", bordersize = 0, radius = 0, margin = 0, - enabled = true, + enabled = button_enabled, show_parent = self, + readonly = self.readonly, } local screen_size = Screen:getSize() self[1] = FrameContainer:new{ @@ -116,20 +122,28 @@ function BookStatusWidget:getStatReadPages() end function BookStatusWidget:getStatusContent(width) - return VerticalGroup:new{ + local close_button = nil + local status_header = self:genHeader(_("Book Status")) + + if self.readonly ~= true then + close_button = CloseButton:new{ window = self } + status_header = self:genHeader(_("Update Status")) + end + local content = VerticalGroup:new{ align = "left", OverlapGroup:new{ dimen = Geom:new{ w = width, h = Size.item.height_default }, - CloseButton:new{ window = self }, + close_button, }, self:genBookInfoGroup(), self:genHeader(_("Statistics")), self:genStatisticsGroup(width), self:genHeader(_("Review")), self:genSummaryGroup(width), - self:genHeader(_("Update Status")), + status_header, self:generateSwitchGroup(width), } + return content end function BookStatusWidget:genHeader(title) @@ -411,6 +425,7 @@ function BookStatusWidget:genSummaryGroup(width) focused = false, padding = text_padding, parent = self, + readonly = self.readonly, hint = _("A few words about the book"), } @@ -468,6 +483,10 @@ function BookStatusWidget:generateSwitchGroup(width) enabled = true, } + if self.readonly then + config.enable = false + end + local switch = ToggleSwitch:new{ width = width * 0.6, default_value = config.default_value, @@ -481,6 +500,7 @@ function BookStatusWidget:generateSwitchGroup(width) values = config.values, enabled = config.enable, config = self, + readonly = self.readonly, } switch:setPosition(position) diff --git a/frontend/ui/widget/button.lua b/frontend/ui/widget/button.lua index 3663a0c23..e5585bf60 100644 --- a/frontend/ui/widget/button.lua +++ b/frontend/ui/widget/button.lua @@ -210,7 +210,9 @@ function Button:onTapSelectButton() elseif type(self.tap_input_func) == "function" then self:onInput(self.tap_input_func()) end - return true + if self.readonly ~= true then + return true + end end function Button:onHoldSelectButton() diff --git a/frontend/ui/widget/infomessage.lua b/frontend/ui/widget/infomessage.lua index 1ca2307b5..116c63938 100644 --- a/frontend/ui/widget/infomessage.lua +++ b/frontend/ui/widget/infomessage.lua @@ -163,13 +163,17 @@ function InfoMessage:onAnyKeyPressed() -- triggered by our defined key events self.dismiss_callback() UIManager:close(self) - return true + if self.readonly ~= true then + return true + end end function InfoMessage:onTapClose() self.dismiss_callback() UIManager:close(self) - return true + if self.readonly ~= true then + return true + end end return InfoMessage diff --git a/frontend/ui/widget/inputtext.lua b/frontend/ui/widget/inputtext.lua index 0a92cf2bc..b64a28e3e 100644 --- a/frontend/ui/widget/inputtext.lua +++ b/frontend/ui/widget/inputtext.lua @@ -72,8 +72,10 @@ end function InputText:init() self:initTextBox(self.text) - self:initKeyboard() - self:initEventListener() + if self.readonly ~= true then + self:initKeyboard() + self:initEventListener() + end end function InputText:initTextBox(text, char_added, is_password_type) diff --git a/frontend/ui/widget/screensaverwidget.lua b/frontend/ui/widget/screensaverwidget.lua new file mode 100644 index 000000000..f9b599625 --- /dev/null +++ b/frontend/ui/widget/screensaverwidget.lua @@ -0,0 +1,92 @@ +local Device = require("device") +local Geom = require("ui/geometry") +local GestureRange = require("ui/gesturerange") +local FrameContainer = require("ui/widget/container/framecontainer") +local InputContainer = require("ui/widget/container/inputcontainer") +local UIManager = require("ui/uimanager") +local Screen = Device.screen + +local ScreenSaverWidget = InputContainer:new{ + widget = nil, + background = nil, +} + +function ScreenSaverWidget:init() + if Device:hasKeys() then + self.key_events = { + Close = { {"Back"}, doc = "close widget" }, + } + end + if Device:isTouchDevice() then + local range = Geom:new{ + x = 0, y = 0, + w = Screen:getWidth(), + h = Screen:getHeight(), + } + self.ges_events = { + Tap = { GestureRange:new{ ges = "tap", range = range } }, + } + end + self:update() +end + +function ScreenSaverWidget:update() + self.height = Screen:getHeight() + self.width = Screen:getWidth() + + self.region = Geom:new{ + x = 0, y = 0, + w = self.width, + h = self.height, + } + self.main_frame = FrameContainer:new{ + radius = 0, + bordersize = 0, + padding = 0, + margin = 0, + background = self.background, + width = self.width, + height = self.height, + self.widget, + } + self[1] = self.main_frame + UIManager:setDirty("all", function() + local update_region = self.main_frame.dimen + return "partial", update_region + end) +end + +function ScreenSaverWidget:onShow() + UIManager:setDirty(self, function() + return "full", self.main_frame.dimen + end) + return true +end + +function ScreenSaverWidget:onTap(_, ges) + if ges.pos:intersectWith(self.main_frame.dimen) then + self:onClose() + UIManager:setDirty("all", "full") + end + return true +end + +function ScreenSaverWidget:onClose() + UIManager:close(self) + UIManager:setDirty("all", "full") + return true +end + +function ScreenSaverWidget:onAnyKeyPressed() + self:onClose() + return true +end + +function ScreenSaverWidget:onCloseWidget() + UIManager:setDirty(nil, function() + return "partial", self.main_frame.dimen + end) + return true +end + +return ScreenSaverWidget diff --git a/frontend/ui/widget/toggleswitch.lua b/frontend/ui/widget/toggleswitch.lua index 1ed81172e..179f58d3d 100644 --- a/frontend/ui/widget/toggleswitch.lua +++ b/frontend/ui/widget/toggleswitch.lua @@ -161,7 +161,13 @@ function ToggleSwitch:calculatePosition(gev) end function ToggleSwitch:onTapSelect(arg, gev) - if not self.enabled then return true end + if not self.enabled then + if self.readonly ~= true then + return true + else + return + end + end local position = self:calculatePosition(gev) self:togglePosition(position) --[[ diff --git a/plugins/statistics.koplugin/main.lua b/plugins/statistics.koplugin/main.lua index 9b7955bd1..d12e3ad44 100755 --- a/plugins/statistics.koplugin/main.lua +++ b/plugins/statistics.koplugin/main.lua @@ -8,6 +8,7 @@ local MultiInputDialog = require("ui/widget/multiinputdialog") local ReaderFooter = require("apps/reader/modules/readerfooter") local ReaderProgress = require("readerprogress") local ReadHistory = require("readhistory") +local Screensaver = require("ui/screensaver") local SQ3 = require("lua-ljsqlite3/init") local TimeVal = require("ui/timeval") local UIManager = require("ui/uimanager") @@ -104,6 +105,24 @@ function ReaderStatistics:init() return self.avg_time end end + Screensaver.getReaderProgress = function() + local readingprogress + self:insertDB(self.id_curr_book) + local current_period, current_pages = self:getCurrentBookStats() + local today_period, today_pages = self:getTodayBookStats() + local dates_stats = self:getReadingProgressStats(7) + if dates_stats then + readingprogress = ReaderProgress:new{ + dates = dates_stats, + current_period = current_period, + current_pages = current_pages, + today_period = today_period, + today_pages = today_pages, + readonly = true, + } + end + return readingprogress + end end function ReaderStatistics:initData() diff --git a/plugins/statistics.koplugin/readerprogress.lua b/plugins/statistics.koplugin/readerprogress.lua index 8e063fe73..5c2bf8d1b 100644 --- a/plugins/statistics.koplugin/readerprogress.lua +++ b/plugins/statistics.koplugin/readerprogress.lua @@ -67,11 +67,15 @@ function ReaderProgress:getTotalStats(stats_day) end function ReaderProgress:getStatusContent(width) + local close_button = nil + if self.readonly ~= true then + close_button = CloseButton:new{ window = self } + end return VerticalGroup:new{ align = "left", OverlapGroup:new{ dimen = Geom:new{ w = width, h = Size.item.height_default }, - CloseButton:new{ window = self }, + close_button, }, self:genSingleHeader(_("Last week")), self:genSummaryWeek(width),