mirror of
https://github.com/koreader/koreader.git
synced 2025-12-18 12:02:09 +01:00
ReaderGesture: cleanup (#6292)
convert all gesture actions to use events for better modularity add network event handlers and device event handlers
This commit is contained in:
@@ -22,7 +22,6 @@ frontend
|
|||||||
│ │ ├── readerflipping.lua
|
│ │ ├── readerflipping.lua
|
||||||
│ │ ├── readerfont.lua
|
│ │ ├── readerfont.lua
|
||||||
│ │ ├── readerfooter.lua
|
│ │ ├── readerfooter.lua
|
||||||
│ │ ├── readerfrontlight.lua
|
|
||||||
│ │ ├── readergoto.lua
|
│ │ ├── readergoto.lua
|
||||||
│ │ ├── readerhighlight.lua
|
│ │ ├── readerhighlight.lua
|
||||||
│ │ ├── readerhinting.lua
|
│ │ ├── readerhinting.lua
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
|||||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
|
local DeviceListener = require("device/devicelistener")
|
||||||
local DocSettings = require("docsettings")
|
local DocSettings = require("docsettings")
|
||||||
local DocumentRegistry = require("document/documentregistry")
|
local DocumentRegistry = require("document/documentregistry")
|
||||||
local Event = require("ui/event")
|
local Event = require("ui/event")
|
||||||
@@ -463,6 +464,7 @@ function FileManager:init()
|
|||||||
table.insert(self, ReaderDictionary:new{ ui = self })
|
table.insert(self, ReaderDictionary:new{ ui = self })
|
||||||
table.insert(self, ReaderWikipedia:new{ ui = self })
|
table.insert(self, ReaderWikipedia:new{ ui = self })
|
||||||
table.insert(self, ReaderDeviceStatus:new{ ui = self })
|
table.insert(self, ReaderDeviceStatus:new{ ui = self })
|
||||||
|
table.insert(self, DeviceListener:new{ ui = self })
|
||||||
|
|
||||||
-- koreader plugins
|
-- koreader plugins
|
||||||
for _,plugin_module in ipairs(PluginLoader:loadPlugins()) do
|
for _,plugin_module in ipairs(PluginLoader:loadPlugins()) do
|
||||||
@@ -484,6 +486,11 @@ function FileManager:init()
|
|||||||
table.insert(self, ReaderGesture:new{ ui = self })
|
table.insert(self, ReaderGesture:new{ ui = self })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Device:hasWifiToggle() then
|
||||||
|
local NetworkListener = require("ui/network/networklistener")
|
||||||
|
table.insert(self, NetworkListener:new{ ui = self })
|
||||||
|
end
|
||||||
|
|
||||||
if Device:hasKeys() then
|
if Device:hasKeys() then
|
||||||
self.key_events.Home = { {"Home"}, doc = "go home" }
|
self.key_events.Home = { {"Home"}, doc = "go home" }
|
||||||
--Override the menu.lua way of handling the back key
|
--Override the menu.lua way of handling the back key
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ function FileSearcher:close()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function FileSearcher:onShowFileSearch(search_path)
|
function FileSearcher:onShowFileSearch()
|
||||||
local dummy = self.search_value
|
local dummy = self.search_value
|
||||||
local enabled_search_home_dir = true
|
local enabled_search_home_dir = true
|
||||||
if not G_reader_settings:readSetting("home_dir") then
|
if not G_reader_settings:readSetting("home_dir") then
|
||||||
@@ -129,7 +129,7 @@ function FileSearcher:onShowFileSearch(search_path)
|
|||||||
text = _("Current folder"),
|
text = _("Current folder"),
|
||||||
enabled = true,
|
enabled = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
self.path = search_path or lfs.currentdir()
|
self.path = self.ui.file_chooser and self.ui.file_chooser.path or self.ui:getLastDirFile()
|
||||||
self.search_value = self.search_dialog:getInputText()
|
self.search_value = self.search_dialog:getInputText()
|
||||||
if self.search_value == dummy then -- probably DELETE this if/else block
|
if self.search_value == dummy then -- probably DELETE this if/else block
|
||||||
self.use_previous_search_results = true
|
self.use_previous_search_results = true
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ function FileManagerMenu:initGesListener()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function FileManagerMenu:openLastDoc()
|
function FileManagerMenu:onOpenLastDoc()
|
||||||
local last_file = G_reader_settings:readSetting("lastfile")
|
local last_file = G_reader_settings:readSetting("lastfile")
|
||||||
if not last_file or lfs.attributes(last_file, "mode") ~= "file" then
|
if not last_file or lfs.attributes(last_file, "mode") ~= "file" then
|
||||||
local InfoMessage = require("ui/widget/infomessage")
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
@@ -478,7 +478,7 @@ function FileManagerMenu:setUpdateItemTable()
|
|||||||
-- @translators Search for files by name.
|
-- @translators Search for files by name.
|
||||||
text = _("Find a file"),
|
text = _("Find a file"),
|
||||||
callback = function()
|
callback = function()
|
||||||
self.ui:handleEvent(Event:new("ShowFileSearch", self.ui.file_chooser.path))
|
self.ui:handleEvent(Event:new("ShowFileSearch"))
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -496,7 +496,7 @@ function FileManagerMenu:setUpdateItemTable()
|
|||||||
return G_reader_settings:readSetting("lastfile") ~= nil
|
return G_reader_settings:readSetting("lastfile") ~= nil
|
||||||
end,
|
end,
|
||||||
callback = function()
|
callback = function()
|
||||||
self:openLastDoc()
|
self:onOpenLastDoc()
|
||||||
end,
|
end,
|
||||||
hold_callback = function()
|
hold_callback = function()
|
||||||
local last_file = G_reader_settings:readSetting("lastfile")
|
local last_file = G_reader_settings:readSetting("lastfile")
|
||||||
@@ -504,7 +504,7 @@ function FileManagerMenu:setUpdateItemTable()
|
|||||||
text = T(_("Would you like to open the last document: %1?"), BD.filepath(last_file)),
|
text = T(_("Would you like to open the last document: %1?"), BD.filepath(last_file)),
|
||||||
ok_text = _("OK"),
|
ok_text = _("OK"),
|
||||||
ok_callback = function()
|
ok_callback = function()
|
||||||
self:openLastDoc()
|
self:onOpenLastDoc()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -819,7 +819,7 @@ function ReaderDictionary:showDict(word, results, box, link)
|
|||||||
refresh_callback = function()
|
refresh_callback = function()
|
||||||
if self.view then
|
if self.view then
|
||||||
-- update info in footer (time, battery, etc)
|
-- update info in footer (time, battery, etc)
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
html_dictionary_link_tapped_callback = function(dictionary, html_link)
|
html_dictionary_link_tapped_callback = function(dictionary, html_link)
|
||||||
|
|||||||
@@ -320,31 +320,32 @@ function ReaderFont:addToMainMenu(menu_items)
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
-- direction +1 - increase font size
|
function ReaderFont:gesToFontSize(ges)
|
||||||
-- direction -1 - decrease font size
|
|
||||||
function ReaderFont:onAdjustFontSize(ges, direction)
|
|
||||||
if ges.distance == nil then
|
if ges.distance == nil then
|
||||||
ges.distance = 1
|
ges.distance = 1
|
||||||
end
|
end
|
||||||
if direction ~= -1 and direction ~= 1 then
|
|
||||||
-- set default value (increase font size)
|
|
||||||
direction = 1
|
|
||||||
end
|
|
||||||
local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale)
|
local step = math.ceil(2 * #self.steps * ges.distance / self.gestureScale)
|
||||||
local delta_int = self.steps[step] or self.steps[#self.steps]
|
local delta_int = self.steps[step] or self.steps[#self.steps]
|
||||||
if direction == 1 then
|
return delta_int
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderFont:onIncreaseFontSize(ges)
|
||||||
|
local delta_int = self:gesToFontSize(ges)
|
||||||
local info = Notification:new{text = _("Increasing font size…")}
|
local info = Notification:new{text = _("Increasing font size…")}
|
||||||
UIManager:show(info)
|
UIManager:show(info)
|
||||||
UIManager:forceRePaint()
|
UIManager:forceRePaint()
|
||||||
self:onChangeSize("increase", delta_int)
|
self:onChangeSize("increase", delta_int)
|
||||||
UIManager:close(info)
|
UIManager:close(info)
|
||||||
else
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderFont:onDecreaseFontSize(ges)
|
||||||
|
local delta_int = self:gesToFontSize(ges)
|
||||||
local info = Notification:new{text = _("Decreasing font size…")}
|
local info = Notification:new{text = _("Decreasing font size…")}
|
||||||
UIManager:show(info)
|
UIManager:show(info)
|
||||||
UIManager:forceRePaint()
|
UIManager:forceRePaint()
|
||||||
self:onChangeSize("decrease", delta_int)
|
self:onChangeSize("decrease", delta_int)
|
||||||
UIManager:close(info)
|
UIManager:close(info)
|
||||||
end
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ end
|
|||||||
function ReaderFooter:setupAutoRefreshTime()
|
function ReaderFooter:setupAutoRefreshTime()
|
||||||
if not self.autoRefreshTime then
|
if not self.autoRefreshTime then
|
||||||
self.autoRefreshTime = function()
|
self.autoRefreshTime = function()
|
||||||
self:updateFooter(true)
|
self:onUpdateFooter(true)
|
||||||
UIManager:scheduleIn(61 - tonumber(os.date("%S")), self.autoRefreshTime)
|
UIManager:scheduleIn(61 - tonumber(os.date("%S")), self.autoRefreshTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -839,7 +839,7 @@ function ReaderFooter:addToMainMenu(menu_items)
|
|||||||
self.settings.order = self.mode_index
|
self.settings.order = self.mode_index
|
||||||
G_reader_settings:saveSetting("footer", self.settings)
|
G_reader_settings:saveSetting("footer", self.settings)
|
||||||
self:updateFooterTextGenerator()
|
self:updateFooterTextGenerator()
|
||||||
self:updateFooter()
|
self:onUpdateFooter()
|
||||||
UIManager:setDirty(nil, "ui")
|
UIManager:setDirty(nil, "ui")
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
@@ -1686,7 +1686,7 @@ function ReaderFooter:getDataFromStatistics(title, pages)
|
|||||||
return title .. sec
|
return title .. sec
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderFooter:updateFooter(force_repaint, force_recompute)
|
function ReaderFooter:onUpdateFooter(force_repaint, force_recompute)
|
||||||
if self.pageno then
|
if self.pageno then
|
||||||
self:updateFooterPage(force_repaint, force_recompute)
|
self:updateFooterPage(force_repaint, force_recompute)
|
||||||
else
|
else
|
||||||
@@ -1811,7 +1811,7 @@ function ReaderFooter:onReaderReady()
|
|||||||
self:resetLayout(self.settings.progress_margin_width) -- set widget dimen
|
self:resetLayout(self.settings.progress_margin_width) -- set widget dimen
|
||||||
self:setTocMarkers()
|
self:setTocMarkers()
|
||||||
self.updateFooterText = self._updateFooterText
|
self.updateFooterText = self._updateFooterText
|
||||||
self:updateFooter()
|
self:onUpdateFooter()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderFooter:onReadSettings(config)
|
function ReaderFooter:onReadSettings(config)
|
||||||
@@ -1894,7 +1894,7 @@ function ReaderFooter:onTapFooter(ges)
|
|||||||
local percentage = (pos.x - dimen.x)/dimen.w
|
local percentage = (pos.x - dimen.x)/dimen.w
|
||||||
self.ui:handleEvent(Event:new("GotoPercentage", percentage))
|
self.ui:handleEvent(Event:new("GotoPercentage", percentage))
|
||||||
end
|
end
|
||||||
self:updateFooter(true)
|
self:onUpdateFooter(true)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if self.has_no_mode or (self.settings.lock_tap and not ignore_lock) then
|
if self.has_no_mode or (self.settings.lock_tap and not ignore_lock) then
|
||||||
@@ -1921,7 +1921,7 @@ function ReaderFooter:onTapFooter(ges)
|
|||||||
end
|
end
|
||||||
self:applyFooterMode()
|
self:applyFooterMode()
|
||||||
G_reader_settings:saveSetting("reader_footer_mode", self.mode)
|
G_reader_settings:saveSetting("reader_footer_mode", self.mode)
|
||||||
self:updateFooter(true)
|
self:onUpdateFooter(true)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -1949,14 +1949,14 @@ function ReaderFooter:refreshFooter(refresh, signal)
|
|||||||
self:resetLayout(true)
|
self:resetLayout(true)
|
||||||
-- If we signal, the event we send will trigger a full repaint anyway, so we should be able to skip this one.
|
-- If we signal, the event we send will trigger a full repaint anyway, so we should be able to skip this one.
|
||||||
-- We *do* need to ensure we at least re-compute the footer layout, though, especially when going from visible to invisible...
|
-- We *do* need to ensure we at least re-compute the footer layout, though, especially when going from visible to invisible...
|
||||||
self:updateFooter(refresh and not signal, refresh and signal)
|
self:onUpdateFooter(refresh and not signal, refresh and signal)
|
||||||
if signal then
|
if signal then
|
||||||
self.ui:handleEvent(Event:new("SetPageBottomMargin", self.view.document.configurable.b_page_margin))
|
self.ui:handleEvent(Event:new("SetPageBottomMargin", self.view.document.configurable.b_page_margin))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderFooter:onResume()
|
function ReaderFooter:onResume()
|
||||||
self:updateFooter()
|
self:onUpdateFooter()
|
||||||
if self.settings.auto_refresh_time then
|
if self.settings.auto_refresh_time then
|
||||||
self:setupAutoRefreshTime()
|
self:setupAutoRefreshTime()
|
||||||
end
|
end
|
||||||
@@ -1971,7 +1971,7 @@ end
|
|||||||
|
|
||||||
function ReaderFooter:onFrontlightStateChanged()
|
function ReaderFooter:onFrontlightStateChanged()
|
||||||
if self.settings.frontlight then
|
if self.settings.frontlight then
|
||||||
self:updateFooter(true)
|
self:onUpdateFooter(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,192 +0,0 @@
|
|||||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
|
||||||
local Notification = require("ui/widget/notification")
|
|
||||||
local UIManager = require("ui/uimanager")
|
|
||||||
local Screen = require("device").screen
|
|
||||||
local Device = require("device")
|
|
||||||
local T = require("ffi/util").template
|
|
||||||
local _ = require("gettext")
|
|
||||||
|
|
||||||
local ReaderFrontLight = InputContainer:new{
|
|
||||||
steps_fl = { 0.1, 0.1, 0.2, 0.4, 0.7, 1.1, 1.6, 2.2, 2.9, 3.7, 4.6, 5.6, 6.7, 7.9, 9.2, 10.6, },
|
|
||||||
gestureScale = Screen:getWidth() * FRONTLIGHT_SENSITIVITY_DECREASE,
|
|
||||||
}
|
|
||||||
|
|
||||||
-- direction +1 - increase frontlight
|
|
||||||
-- direction -1 - decrease frontlight
|
|
||||||
function ReaderFrontLight:onChangeFlIntensity(ges, direction)
|
|
||||||
local powerd = Device:getPowerDevice()
|
|
||||||
local gestureScale
|
|
||||||
local scale_multiplier
|
|
||||||
if ges.ges == "two_finger_swipe" then
|
|
||||||
-- for backward compatibility
|
|
||||||
scale_multiplier = FRONTLIGHT_SENSITIVITY_DECREASE * 0.8
|
|
||||||
elseif ges.ges == "swipe" then
|
|
||||||
scale_multiplier = 0.8
|
|
||||||
else
|
|
||||||
scale_multiplier = 1
|
|
||||||
end
|
|
||||||
if ges.direction == "south" or ges.direction == "north" then
|
|
||||||
gestureScale = Screen:getHeight() * scale_multiplier
|
|
||||||
elseif ges.direction == "west" or ges.direction == "east" then
|
|
||||||
gestureScale = Screen:getWidth() * scale_multiplier
|
|
||||||
else
|
|
||||||
local width = Screen:getWidth()
|
|
||||||
local height = Screen:getHeight()
|
|
||||||
-- diagonal
|
|
||||||
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
|
||||||
end
|
|
||||||
if powerd.fl_intensity == nil then return false end
|
|
||||||
|
|
||||||
local steps_tbl = {}
|
|
||||||
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
|
|
||||||
for i = 1, #self.steps_fl, 1
|
|
||||||
do
|
|
||||||
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
|
|
||||||
end
|
|
||||||
|
|
||||||
if ges.distance == nil then
|
|
||||||
ges.distance = 1
|
|
||||||
end
|
|
||||||
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
|
|
||||||
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
|
|
||||||
if direction ~= -1 and direction ~= 1 then
|
|
||||||
-- set default value (increase frontlight)
|
|
||||||
direction = 1
|
|
||||||
end
|
|
||||||
local new_intensity = powerd.fl_intensity + direction * delta_int
|
|
||||||
|
|
||||||
if new_intensity == nil then return true end
|
|
||||||
-- when new_intensity <=0, toggle light off
|
|
||||||
if new_intensity <= 0 then
|
|
||||||
powerd:turnOffFrontlight()
|
|
||||||
else
|
|
||||||
powerd:setIntensity(new_intensity)
|
|
||||||
end
|
|
||||||
self:onShowIntensity()
|
|
||||||
if self.view and self.view.footer_visible and self.view.footer.settings.frontlight then
|
|
||||||
self.view.footer:updateFooter()
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
-- direction +1 - increase frontlight warmth
|
|
||||||
-- direction -1 - decrease frontlight warmth
|
|
||||||
function ReaderFrontLight:onChangeFlWarmth(ges, direction)
|
|
||||||
local powerd = Device:getPowerDevice()
|
|
||||||
if powerd.fl_warmth == nil then return false end
|
|
||||||
|
|
||||||
if powerd.auto_warmth then
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = _("Warmth is handled automatically."),
|
|
||||||
timeout = 1.0,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local gestureScale
|
|
||||||
local scale_multiplier
|
|
||||||
if ges.ges == "two_finger_swipe" then
|
|
||||||
-- for backward compatibility
|
|
||||||
scale_multiplier = FRONTLIGHT_SENSITIVITY_DECREASE * 0.8
|
|
||||||
elseif ges.ges == "swipe" then
|
|
||||||
scale_multiplier = 0.8
|
|
||||||
else
|
|
||||||
scale_multiplier = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if ges.direction == "south" or ges.direction == "north" then
|
|
||||||
gestureScale = Screen:getHeight() * scale_multiplier
|
|
||||||
elseif ges.direction == "west" or ges.direction == "east" then
|
|
||||||
gestureScale = Screen:getWidth() * scale_multiplier
|
|
||||||
else
|
|
||||||
local width = Screen:getWidth()
|
|
||||||
local height = Screen:getHeight()
|
|
||||||
-- diagonal
|
|
||||||
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
|
||||||
end
|
|
||||||
|
|
||||||
local steps_tbl = {}
|
|
||||||
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
|
|
||||||
for i = 1, #self.steps_fl, 1
|
|
||||||
do
|
|
||||||
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
|
|
||||||
end
|
|
||||||
|
|
||||||
if ges.distance == nil then
|
|
||||||
ges.distance = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
|
|
||||||
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
|
|
||||||
local warmth
|
|
||||||
if direction ~= -1 and direction ~= 1 then
|
|
||||||
-- set default value (increase frontlight)
|
|
||||||
direction = 1
|
|
||||||
end
|
|
||||||
warmth = powerd.fl_warmth + direction * delta_int
|
|
||||||
if warmth > 100 then
|
|
||||||
warmth = 100
|
|
||||||
elseif warmth < 0 then
|
|
||||||
warmth = 0
|
|
||||||
end
|
|
||||||
powerd:setWarmth(warmth)
|
|
||||||
self:onShowWarmth()
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function ReaderFrontLight:onShowOnOff()
|
|
||||||
local powerd = Device:getPowerDevice()
|
|
||||||
local new_text
|
|
||||||
if powerd.is_fl_on then
|
|
||||||
new_text = _("Frontlight enabled.")
|
|
||||||
else
|
|
||||||
new_text = _("Frontlight disabled.")
|
|
||||||
end
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = new_text,
|
|
||||||
timeout = 1.0,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderFrontLight:onShowIntensity()
|
|
||||||
if not Device:hasFrontlight() then return true end
|
|
||||||
local powerd = Device:getPowerDevice()
|
|
||||||
local new_text
|
|
||||||
if powerd:isFrontlightOff() then
|
|
||||||
new_text = _("Frontlight disabled.")
|
|
||||||
else
|
|
||||||
new_text = T(_("Frontlight intensity set to %1."), powerd:frontlightIntensity())
|
|
||||||
end
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = new_text,
|
|
||||||
timeout = 1,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderFrontLight:onShowWarmth(value)
|
|
||||||
local powerd = Device:getPowerDevice()
|
|
||||||
if powerd.fl_warmth ~= nil then
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = T(_("Warmth set to %1."), powerd.fl_warmth),
|
|
||||||
timeout = 1.0,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderFrontLight:onShowFlDialog()
|
|
||||||
local FrontLightWidget = require("ui/widget/frontlightwidget")
|
|
||||||
UIManager:show(FrontLightWidget:new{
|
|
||||||
use_system_fl = Device:hasLightLevelFallback()
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderFrontLight:close()
|
|
||||||
self.fl_dialog:onClose()
|
|
||||||
UIManager:close(self.fl_dialog)
|
|
||||||
end
|
|
||||||
|
|
||||||
return ReaderFrontLight
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
local BD = require("ui/bidi")
|
local BD = require("ui/bidi")
|
||||||
local bit = require("bit")
|
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
local DataStorage = require("datastorage")
|
local DataStorage = require("datastorage")
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
@@ -10,7 +9,6 @@ local InfoMessage = require("ui/widget/infomessage")
|
|||||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
local InputDialog = require("ui/widget/inputdialog")
|
local InputDialog = require("ui/widget/inputdialog")
|
||||||
local LuaData = require("luadata")
|
local LuaData = require("luadata")
|
||||||
local Notification = require("ui/widget/notification")
|
|
||||||
local Screen = require("device").screen
|
local Screen = require("device").screen
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
local T = require("ffi/util").template
|
local T = require("ffi/util").template
|
||||||
@@ -774,7 +772,7 @@ function ReaderGesture:buildMenu(ges, default)
|
|||||||
|
|
||||||
{"toc", not self.is_docless},
|
{"toc", not self.is_docless},
|
||||||
{"bookmarks", not self.is_docless},
|
{"bookmarks", not self.is_docless},
|
||||||
{"reading_progress", ReaderGesture.getReaderProgress ~= nil},
|
{"reading_progress", not self.is_docless},
|
||||||
{"book_statistics", not self.is_docless},
|
{"book_statistics", not self.is_docless},
|
||||||
|
|
||||||
{"book_status", not self.is_docless},
|
{"book_status", not self.is_docless},
|
||||||
@@ -812,7 +810,7 @@ function ReaderGesture:buildMenu(ges, default)
|
|||||||
|
|
||||||
{"toggle_hold_corners", true},
|
{"toggle_hold_corners", true},
|
||||||
{"toggle_gsensor", Device:canToggleGSensor()},
|
{"toggle_gsensor", Device:canToggleGSensor()},
|
||||||
{"toggle_rotation", not self.is_docless, true},
|
{"toggle_rotation", true, true},
|
||||||
|
|
||||||
{"wifi_on", Device:hasWifiToggle()},
|
{"wifi_on", Device:hasWifiToggle()},
|
||||||
{"wifi_off", Device:hasWifiToggle()},
|
{"wifi_off", Device:hasWifiToggle()},
|
||||||
@@ -1344,33 +1342,22 @@ function ReaderGesture:registerGesture(ges, action, ges_type, zone, overrides, d
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
local function lightFrontlight()
|
|
||||||
return Device:hasLightLevelFallback() and G_reader_settings:nilOrTrue("light_fallback")
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderGesture:gestureAction(action, ges)
|
function ReaderGesture:gestureAction(action, ges)
|
||||||
if action == "ignore"
|
if action == "ignore"
|
||||||
or (ges.ges == "hold" and self.ignore_hold_corners) then
|
or (ges.ges == "hold" and self.ignore_hold_corners) then
|
||||||
return
|
return
|
||||||
elseif action == "reading_progress" and ReaderGesture.getReaderProgress then
|
elseif action == "reading_progress" then
|
||||||
UIManager:show(ReaderGesture.getReaderProgress())
|
self.ui:handleEvent(Event:new("ShowReaderProgress"))
|
||||||
elseif action == "book_statistics" and ReaderGesture.getBookStats then
|
elseif action == "book_statistics" then
|
||||||
UIManager:show(ReaderGesture.getBookStats())
|
self.ui:handleEvent(Event:new("ShowBookStats"))
|
||||||
elseif action == "stats_calendar_view" and ReaderGesture.getCalendarView then
|
elseif action == "stats_calendar_view" then
|
||||||
UIManager:show(ReaderGesture.getCalendarView())
|
self.ui:handleEvent(Event:new("ShowCalendarView"))
|
||||||
elseif action == "toc" then
|
elseif action == "toc" then
|
||||||
self.ui:handleEvent(Event:new("ShowToc"))
|
self.ui:handleEvent(Event:new("ShowToc"))
|
||||||
elseif action == "night_mode" then
|
elseif action == "night_mode" then
|
||||||
local night_mode = G_reader_settings:isTrue("night_mode")
|
self.ui:handleEvent(Event:new("ToggleNightMode"))
|
||||||
Screen:toggleNightMode()
|
|
||||||
UIManager:setDirty("all", "full")
|
|
||||||
G_reader_settings:saveSetting("night_mode", not night_mode)
|
|
||||||
elseif action == "full_refresh" then
|
elseif action == "full_refresh" then
|
||||||
if self.view then
|
self.ui:handleEvent(Event:new("FullRefresh"))
|
||||||
-- update footer (time & battery)
|
|
||||||
self.view.footer:updateFooter()
|
|
||||||
end
|
|
||||||
UIManager:setDirty("all", "full")
|
|
||||||
elseif action == "bookmarks" then
|
elseif action == "bookmarks" then
|
||||||
self.ui:handleEvent(Event:new("ShowBookmark"))
|
self.ui:handleEvent(Event:new("ShowBookmark"))
|
||||||
elseif action == "history" then
|
elseif action == "history" then
|
||||||
@@ -1386,21 +1373,19 @@ function ReaderGesture:gestureAction(action, ges)
|
|||||||
elseif action == "book_status" then
|
elseif action == "book_status" then
|
||||||
self.ui:handleEvent(Event:new("ShowBookStatus"))
|
self.ui:handleEvent(Event:new("ShowBookStatus"))
|
||||||
elseif action == "page_jmp_fwd_10" then
|
elseif action == "page_jmp_fwd_10" then
|
||||||
self:pageUpdate(10)
|
self.ui:handleEvent(Event:new("GotoRelativePage", 10))
|
||||||
elseif action == "page_jmp_fwd_1" then
|
elseif action == "page_jmp_fwd_1" then
|
||||||
self.ui:handleEvent(Event:new("GotoViewRel", 1))
|
self.ui:handleEvent(Event:new("GotoViewRel", 1))
|
||||||
elseif action == "page_jmp_back_10" then
|
elseif action == "page_jmp_back_10" then
|
||||||
self:pageUpdate(-10)
|
self.ui:handleEvent(Event:new("GotoRelativePage", -10))
|
||||||
elseif action == "page_jmp_back_1" then
|
elseif action == "page_jmp_back_1" then
|
||||||
self.ui:handleEvent(Event:new("GotoViewRel", -1))
|
self.ui:handleEvent(Event:new("GotoViewRel", -1))
|
||||||
elseif action == "next_chapter" then
|
elseif action == "next_chapter" then
|
||||||
self.ui:handleEvent(Event:new("GotoNextChapter"))
|
self.ui:handleEvent(Event:new("GotoNextChapter"))
|
||||||
elseif action == "first_page" then
|
elseif action == "first_page" then
|
||||||
self.ui:handleEvent(Event:new("GotoPage", 1))
|
self.ui:handleEvent(Event:new("GoToBeginning"))
|
||||||
elseif action == "last_page" then
|
elseif action == "last_page" then
|
||||||
if self.view.document then
|
self.ui:handleEvent(Event:new("GoToEnd"))
|
||||||
self.ui:handleEvent(Event:new("GotoPage", self.view.document:getPageCount()))
|
|
||||||
end
|
|
||||||
elseif action == "prev_chapter" then
|
elseif action == "prev_chapter" then
|
||||||
self.ui:handleEvent(Event:new("GotoPrevChapter"))
|
self.ui:handleEvent(Event:new("GotoPrevChapter"))
|
||||||
elseif action == "next_bookmark" then
|
elseif action == "next_bookmark" then
|
||||||
@@ -1418,35 +1403,23 @@ function ReaderGesture:gestureAction(action, ges)
|
|||||||
elseif action == "latest_bookmark" then
|
elseif action == "latest_bookmark" then
|
||||||
self.ui:handleEvent(Event:new("GoToLatestBookmark"))
|
self.ui:handleEvent(Event:new("GoToLatestBookmark"))
|
||||||
elseif action == "follow_nearest_link" then
|
elseif action == "follow_nearest_link" then
|
||||||
self.ui:handleEvent(Event:new("GoToPageLink", ges, false, G_reader_settings:isTrue("footnote_link_in_popup")))
|
self.ui:handleEvent(Event:new("GoToPageLink", ges))
|
||||||
elseif action == "follow_nearest_internal_link" then
|
elseif action == "follow_nearest_internal_link" then
|
||||||
self.ui:handleEvent(Event:new("GoToPageLink", ges, true, G_reader_settings:isTrue("footnote_link_in_popup")))
|
self.ui:handleEvent(Event:new("GoToInternalPageLink", ges))
|
||||||
elseif action == "clear_location_history" then
|
elseif action == "clear_location_history" then
|
||||||
self.ui:handleEvent(Event:new("ClearLocationStack", true)) -- show_notification
|
self.ui:handleEvent(Event:new("ClearLocationStack", true)) -- show_notification
|
||||||
elseif action == "filemanager" then
|
elseif action == "filemanager" then
|
||||||
self.ui:onClose()
|
self.ui:handleEvent(Event:new("Home"))
|
||||||
self.ui:showFileManager()
|
|
||||||
elseif action == "file_search" then
|
elseif action == "file_search" then
|
||||||
if self.ges_mode == "gesture_fm" then
|
self.ui:handleEvent(Event:new("ShowFileSearch"))
|
||||||
self.ui:handleEvent(Event:new("ShowFileSearch", self.ui.file_chooser.path))
|
|
||||||
else
|
|
||||||
local last_dir = self.ui:getLastDirFile()
|
|
||||||
self.ui:handleEvent(Event:new("ShowFileSearch", last_dir))
|
|
||||||
end
|
|
||||||
elseif action == "folder_up" then
|
elseif action == "folder_up" then
|
||||||
self.ui.file_chooser:changeToPath(string.format("%s/..", self.ui.file_chooser.path))
|
self.ui:handleEvent(Event:new("FolderUp"))
|
||||||
elseif action == "show_plus_menu" then
|
elseif action == "show_plus_menu" then
|
||||||
self.ui:handleEvent(Event:new("ShowPlusMenu"))
|
self.ui:handleEvent(Event:new("ShowPlusMenu"))
|
||||||
elseif action == "folder_shortcuts" then
|
elseif action == "folder_shortcuts" then
|
||||||
self.ui:handleEvent(Event:new("ShowFolderShortcutsDialog"))
|
self.ui:handleEvent(Event:new("ShowFolderShortcutsDialog"))
|
||||||
elseif action == "open_previous_document" then
|
elseif action == "open_previous_document" then
|
||||||
-- FileManager
|
self.ui:handleEvent(Event:new("OpenLastDoc"))
|
||||||
if self.ui.menu.openLastDoc and G_reader_settings:readSetting("lastfile") ~= nil then
|
|
||||||
self.ui.menu:openLastDoc()
|
|
||||||
-- ReaderUI
|
|
||||||
elseif self.ui.switchDocument and self.ui.menu then
|
|
||||||
self.ui:switchDocument(self.ui.menu:getPreviousFile())
|
|
||||||
end
|
|
||||||
elseif action == "dictionary_lookup" then
|
elseif action == "dictionary_lookup" then
|
||||||
self.ui:handleEvent(Event:new("ShowDictionaryLookup"))
|
self.ui:handleEvent(Event:new("ShowDictionaryLookup"))
|
||||||
elseif action == "wikipedia_lookup" then
|
elseif action == "wikipedia_lookup" then
|
||||||
@@ -1454,187 +1427,55 @@ function ReaderGesture:gestureAction(action, ges)
|
|||||||
elseif action == "fulltext_search" then
|
elseif action == "fulltext_search" then
|
||||||
self.ui:handleEvent(Event:new("ShowFulltextSearchInput"))
|
self.ui:handleEvent(Event:new("ShowFulltextSearchInput"))
|
||||||
elseif action == "show_menu" then
|
elseif action == "show_menu" then
|
||||||
if self.ges_mode == "gesture_fm" then
|
|
||||||
self.ui:handleEvent(Event:new("ShowMenu"))
|
self.ui:handleEvent(Event:new("ShowMenu"))
|
||||||
else
|
|
||||||
self.ui:handleEvent(Event:new("ShowReaderMenu"))
|
|
||||||
end
|
|
||||||
elseif action == "show_config_menu" then
|
elseif action == "show_config_menu" then
|
||||||
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
||||||
elseif action == "show_frontlight_dialog" then
|
elseif action == "show_frontlight_dialog" then
|
||||||
if self.ges_mode == "gesture_fm" then
|
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
ReaderFrontLight:onShowFlDialog()
|
|
||||||
else
|
|
||||||
self.ui:handleEvent(Event:new("ShowFlDialog"))
|
self.ui:handleEvent(Event:new("ShowFlDialog"))
|
||||||
end
|
|
||||||
elseif action == "increase_frontlight" then
|
elseif action == "increase_frontlight" then
|
||||||
-- when using frontlight system settings
|
self.ui:handleEvent(Event:new("IncreaseFlIntensity", ges))
|
||||||
if lightFrontlight() then
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = _("Frontlight controlled by system settings."),
|
|
||||||
timeout = 2.5,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if self.ges_mode == "gesture_fm" then
|
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
ReaderFrontLight:onChangeFlIntensity(ges, 1)
|
|
||||||
else
|
|
||||||
self.ui:handleEvent(Event:new("ChangeFlIntensity", ges, 1))
|
|
||||||
end
|
|
||||||
elseif action == "decrease_frontlight" then
|
elseif action == "decrease_frontlight" then
|
||||||
-- when using frontlight system settings
|
self.ui:handleEvent(Event:new("DecreaseFlIntensity", ges))
|
||||||
if lightFrontlight() then
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = _("Frontlight controlled by system settings."),
|
|
||||||
timeout = 2.5,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
if self.ges_mode == "gesture_fm" then
|
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
ReaderFrontLight:onChangeFlIntensity(ges, -1)
|
|
||||||
else
|
|
||||||
self.ui:handleEvent(Event:new("ChangeFlIntensity", ges, -1))
|
|
||||||
end
|
|
||||||
elseif action == "increase_frontlight_warmth" then
|
elseif action == "increase_frontlight_warmth" then
|
||||||
if self.ges_mode == "gesture_fm" then
|
self.ui:handleEvent(Event:new("IncreaseFlWarmth", ges))
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
ReaderFrontLight:onChangeFlWarmth(ges, 1)
|
|
||||||
else
|
|
||||||
self.ui:handleEvent(Event:new("ChangeFlWarmth", ges, 1))
|
|
||||||
end
|
|
||||||
elseif action == "decrease_frontlight_warmth" then
|
elseif action == "decrease_frontlight_warmth" then
|
||||||
if self.ges_mode == "gesture_fm" then
|
self.ui:handleEvent(Event:new("DecreaseFlWarmth", ges))
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
ReaderFrontLight:onChangeFlWarmth(ges, -1)
|
|
||||||
else
|
|
||||||
self.ui:handleEvent(Event:new("ChangeFlWarmth", ges, -1))
|
|
||||||
end
|
|
||||||
elseif action == "toggle_bookmark" then
|
elseif action == "toggle_bookmark" then
|
||||||
self.ui:handleEvent(Event:new("ToggleBookmark"))
|
self.ui:handleEvent(Event:new("ToggleBookmark"))
|
||||||
elseif action == "toggle_inverse_reading_order" then
|
elseif action == "toggle_inverse_reading_order" then
|
||||||
self:onToggleReadingOrder()
|
self.ui:handleEvent(Event:new("ToggleReadingOrder"))
|
||||||
elseif action == "toggle_frontlight" then
|
elseif action == "toggle_frontlight" then
|
||||||
-- when using frontlight system settings
|
self.ui:handleEvent(Event:new("ToggleFrontlight"))
|
||||||
if lightFrontlight() then
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = _("Frontlight controlled by system settings."),
|
|
||||||
timeout = 2.5,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
Device:getPowerDevice():toggleFrontlight()
|
|
||||||
self:onShowFLOnOff()
|
|
||||||
elseif action == "toggle_hold_corners" then
|
elseif action == "toggle_hold_corners" then
|
||||||
self:onIgnoreHoldCorners()
|
self:onIgnoreHoldCorners()
|
||||||
elseif action == "toggle_gsensor" then
|
elseif action == "toggle_gsensor" then
|
||||||
G_reader_settings:flipNilOrFalse("input_ignore_gsensor")
|
self.ui:handleEvent(Event:new("ToggleGSensor"))
|
||||||
Device:toggleGSensor(not G_reader_settings:isTrue("input_ignore_gsensor"))
|
|
||||||
self:onGSensorToggle()
|
|
||||||
elseif action == "toggle_page_flipping" then
|
elseif action == "toggle_page_flipping" then
|
||||||
if not self.ui.document.info.has_pages then
|
|
||||||
-- ReaderRolling has no support (yet) for onTogglePageFlipping,
|
|
||||||
-- so don't make that top left tap area unusable (and allow
|
|
||||||
-- taping on links there)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
self.ui:handleEvent(Event:new("TogglePageFlipping"))
|
self.ui:handleEvent(Event:new("TogglePageFlipping"))
|
||||||
elseif action == "toggle_reflow" then
|
elseif action == "toggle_reflow" then
|
||||||
if not self.document.info.has_pages then return end
|
self.ui:handleEvent(Event:new("ToggleReflow"))
|
||||||
if self.document.configurable.text_wrap == 1 then
|
|
||||||
self.document.configurable.text_wrap = 0
|
|
||||||
else
|
|
||||||
self.document.configurable.text_wrap = 1
|
|
||||||
end
|
|
||||||
self.ui:handleEvent(Event:new("RedrawCurrentPage"))
|
|
||||||
self.ui:handleEvent(Event:new("RestoreZoomMode"))
|
|
||||||
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
|
||||||
elseif action == "toggle_rotation" then
|
elseif action == "toggle_rotation" then
|
||||||
local arg = bit.band((Screen:getRotationMode() + 1), 3)
|
self.ui:handleEvent(Event:new("ToggleRotation"))
|
||||||
self.ui:handleEvent(Event:new("SetRotationMode", arg))
|
|
||||||
elseif action == "toggle_wifi" then
|
elseif action == "toggle_wifi" then
|
||||||
local NetworkMgr = require("ui/network/manager")
|
self.ui:handleEvent(Event:new("ToggleWifi"))
|
||||||
|
|
||||||
if not NetworkMgr:isOnline() then
|
|
||||||
UIManager:show(InfoMessage:new{
|
|
||||||
text = _("Turning on Wi-Fi…"),
|
|
||||||
timeout = 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- NB Normal widgets should use NetworkMgr:promptWifiOn()
|
|
||||||
-- This is specifically the toggle wifi action, so consent is implied.
|
|
||||||
NetworkMgr:turnOnWifi()
|
|
||||||
else
|
|
||||||
NetworkMgr:turnOffWifi()
|
|
||||||
|
|
||||||
UIManager:show(InfoMessage:new{
|
|
||||||
text = _("Wi-Fi off."),
|
|
||||||
timeout = 1,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
elseif action == "wifi_off" then
|
elseif action == "wifi_off" then
|
||||||
local NetworkMgr = require("ui/network/manager")
|
self.ui:handleEvent(Event:new("InfoWifiOff"))
|
||||||
-- can't hurt
|
|
||||||
NetworkMgr:turnOffWifi()
|
|
||||||
|
|
||||||
UIManager:show(InfoMessage:new{
|
|
||||||
text = _("Wi-Fi off."),
|
|
||||||
timeout = 1,
|
|
||||||
})
|
|
||||||
elseif action == "wifi_on" then
|
elseif action == "wifi_on" then
|
||||||
local NetworkMgr = require("ui/network/manager")
|
self.ui:handleEvent(Event:new("InfoWifiOn"))
|
||||||
|
|
||||||
if not NetworkMgr:isOnline() then
|
|
||||||
UIManager:show(InfoMessage:new{
|
|
||||||
text = _("Enabling wifi…"),
|
|
||||||
timeout = 1,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- NB Normal widgets should use NetworkMgr:promptWifiOn()
|
|
||||||
-- This is specifically the toggle Wi-Fi action, so consent is implied.
|
|
||||||
NetworkMgr:turnOnWifi()
|
|
||||||
else
|
|
||||||
local info_text
|
|
||||||
local current_network = NetworkMgr:getCurrentNetwork()
|
|
||||||
-- this method is only available for some implementations
|
|
||||||
if current_network and current_network.ssid then
|
|
||||||
info_text = T(_("Already connected to network %1."), BD.wrap(current_network.ssid))
|
|
||||||
else
|
|
||||||
info_text = _("Already connected.")
|
|
||||||
end
|
|
||||||
UIManager:show(InfoMessage:new{
|
|
||||||
text = info_text,
|
|
||||||
timeout = 1,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
elseif action == "increase_font" then
|
elseif action == "increase_font" then
|
||||||
self.ui:handleEvent(Event:new("AdjustFontSize", ges, 1))
|
self.ui:handleEvent(Event:new("IncreaseFontSize", ges))
|
||||||
elseif action == "decrease_font" then
|
elseif action == "decrease_font" then
|
||||||
self.ui:handleEvent(Event:new("AdjustFontSize", ges, -1))
|
self.ui:handleEvent(Event:new("DecreaseFontSize", ges))
|
||||||
elseif action == "suspend" then
|
elseif action == "suspend" then
|
||||||
UIManager:suspend()
|
self.ui:handleEvent(Event:new("SuspendEvent"))
|
||||||
elseif action == "exit" then
|
elseif action == "exit" then
|
||||||
self.ui.menu:exitOrRestart()
|
self.ui:handleEvent(Event:new("Exit"))
|
||||||
elseif action == "restart" then
|
elseif action == "restart" then
|
||||||
self.ui.menu:exitOrRestart(function() UIManager:restartKOReader() end)
|
self.ui:handleEvent(Event:new("Restart"))
|
||||||
elseif action == "reboot" then
|
elseif action == "reboot" then
|
||||||
UIManager:show(ConfirmBox:new{
|
self.ui:handleEvent(Event:new("Reboot"))
|
||||||
text = _("Are you sure you want to reboot the device?"),
|
|
||||||
ok_text = _("Reboot"),
|
|
||||||
ok_callback = function()
|
|
||||||
UIManager:nextTick(UIManager.reboot_action)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
elseif action == "poweroff" then
|
elseif action == "poweroff" then
|
||||||
UIManager:show(ConfirmBox:new{
|
self.ui:handleEvent(Event:new("PowerOff"))
|
||||||
text = _("Are you sure you want to power off the device?"),
|
|
||||||
ok_text = _("Power off"),
|
|
||||||
ok_callback = function()
|
|
||||||
UIManager:nextTick(UIManager.poweroff_action)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
elseif action == "zoom_contentwidth" then
|
elseif action == "zoom_contentwidth" then
|
||||||
self.ui:handleEvent(Event:new("SetZoomMode", "contentwidth"))
|
self.ui:handleEvent(Event:new("SetZoomMode", "contentwidth"))
|
||||||
elseif action == "zoom_contentheight" then
|
elseif action == "zoom_contentheight" then
|
||||||
@@ -1679,15 +1520,6 @@ function ReaderGesture:multiswipeAction(multiswipe_directions, ges)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderGesture:pageUpdate(page)
|
|
||||||
local curr_page = self.ui:getCurrentPage()
|
|
||||||
if curr_page and page then
|
|
||||||
curr_page = curr_page + page
|
|
||||||
self.ui:handleEvent(Event:new("GotoPage", curr_page))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderGesture:onIgnoreHoldCorners(ignore_hold_corners)
|
function ReaderGesture:onIgnoreHoldCorners(ignore_hold_corners)
|
||||||
if ignore_hold_corners == nil then
|
if ignore_hold_corners == nil then
|
||||||
G_reader_settings:flipNilOrFalse("ignore_hold_corners")
|
G_reader_settings:flipNilOrFalse("ignore_hold_corners")
|
||||||
@@ -1698,48 +1530,4 @@ function ReaderGesture:onIgnoreHoldCorners(ignore_hold_corners)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderGesture:onShowFLOnOff()
|
|
||||||
local powerd = Device:getPowerDevice()
|
|
||||||
local new_text
|
|
||||||
if powerd.is_fl_on then
|
|
||||||
new_text = _("Frontlight on.")
|
|
||||||
else
|
|
||||||
new_text = _("Frontlight off.")
|
|
||||||
end
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = new_text,
|
|
||||||
timeout = 1.0,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderGesture:onGSensorToggle()
|
|
||||||
local new_text
|
|
||||||
if G_reader_settings:isTrue("input_ignore_gsensor") then
|
|
||||||
new_text = _("Accelerometer rotation events off.")
|
|
||||||
else
|
|
||||||
new_text = _("Accelerometer rotation events on.")
|
|
||||||
end
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = new_text,
|
|
||||||
timeout = 1.0,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function ReaderGesture:onToggleReadingOrder()
|
|
||||||
local document_module = self.ui.document.info.has_pages and self.ui.paging or self.ui.rolling
|
|
||||||
document_module.inverse_reading_order = not document_module.inverse_reading_order
|
|
||||||
document_module:setupTouchZones()
|
|
||||||
local is_rtl = BD.mirroredUILayout()
|
|
||||||
if document_module.inverse_reading_order then
|
|
||||||
is_rtl = not is_rtl
|
|
||||||
end
|
|
||||||
UIManager:show(Notification:new{
|
|
||||||
text = is_rtl and _("RTL page turning.") or _("LTR page turning."),
|
|
||||||
timeout = 2.5,
|
|
||||||
})
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
return ReaderGesture
|
return ReaderGesture
|
||||||
|
|||||||
@@ -426,7 +426,7 @@ function ReaderLink:onTap(_, ges)
|
|||||||
-- screen DPI if the user has set another one).
|
-- screen DPI if the user has set another one).
|
||||||
max_distance = Screen:scaleByDPI(30)
|
max_distance = Screen:scaleByDPI(30)
|
||||||
end
|
end
|
||||||
return self:onGoToPageLink(ges, isTapIgnoreExternalLinksEnabled(), allow_footnote_popup, max_distance)
|
return self:onGoToPageLink(ges, isTapIgnoreExternalLinksEnabled(), max_distance)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -724,7 +724,7 @@ function ReaderLink:onSwipe(arg, ges)
|
|||||||
elseif direction == "west" then
|
elseif direction == "west" then
|
||||||
local ret = false
|
local ret = false
|
||||||
if isSwipeToFollowNearestLinkEnabled() then
|
if isSwipeToFollowNearestLinkEnabled() then
|
||||||
ret = self:onGoToPageLink(ges, isSwipeIgnoreExternalLinksEnabled(), isFootnoteLinkInPopupEnabled())
|
ret = self:onGoToPageLink(ges, isSwipeIgnoreExternalLinksEnabled())
|
||||||
end
|
end
|
||||||
-- If no link found, or no follow link option enabled,
|
-- If no link found, or no follow link option enabled,
|
||||||
-- jump to latest bookmark (if enabled)
|
-- jump to latest bookmark (if enabled)
|
||||||
@@ -736,7 +736,7 @@ function ReaderLink:onSwipe(arg, ges)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- Goes to link nearest to the gesture (or first link in page)
|
--- Goes to link nearest to the gesture (or first link in page)
|
||||||
function ReaderLink:onGoToPageLink(ges, internal_links_only, allow_footnote_popup, max_distance)
|
function ReaderLink:onGoToPageLink(ges, internal_links_only, max_distance)
|
||||||
local selected_link = nil
|
local selected_link = nil
|
||||||
local selected_distance2 = nil
|
local selected_distance2 = nil
|
||||||
-- We use squares of distances all along the calculations, no need
|
-- We use squares of distances all along the calculations, no need
|
||||||
@@ -928,11 +928,15 @@ function ReaderLink:onGoToPageLink(ges, internal_links_only, allow_footnote_popu
|
|||||||
if max_distance and selected_distance2 and selected_distance2 > math.pow(max_distance, 2) then
|
if max_distance and selected_distance2 and selected_distance2 > math.pow(max_distance, 2) then
|
||||||
logger.dbg("nearest link is further than max distance, ignoring it")
|
logger.dbg("nearest link is further than max distance, ignoring it")
|
||||||
else
|
else
|
||||||
return self:onGotoLink(selected_link, false, allow_footnote_popup)
|
return self:onGotoLink(selected_link, false, isFootnoteLinkInPopupEnabled())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderLink:onGoToInternalPageLink(ges)
|
||||||
|
self:onGoToPageLink(ges, true)
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderLink:onGoToLatestBookmark(ges)
|
function ReaderLink:onGoToLatestBookmark(ges)
|
||||||
local latest_bookmark = self.ui.bookmark:getLatestBookmark()
|
local latest_bookmark = self.ui.bookmark:getLatestBookmark()
|
||||||
if latest_bookmark then
|
if latest_bookmark then
|
||||||
|
|||||||
@@ -65,9 +65,9 @@ function ReaderMenu:init()
|
|||||||
else
|
else
|
||||||
-- map menu key to only top menu because bottom menu is only
|
-- map menu key to only top menu because bottom menu is only
|
||||||
-- designed for touch devices
|
-- designed for touch devices
|
||||||
self.key_events.ShowReaderMenu = { { "Menu" }, doc = "show menu", }
|
self.key_events.ShowMenu = { { "Menu" }, doc = "show menu", }
|
||||||
if Device:hasFewKeys() then
|
if Device:hasFewKeys() then
|
||||||
self.key_events.ShowReaderMenu = { { { "Menu", "Right" } }, doc = "show menu", }
|
self.key_events.ShowMenu = { { { "Menu", "Right" } }, doc = "show menu", }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -231,7 +231,7 @@ function ReaderMenu:setUpdateItemTable()
|
|||||||
return self:getPreviousFile() ~= nil
|
return self:getPreviousFile() ~= nil
|
||||||
end,
|
end,
|
||||||
callback = function()
|
callback = function()
|
||||||
self.ui:switchDocument(self:getPreviousFile())
|
self.ui:onOpenLastDoc()
|
||||||
end,
|
end,
|
||||||
hold_callback = function()
|
hold_callback = function()
|
||||||
local previous_file = self:getPreviousFile()
|
local previous_file = self:getPreviousFile()
|
||||||
@@ -293,7 +293,7 @@ function ReaderMenu:exitOrRestart(callback)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderMenu:onShowReaderMenu(tab_index)
|
function ReaderMenu:onShowMenu(tab_index)
|
||||||
if self.tab_item_table == nil then
|
if self.tab_item_table == nil then
|
||||||
self:setUpdateItemTable()
|
self:setUpdateItemTable()
|
||||||
end
|
end
|
||||||
@@ -386,7 +386,7 @@ function ReaderMenu:onSwipeShowMenu(ges)
|
|||||||
if G_reader_settings:nilOrTrue("show_bottom_menu") then
|
if G_reader_settings:nilOrTrue("show_bottom_menu") then
|
||||||
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
||||||
end
|
end
|
||||||
self.ui:handleEvent(Event:new("ShowReaderMenu", self:_getTabIndexFromLocation(ges)))
|
self.ui:handleEvent(Event:new("ShowMenu", self:_getTabIndexFromLocation(ges)))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -396,7 +396,7 @@ function ReaderMenu:onTapShowMenu(ges)
|
|||||||
if G_reader_settings:nilOrTrue("show_bottom_menu") then
|
if G_reader_settings:nilOrTrue("show_bottom_menu") then
|
||||||
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
self.ui:handleEvent(Event:new("ShowConfigMenu"))
|
||||||
end
|
end
|
||||||
self.ui:handleEvent(Event:new("ShowReaderMenu", self:_getTabIndexFromLocation(ges)))
|
self.ui:handleEvent(Event:new("ShowMenu", self:_getTabIndexFromLocation(ges)))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -326,7 +326,7 @@ function ReaderPageMap:addToMainMenu(menu_items)
|
|||||||
self.ui.doc_settings:saveSetting("pagemap_use_page_labels", self.use_page_labels)
|
self.ui.doc_settings:saveSetting("pagemap_use_page_labels", self.use_page_labels)
|
||||||
-- Reset a few stuff that may use page labels
|
-- Reset a few stuff that may use page labels
|
||||||
self.ui.toc:resetToc()
|
self.ui.toc:resetToc()
|
||||||
self.ui.view.footer:updateFooter()
|
self.ui.view.footer:onUpdateFooter()
|
||||||
UIManager:setDirty(self.view.dialog, "partial")
|
UIManager:setDirty(self.view.dialog, "partial")
|
||||||
end,
|
end,
|
||||||
hold_callback = function(touchmenu_instance)
|
hold_callback = function(touchmenu_instance)
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ local Geom = require("ui/geometry")
|
|||||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
local Math = require("optmath")
|
local Math = require("optmath")
|
||||||
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
||||||
|
local Notification = require("ui/widget/notification")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
|
local bit = require("bit")
|
||||||
local logger = require("logger")
|
local logger = require("logger")
|
||||||
local _ = require("gettext")
|
local _ = require("gettext")
|
||||||
local Screen = Device.screen
|
local Screen = Device.screen
|
||||||
@@ -422,7 +424,7 @@ function ReaderPaging:onSwipe(_, ges)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- update footer (time & battery)
|
-- update footer (time & battery)
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
-- trigger full refresh
|
-- trigger full refresh
|
||||||
UIManager:setDirty(nil, "full")
|
UIManager:setDirty(nil, "full")
|
||||||
end
|
end
|
||||||
@@ -977,7 +979,7 @@ function ReaderPaging:_gotoPage(number, orig_mode)
|
|||||||
if number == self.current_page or not number then
|
if number == self.current_page or not number then
|
||||||
-- update footer even if we stay on the same page (like when
|
-- update footer even if we stay on the same page (like when
|
||||||
-- viewing the bottom part of a page from a top part view)
|
-- viewing the bottom part of a page from a top part view)
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
if number > self.number_of_pages then
|
if number > self.number_of_pages then
|
||||||
@@ -1031,4 +1033,26 @@ function ReaderPaging:onGotoPrevChapter()
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderPaging:onToggleReflow()
|
||||||
|
self.view.document.configurable.text_wrap = bit.bxor(self.view.document.configurable.text_wrap, 1)
|
||||||
|
self.ui:handleEvent(Event:new("RedrawCurrentPage"))
|
||||||
|
self.ui:handleEvent(Event:new("RestoreZoomMode"))
|
||||||
|
self.ui:handleEvent(Event:new("InitScrollPageStates"))
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Duplicated in ReaderRolling
|
||||||
|
function ReaderPaging:onToggleReadingOrder()
|
||||||
|
self.inverse_reading_order = not self.inverse_reading_order
|
||||||
|
self:setupTouchZones()
|
||||||
|
local is_rtl = BD.mirroredUILayout()
|
||||||
|
if self.inverse_reading_order then
|
||||||
|
is_rtl = not is_rtl
|
||||||
|
end
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = is_rtl and _("RTL page turning.") or _("LTR page turning."),
|
||||||
|
timeout = 2.5,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return ReaderPaging
|
return ReaderPaging
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ local Device = require("device")
|
|||||||
local Event = require("ui/event")
|
local Event = require("ui/event")
|
||||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
||||||
|
local Notification = require("ui/widget/notification")
|
||||||
local ProgressWidget = require("ui/widget/progresswidget")
|
local ProgressWidget = require("ui/widget/progresswidget")
|
||||||
local ReaderPanning = require("apps/reader/modules/readerpanning")
|
local ReaderPanning = require("apps/reader/modules/readerpanning")
|
||||||
local Size = require("ui/size")
|
local Size = require("ui/size")
|
||||||
@@ -484,7 +485,7 @@ function ReaderRolling:onSwipe(_, ges)
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- update footer (time & battery)
|
-- update footer (time & battery)
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
-- trigger full refresh
|
-- trigger full refresh
|
||||||
UIManager:setDirty(nil, "full")
|
UIManager:setDirty(nil, "full")
|
||||||
end
|
end
|
||||||
@@ -786,7 +787,7 @@ function ReaderRolling:updatePos()
|
|||||||
self.old_doc_height = new_height
|
self.old_doc_height = new_height
|
||||||
self.old_page = new_page
|
self.old_page = new_page
|
||||||
self.ui:handleEvent(Event:new("UpdateToc"))
|
self.ui:handleEvent(Event:new("UpdateToc"))
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
end
|
end
|
||||||
self:updateTopStatusBarMarkers()
|
self:updateTopStatusBarMarkers()
|
||||||
UIManager:setDirty(self.view.dialog, "partial")
|
UIManager:setDirty(self.view.dialog, "partial")
|
||||||
@@ -1298,4 +1299,19 @@ Note that %1 (out of %2) xpaths from your bookmarks and highlights have been nor
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Duplicated in ReaderPaging
|
||||||
|
function ReaderRolling:onToggleReadingOrder()
|
||||||
|
self.inverse_reading_order = not self.inverse_reading_order
|
||||||
|
self:setupTouchZones()
|
||||||
|
local is_rtl = BD.mirroredUILayout()
|
||||||
|
if self.inverse_reading_order then
|
||||||
|
is_rtl = not is_rtl
|
||||||
|
end
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = is_rtl and _("RTL page turning.") or _("LTR page turning."),
|
||||||
|
timeout = 2.5,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return ReaderRolling
|
return ReaderRolling
|
||||||
|
|||||||
@@ -659,7 +659,7 @@ function ReaderToc:addToMainMenu(menu_items)
|
|||||||
self.ui.doc_settings:saveSetting("alternative_toc", true)
|
self.ui.doc_settings:saveSetting("alternative_toc", true)
|
||||||
self:onShowToc()
|
self:onShowToc()
|
||||||
self.view.footer:setTocMarkers(true)
|
self.view.footer:setTocMarkers(true)
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ local BD = require("ui/bidi")
|
|||||||
local Cache = require("cache")
|
local Cache = require("cache")
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
|
local DeviceListener = require("device/devicelistener")
|
||||||
local DocSettings = require("docsettings")
|
local DocSettings = require("docsettings")
|
||||||
local DocumentRegistry = require("document/documentregistry")
|
local DocumentRegistry = require("document/documentregistry")
|
||||||
local Event = require("ui/event")
|
local Event = require("ui/event")
|
||||||
@@ -29,7 +30,6 @@ local ReaderCropping = require("apps/reader/modules/readercropping")
|
|||||||
local ReaderDeviceStatus = require("apps/reader/modules/readerdevicestatus")
|
local ReaderDeviceStatus = require("apps/reader/modules/readerdevicestatus")
|
||||||
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
|
local ReaderDictionary = require("apps/reader/modules/readerdictionary")
|
||||||
local ReaderFont = require("apps/reader/modules/readerfont")
|
local ReaderFont = require("apps/reader/modules/readerfont")
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
local ReaderGesture = require("apps/reader/modules/readergesture")
|
local ReaderGesture = require("apps/reader/modules/readergesture")
|
||||||
local ReaderGoto = require("apps/reader/modules/readergoto")
|
local ReaderGoto = require("apps/reader/modules/readergoto")
|
||||||
local ReaderHinting = require("apps/reader/modules/readerhinting")
|
local ReaderHinting = require("apps/reader/modules/readerhinting")
|
||||||
@@ -187,14 +187,6 @@ function ReaderUI:init()
|
|||||||
view = self.view,
|
view = self.view,
|
||||||
ui = self
|
ui = self
|
||||||
}, true)
|
}, true)
|
||||||
-- frontlight controller
|
|
||||||
if Device:hasFrontlight() then
|
|
||||||
self:registerModule("frontlight", ReaderFrontLight:new{
|
|
||||||
dialog = self.dialog,
|
|
||||||
view = self.view,
|
|
||||||
ui = self
|
|
||||||
})
|
|
||||||
end
|
|
||||||
-- device status controller
|
-- device status controller
|
||||||
self:registerModule("battery", ReaderDeviceStatus:new{
|
self:registerModule("battery", ReaderDeviceStatus:new{
|
||||||
ui = self,
|
ui = self,
|
||||||
@@ -371,6 +363,12 @@ function ReaderUI:init()
|
|||||||
document = self.document,
|
document = self.document,
|
||||||
ui = self,
|
ui = self,
|
||||||
})
|
})
|
||||||
|
-- event listener to change device settings
|
||||||
|
self:registerModule("devicelistener", DeviceListener:new {
|
||||||
|
document = self.document,
|
||||||
|
view = self.view,
|
||||||
|
ui = self,
|
||||||
|
})
|
||||||
-- koreader plugins
|
-- koreader plugins
|
||||||
for _, plugin_module in ipairs(PluginLoader:loadPlugins()) do
|
for _, plugin_module in ipairs(PluginLoader:loadPlugins()) do
|
||||||
local ok, plugin_or_err = PluginLoader:createPluginInstance(
|
local ok, plugin_or_err = PluginLoader:createPluginInstance(
|
||||||
@@ -396,6 +394,15 @@ function ReaderUI:init()
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Device:hasWifiToggle() then
|
||||||
|
local NetworkListener = require("ui/network/networklistener")
|
||||||
|
self:registerModule("networklistener", NetworkListener:new {
|
||||||
|
document = self.document,
|
||||||
|
view = self.view,
|
||||||
|
ui = self,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
-- Allow others to change settings based on external factors
|
-- Allow others to change settings based on external factors
|
||||||
-- Must be called after plugins are loaded & before setting are read.
|
-- Must be called after plugins are loaded & before setting are read.
|
||||||
self:handleEvent(Event:new("DocSettingsLoad", self.doc_settings, self.document))
|
self:handleEvent(Event:new("DocSettingsLoad", self.doc_settings, self.document))
|
||||||
@@ -761,6 +768,10 @@ function ReaderUI:switchDocument(new_file)
|
|||||||
self:showReader(new_file)
|
self:showReader(new_file)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderUI:onOpenLastDoc()
|
||||||
|
self:switchDocument(self.menu:getPreviousFile())
|
||||||
|
end
|
||||||
|
|
||||||
function ReaderUI:getCurrentPage()
|
function ReaderUI:getCurrentPage()
|
||||||
if self.document.info.has_pages then
|
if self.document.info.has_pages then
|
||||||
return self.paging.current_page
|
return self.paging.current_page
|
||||||
|
|||||||
302
frontend/device/devicelistener.lua
Normal file
302
frontend/device/devicelistener.lua
Normal file
@@ -0,0 +1,302 @@
|
|||||||
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
|
local Device = require("device")
|
||||||
|
local Event = require("ui/event")
|
||||||
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
|
local Notification = require("ui/widget/notification")
|
||||||
|
local Screen = Device.screen
|
||||||
|
local UIManager = require("ui/uimanager")
|
||||||
|
local bit = require("bit")
|
||||||
|
local _ = require("gettext")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
|
||||||
|
local DeviceListener = InputContainer:new{
|
||||||
|
steps_fl = { 0.1, 0.1, 0.2, 0.4, 0.7, 1.1, 1.6, 2.2, 2.9, 3.7, 4.6, 5.6, 6.7, 7.9, 9.2, 10.6, },
|
||||||
|
}
|
||||||
|
|
||||||
|
function DeviceListener:onToggleNightMode()
|
||||||
|
local night_mode = G_reader_settings:isTrue("night_mode")
|
||||||
|
Screen:toggleNightMode()
|
||||||
|
UIManager:setDirty("all", "full")
|
||||||
|
G_reader_settings:saveSetting("night_mode", not night_mode)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function lightFrontlight()
|
||||||
|
return Device:hasLightLevelFallback() and G_reader_settings:nilOrTrue("light_fallback")
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onShowIntensity()
|
||||||
|
if not Device:hasFrontlight() then return true end
|
||||||
|
local powerd = Device:getPowerDevice()
|
||||||
|
local new_text
|
||||||
|
if powerd:isFrontlightOff() then
|
||||||
|
new_text = _("Frontlight disabled.")
|
||||||
|
else
|
||||||
|
new_text = T(_("Frontlight intensity set to %1."), powerd:frontlightIntensity())
|
||||||
|
end
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = new_text,
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onShowWarmth(value)
|
||||||
|
local powerd = Device:getPowerDevice()
|
||||||
|
if powerd.fl_warmth ~= nil then
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = T(_("Warmth set to %1."), powerd.fl_warmth),
|
||||||
|
timeout = 1.0,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- frontlight controller
|
||||||
|
if Device:hasFrontlight() then
|
||||||
|
|
||||||
|
-- direction +1 - increase frontlight
|
||||||
|
-- direction -1 - decrease frontlight
|
||||||
|
function DeviceListener:onChangeFlIntensity(ges, direction)
|
||||||
|
local powerd = Device:getPowerDevice()
|
||||||
|
local gestureScale
|
||||||
|
local scale_multiplier
|
||||||
|
if ges.ges == "two_finger_swipe" then
|
||||||
|
-- for backward compatibility
|
||||||
|
scale_multiplier = FRONTLIGHT_SENSITIVITY_DECREASE * 0.8
|
||||||
|
elseif ges.ges == "swipe" then
|
||||||
|
scale_multiplier = 0.8
|
||||||
|
else
|
||||||
|
scale_multiplier = 1
|
||||||
|
end
|
||||||
|
if ges.direction == "south" or ges.direction == "north" then
|
||||||
|
gestureScale = Screen:getHeight() * scale_multiplier
|
||||||
|
elseif ges.direction == "west" or ges.direction == "east" then
|
||||||
|
gestureScale = Screen:getWidth() * scale_multiplier
|
||||||
|
else
|
||||||
|
local width = Screen:getWidth()
|
||||||
|
local height = Screen:getHeight()
|
||||||
|
-- diagonal
|
||||||
|
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
||||||
|
end
|
||||||
|
if powerd.fl_intensity == nil then return false end
|
||||||
|
|
||||||
|
local steps_tbl = {}
|
||||||
|
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
|
||||||
|
for i = 1, #self.steps_fl, 1
|
||||||
|
do
|
||||||
|
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
|
||||||
|
end
|
||||||
|
|
||||||
|
if ges.distance == nil then
|
||||||
|
ges.distance = 1
|
||||||
|
end
|
||||||
|
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
|
||||||
|
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
|
||||||
|
if direction ~= -1 and direction ~= 1 then
|
||||||
|
-- set default value (increase frontlight)
|
||||||
|
direction = 1
|
||||||
|
end
|
||||||
|
local new_intensity = powerd.fl_intensity + direction * delta_int
|
||||||
|
|
||||||
|
if new_intensity == nil then return true end
|
||||||
|
-- when new_intensity <=0, toggle light off
|
||||||
|
if new_intensity <= 0 then
|
||||||
|
powerd:turnOffFrontlight()
|
||||||
|
else
|
||||||
|
powerd:setIntensity(new_intensity)
|
||||||
|
end
|
||||||
|
self:onShowIntensity()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onIncreaseFlIntensity(ges)
|
||||||
|
self:onChangeFlIntensity(ges, 1)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onDecreaseFlIntensity(ges)
|
||||||
|
self:onChangeFlIntensity(ges, -1)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- direction +1 - increase frontlight warmth
|
||||||
|
-- direction -1 - decrease frontlight warmth
|
||||||
|
function DeviceListener:onChangeFlWarmth(ges, direction)
|
||||||
|
-- when using frontlight system settings
|
||||||
|
if lightFrontlight() then
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = _("Frontlight controlled by system settings."),
|
||||||
|
timeout = 2.5,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local powerd = Device:getPowerDevice()
|
||||||
|
if powerd.fl_warmth == nil then return false end
|
||||||
|
|
||||||
|
if powerd.auto_warmth then
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = _("Warmth is handled automatically."),
|
||||||
|
timeout = 1.0,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
local gestureScale
|
||||||
|
local scale_multiplier
|
||||||
|
if ges.ges == "two_finger_swipe" then
|
||||||
|
-- for backward compatibility
|
||||||
|
scale_multiplier = FRONTLIGHT_SENSITIVITY_DECREASE * 0.8
|
||||||
|
elseif ges.ges == "swipe" then
|
||||||
|
scale_multiplier = 0.8
|
||||||
|
else
|
||||||
|
scale_multiplier = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if ges.direction == "south" or ges.direction == "north" then
|
||||||
|
gestureScale = Screen:getHeight() * scale_multiplier
|
||||||
|
elseif ges.direction == "west" or ges.direction == "east" then
|
||||||
|
gestureScale = Screen:getWidth() * scale_multiplier
|
||||||
|
else
|
||||||
|
local width = Screen:getWidth()
|
||||||
|
local height = Screen:getHeight()
|
||||||
|
-- diagonal
|
||||||
|
gestureScale = math.sqrt(width * width + height * height) * scale_multiplier
|
||||||
|
end
|
||||||
|
|
||||||
|
local steps_tbl = {}
|
||||||
|
local scale = (powerd.fl_max - powerd.fl_min) / 2 / 10.6
|
||||||
|
for i = 1, #self.steps_fl, 1
|
||||||
|
do
|
||||||
|
steps_tbl[i] = math.ceil(self.steps_fl[i] * scale)
|
||||||
|
end
|
||||||
|
|
||||||
|
if ges.distance == nil then
|
||||||
|
ges.distance = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
local step = math.ceil(#steps_tbl * ges.distance / gestureScale)
|
||||||
|
local delta_int = steps_tbl[step] or steps_tbl[#steps_tbl]
|
||||||
|
local warmth
|
||||||
|
if direction ~= -1 and direction ~= 1 then
|
||||||
|
-- set default value (increase frontlight)
|
||||||
|
direction = 1
|
||||||
|
end
|
||||||
|
warmth = powerd.fl_warmth + direction * delta_int
|
||||||
|
if warmth > 100 then
|
||||||
|
warmth = 100
|
||||||
|
elseif warmth < 0 then
|
||||||
|
warmth = 0
|
||||||
|
end
|
||||||
|
powerd:setWarmth(warmth)
|
||||||
|
self:onShowWarmth()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onIncreaseFlWarmth(ges)
|
||||||
|
self:onChangeFlWarmth(ges, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onDecreaseFlWarmth(ges)
|
||||||
|
self:onChangeFlWarmth(ges, -1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onToggleFrontlight()
|
||||||
|
-- when using frontlight system settings
|
||||||
|
if lightFrontlight() then
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = _("Frontlight controlled by system settings."),
|
||||||
|
timeout = 2.5,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local powerd = Device:getPowerDevice()
|
||||||
|
powerd:toggleFrontlight()
|
||||||
|
local new_text
|
||||||
|
if powerd.is_fl_on then
|
||||||
|
new_text = _("Frontlight enabled.")
|
||||||
|
else
|
||||||
|
new_text = _("Frontlight disabled.")
|
||||||
|
end
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = new_text,
|
||||||
|
timeout = 1.0,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onShowFlDialog()
|
||||||
|
local FrontLightWidget = require("ui/widget/frontlightwidget")
|
||||||
|
UIManager:show(FrontLightWidget:new{
|
||||||
|
use_system_fl = Device:hasLightLevelFallback()
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
if Device:canToggleGSensor() then
|
||||||
|
function DeviceListener:onToggleGSensor()
|
||||||
|
G_reader_settings:flipNilOrFalse("input_ignore_gsensor")
|
||||||
|
Device:toggleGSensor(not G_reader_settings:isTrue("input_ignore_gsensor"))
|
||||||
|
local new_text
|
||||||
|
if G_reader_settings:isTrue("input_ignore_gsensor") then
|
||||||
|
new_text = _("Accelerometer rotation events off.")
|
||||||
|
else
|
||||||
|
new_text = _("Accelerometer rotation events on.")
|
||||||
|
end
|
||||||
|
UIManager:show(Notification:new{
|
||||||
|
text = new_text,
|
||||||
|
timeout = 1.0,
|
||||||
|
})
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onToggleRotation()
|
||||||
|
local arg = bit.band((Screen:getRotationMode() + 1), 3)
|
||||||
|
self.ui:handleEvent(Event:new("SetRotationMode", arg))
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if Device:canReboot() then
|
||||||
|
function DeviceListener:onReboot()
|
||||||
|
UIManager:show(ConfirmBox:new{
|
||||||
|
text = _("Are you sure you want to reboot the device?"),
|
||||||
|
ok_text = _("Reboot"),
|
||||||
|
ok_callback = function()
|
||||||
|
UIManager:nextTick(UIManager.reboot_action)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if Device:canPowerOff() then
|
||||||
|
function DeviceListener:onPowerOff()
|
||||||
|
UIManager:show(ConfirmBox:new{
|
||||||
|
text = _("Are you sure you want to power off the device?"),
|
||||||
|
ok_text = _("Power off"),
|
||||||
|
ok_callback = function()
|
||||||
|
UIManager:nextTick(UIManager.poweroff_action)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onSuspendEvent()
|
||||||
|
UIManager:suspend()
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onExit(callback)
|
||||||
|
self.ui.menu:exitOrRestart(callback)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onRestart()
|
||||||
|
self.ui.menu:exitOrRestart(function() UIManager:restartKOReader() end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DeviceListener:onFullRefresh()
|
||||||
|
self.ui:handleEvent(Event:new("UpdateFooter"))
|
||||||
|
UIManager:setDirty("all", "full")
|
||||||
|
end
|
||||||
|
|
||||||
|
return DeviceListener
|
||||||
@@ -370,24 +370,11 @@ function Input:handleKeyBoardEv(ev)
|
|||||||
local Device = require("frontend/device")
|
local Device = require("frontend/device")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
|
|
||||||
local savequit_caller = nil
|
|
||||||
local save_quit = function()
|
local save_quit = function()
|
||||||
Device:saveSettings()
|
Device:saveSettings()
|
||||||
UIManager:quit()
|
UIManager:quit()
|
||||||
end
|
end
|
||||||
|
UIManager:broadcastEvent(Event:new("Exit", save_quit))
|
||||||
local FileManager = require("apps/filemanager/filemanager")
|
|
||||||
if FileManager.instance then
|
|
||||||
savequit_caller = FileManager.instance.menu
|
|
||||||
end
|
|
||||||
|
|
||||||
local ReaderUI = require("apps/reader/readerui")
|
|
||||||
local readerui_instance = ReaderUI:_getRunningInstance()
|
|
||||||
if readerui_instance then
|
|
||||||
savequit_caller = readerui_instance.menu
|
|
||||||
end
|
|
||||||
|
|
||||||
savequit_caller:exitOrRestart(save_quit)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- handle modifier keys
|
-- handle modifier keys
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local BD = require("ui/bidi")
|
local BD = require("ui/bidi")
|
||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
|
local Event = require("ui/event")
|
||||||
local InfoMessage = require("ui/widget/infomessage")
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
local UIManager = require("ui/uimanager")
|
local UIManager = require("ui/uimanager")
|
||||||
local _ = require("gettext")
|
local _ = require("gettext")
|
||||||
@@ -75,13 +75,7 @@ if Device:canReboot() then
|
|||||||
text = _("Reboot the device"),
|
text = _("Reboot the device"),
|
||||||
keep_menu_open = true,
|
keep_menu_open = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
UIManager:show(ConfirmBox:new{
|
UIManager:broadcastEvent(Event:new("Reboot"))
|
||||||
text = _("Are you sure you want to reboot the device?"),
|
|
||||||
ok_text = _("Reboot"),
|
|
||||||
ok_callback = function()
|
|
||||||
UIManager:nextTick(UIManager.reboot_action)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -90,13 +84,7 @@ if Device:canPowerOff() then
|
|||||||
text = _("Power off"),
|
text = _("Power off"),
|
||||||
keep_menu_open = true,
|
keep_menu_open = true,
|
||||||
callback = function()
|
callback = function()
|
||||||
UIManager:show(ConfirmBox:new{
|
UIManager:broadcastEvent(Event:new("PowerOff"))
|
||||||
text = _("Are you sure you want to power off the device?"),
|
|
||||||
ok_text = _("Power off"),
|
|
||||||
ok_callback = function()
|
|
||||||
UIManager:nextTick(UIManager.poweroff_action)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -27,11 +27,10 @@ if Device:isCervantes() then
|
|||||||
end
|
end
|
||||||
|
|
||||||
if Device:hasFrontlight() then
|
if Device:hasFrontlight() then
|
||||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
|
||||||
common_settings.frontlight = {
|
common_settings.frontlight = {
|
||||||
text = _("Frontlight"),
|
text = _("Frontlight"),
|
||||||
callback = function()
|
callback = function()
|
||||||
ReaderFrontLight:onShowFlDialog()
|
UIManager:broadcastEvent(Event:new("ShowFlDialog"))
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@@ -166,10 +165,7 @@ common_settings.night_mode = {
|
|||||||
text = _("Night mode"),
|
text = _("Night mode"),
|
||||||
checked_func = function() return G_reader_settings:isTrue("night_mode") end,
|
checked_func = function() return G_reader_settings:isTrue("night_mode") end,
|
||||||
callback = function()
|
callback = function()
|
||||||
local night_mode = G_reader_settings:isTrue("night_mode")
|
UIManager:broadcastEvent(Event:new("ToggleNightMode"))
|
||||||
Screen:toggleNightMode()
|
|
||||||
UIManager:setDirty(nil, "full")
|
|
||||||
G_reader_settings:saveSetting("night_mode", not night_mode)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
common_settings.network = {
|
common_settings.network = {
|
||||||
|
|||||||
@@ -19,8 +19,7 @@ return {
|
|||||||
return G_reader_settings:isTrue("input_ignore_gsensor")
|
return G_reader_settings:isTrue("input_ignore_gsensor")
|
||||||
end,
|
end,
|
||||||
callback = function()
|
callback = function()
|
||||||
G_reader_settings:flipNilOrFalse("input_ignore_gsensor")
|
UIManager:broadcastEvent(Event:new("ToggleGSensor"))
|
||||||
Device:toggleGSensor(not G_reader_settings:isTrue("input_ignore_gsensor"))
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
67
frontend/ui/network/networklistener.lua
Normal file
67
frontend/ui/network/networklistener.lua
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
local BD = require("ui/bidi")
|
||||||
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||||
|
local NetworkMgr = require("ui/network/manager")
|
||||||
|
local UIManager = require("ui/uimanager")
|
||||||
|
local _ = require("gettext")
|
||||||
|
local T = require("ffi/util").template
|
||||||
|
|
||||||
|
local NetworkListener = InputContainer:new{}
|
||||||
|
|
||||||
|
function NetworkListener:onToggleWifi()
|
||||||
|
if not NetworkMgr:isOnline() then
|
||||||
|
UIManager:show(InfoMessage:new{
|
||||||
|
text = _("Turning on Wi-Fi…"),
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- NB Normal widgets should use NetworkMgr:promptWifiOn()
|
||||||
|
-- This is specifically the toggle wifi action, so consent is implied.
|
||||||
|
NetworkMgr:turnOnWifi()
|
||||||
|
else
|
||||||
|
NetworkMgr:turnOffWifi()
|
||||||
|
|
||||||
|
UIManager:show(InfoMessage:new{
|
||||||
|
text = _("Wi-Fi off."),
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function NetworkListener:onInfoWifiOff()
|
||||||
|
-- can't hurt
|
||||||
|
NetworkMgr:turnOffWifi()
|
||||||
|
|
||||||
|
UIManager:show(InfoMessage:new{
|
||||||
|
text = _("Wi-Fi off."),
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function NetworkListener:onInfoWifiOn()
|
||||||
|
if not NetworkMgr:isOnline() then
|
||||||
|
UIManager:show(InfoMessage:new{
|
||||||
|
text = _("Enabling wifi…"),
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- NB Normal widgets should use NetworkMgr:promptWifiOn()
|
||||||
|
-- This is specifically the toggle Wi-Fi action, so consent is implied.
|
||||||
|
NetworkMgr:turnOnWifi()
|
||||||
|
else
|
||||||
|
local info_text
|
||||||
|
local current_network = NetworkMgr:getCurrentNetwork()
|
||||||
|
-- this method is only available for some implementations
|
||||||
|
if current_network and current_network.ssid then
|
||||||
|
info_text = T(_("Already connected to network %1."), BD.wrap(current_network.ssid))
|
||||||
|
else
|
||||||
|
info_text = _("Already connected.")
|
||||||
|
end
|
||||||
|
UIManager:show(InfoMessage:new{
|
||||||
|
text = info_text,
|
||||||
|
timeout = 1,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return NetworkListener
|
||||||
@@ -6,6 +6,7 @@ local BD = require("ui/bidi")
|
|||||||
local ConfirmBox = require("ui/widget/confirmbox")
|
local ConfirmBox = require("ui/widget/confirmbox")
|
||||||
local DataStorage = require("datastorage")
|
local DataStorage = require("datastorage")
|
||||||
local Device = require("device")
|
local Device = require("device")
|
||||||
|
local Event = require("ui/event")
|
||||||
local InfoMessage = require("ui/widget/infomessage")
|
local InfoMessage = require("ui/widget/infomessage")
|
||||||
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
|
||||||
local NetworkMgr = require("ui/network/manager")
|
local NetworkMgr = require("ui/network/manager")
|
||||||
@@ -53,24 +54,12 @@ local function showRestartMessage()
|
|||||||
text = _("KOReader will be updated on next restart.\nWould you like to restart now?"),
|
text = _("KOReader will be updated on next restart.\nWould you like to restart now?"),
|
||||||
ok_text = _("Restart"),
|
ok_text = _("Restart"),
|
||||||
ok_callback = function()
|
ok_callback = function()
|
||||||
local savequit_caller
|
|
||||||
local save_quit = function()
|
local save_quit = function()
|
||||||
Device:saveSettings()
|
Device:saveSettings()
|
||||||
UIManager:quit()
|
UIManager:quit()
|
||||||
UIManager._exit_code = 85
|
UIManager._exit_code = 85
|
||||||
end
|
end
|
||||||
|
UIManager:broadcastEvent(Event:new("Exit", save_quit))
|
||||||
local FileManager = require("apps/filemanager/filemanager")
|
|
||||||
if FileManager.instance then
|
|
||||||
savequit_caller = FileManager.instance.menu
|
|
||||||
end
|
|
||||||
|
|
||||||
local ReaderUI = require("apps/reader/readerui")
|
|
||||||
local readerui_instance = ReaderUI:_getRunningInstance()
|
|
||||||
if readerui_instance then
|
|
||||||
savequit_caller = readerui_instance.menu
|
|
||||||
end
|
|
||||||
savequit_caller:exitOrRestart(save_quit)
|
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -322,6 +322,10 @@ function FileChooser:changeToPath(path, focused_path)
|
|||||||
self:onPathChanged(path)
|
self:onPathChanged(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function FileChooser:onFolderUp()
|
||||||
|
self:changeToPath(string.format("%s/..", self.path))
|
||||||
|
end
|
||||||
|
|
||||||
function FileChooser:changePageToPath(path)
|
function FileChooser:changePageToPath(path)
|
||||||
if not path then return end
|
if not path then return end
|
||||||
for num, item in ipairs(self.item_table) do
|
for num, item in ipairs(self.item_table) do
|
||||||
|
|||||||
@@ -149,38 +149,6 @@ function ReaderStatistics:init()
|
|||||||
end
|
end
|
||||||
return readingprogress
|
return readingprogress
|
||||||
end
|
end
|
||||||
local ReaderGesture = require("apps/reader/modules/readergesture")
|
|
||||||
ReaderGesture.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
|
|
||||||
|
|
||||||
ReaderGesture.getBookStats = function()
|
|
||||||
if self:isDocless() or not self.is_enabled then return end
|
|
||||||
local stats = KeyValuePage:new{
|
|
||||||
title = _("Current statistics"),
|
|
||||||
kv_pairs = self:getCurrentStat(self.id_curr_book),
|
|
||||||
}
|
|
||||||
return stats
|
|
||||||
end
|
|
||||||
|
|
||||||
ReaderGesture.getCalendarView = function()
|
|
||||||
return self:getCalendarView()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderStatistics:initData()
|
function ReaderStatistics:initData()
|
||||||
@@ -692,7 +660,7 @@ function ReaderStatistics:getStatisticEnabledMenuItem()
|
|||||||
end
|
end
|
||||||
self:saveSettings()
|
self:saveSettings()
|
||||||
if not self:isDocless() then
|
if not self:isDocless() then
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
@@ -2007,7 +1975,7 @@ end
|
|||||||
function ReaderStatistics:onReaderReady()
|
function ReaderStatistics:onReaderReady()
|
||||||
-- we have correct page count now, do the actual initialization work
|
-- we have correct page count now, do the actual initialization work
|
||||||
self:initData()
|
self:initData()
|
||||||
self.view.footer:updateFooter()
|
self.view.footer:onUpdateFooter()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ReaderStatistics:getCalendarView()
|
function ReaderStatistics:getCalendarView()
|
||||||
@@ -2101,4 +2069,36 @@ function ReaderStatistics:getReadBookByDay(month)
|
|||||||
return per_day
|
return per_day
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function ReaderStatistics:onShowReaderProgress()
|
||||||
|
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
|
||||||
|
UIManager:show(readingprogress)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderStatistics:onShowBookStats()
|
||||||
|
if self:isDocless() or not self.is_enabled then return end
|
||||||
|
local stats = KeyValuePage:new{
|
||||||
|
title = _("Current statistics"),
|
||||||
|
kv_pairs = self:getCurrentStat(self.id_curr_book),
|
||||||
|
}
|
||||||
|
UIManager:show(stats)
|
||||||
|
end
|
||||||
|
|
||||||
|
function ReaderStatistics:onShowCalendarView()
|
||||||
|
UIManager:show(self:getCalendarView())
|
||||||
|
end
|
||||||
|
|
||||||
return ReaderStatistics
|
return ReaderStatistics
|
||||||
|
|||||||
@@ -166,7 +166,7 @@ describe("Readerfooter module", function()
|
|||||||
}
|
}
|
||||||
local footer = readerui.view.footer
|
local footer = readerui.view.footer
|
||||||
footer:onPageUpdate(1)
|
footer:onPageUpdate(1)
|
||||||
footer:updateFooter()
|
footer:onUpdateFooter()
|
||||||
local timeinfo = footer.textGeneratorMap.time(footer)
|
local timeinfo = footer.textGeneratorMap.time(footer)
|
||||||
local page_count = readerui.document:getPageCount()
|
local page_count = readerui.document:getPageCount()
|
||||||
-- stats has not been initialized here, so we get na TB and TC
|
-- stats has not been initialized here, so we get na TB and TC
|
||||||
@@ -184,7 +184,7 @@ describe("Readerfooter module", function()
|
|||||||
document = DocumentRegistry:openDocument(sample_pdf),
|
document = DocumentRegistry:openDocument(sample_pdf),
|
||||||
}
|
}
|
||||||
local footer = readerui.view.footer
|
local footer = readerui.view.footer
|
||||||
readerui.view.footer:updateFooter()
|
readerui.view.footer:onUpdateFooter()
|
||||||
local timeinfo = readerui.view.footer.textGeneratorMap.time(footer)
|
local timeinfo = readerui.view.footer.textGeneratorMap.time(footer)
|
||||||
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
|
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
|
||||||
readerui.view.footer.footer_text.text)
|
readerui.view.footer.footer_text.text)
|
||||||
@@ -203,7 +203,7 @@ describe("Readerfooter module", function()
|
|||||||
local footer = readerui.view.footer
|
local footer = readerui.view.footer
|
||||||
footer:addToMainMenu(fake_menu)
|
footer:addToMainMenu(fake_menu)
|
||||||
footer:resetLayout()
|
footer:resetLayout()
|
||||||
footer:updateFooter()
|
footer:onUpdateFooter()
|
||||||
local timeinfo = footer.textGeneratorMap.time(footer)
|
local timeinfo = footer.textGeneratorMap.time(footer)
|
||||||
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
|
assert.are.same('1 / 2 | '..timeinfo..' | ⇒ 1 | 0% | ⤠ 50% | ⏳ na | ⤻ na',
|
||||||
footer.footer_text.text)
|
footer.footer_text.text)
|
||||||
@@ -295,7 +295,7 @@ describe("Readerfooter module", function()
|
|||||||
}
|
}
|
||||||
local footer = readerui.view.footer
|
local footer = readerui.view.footer
|
||||||
local horizontal_margin = Screen:scaleBySize(10)*2
|
local horizontal_margin = Screen:scaleBySize(10)*2
|
||||||
footer:updateFooter()
|
footer:onUpdateFooter()
|
||||||
assert.is.same(354, footer.text_width)
|
assert.is.same(354, footer.text_width)
|
||||||
assert.is.same(600, footer.progress_bar.width
|
assert.is.same(600, footer.progress_bar.width
|
||||||
+ footer.text_width
|
+ footer.text_width
|
||||||
|
|||||||
Reference in New Issue
Block a user