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:
yparitcher
2020-07-12 14:47:49 -04:00
committed by GitHub
parent f4dad2fae8
commit 70f89c4df1
26 changed files with 585 additions and 595 deletions

View File

@@ -1,6 +1,6 @@
local BD = require("ui/bidi")
local ConfirmBox = require("ui/widget/confirmbox")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager")
local _ = require("gettext")
@@ -75,13 +75,7 @@ if Device:canReboot() then
text = _("Reboot the device"),
keep_menu_open = true,
callback = function()
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,
})
UIManager:broadcastEvent(Event:new("Reboot"))
end
}
end
@@ -90,13 +84,7 @@ if Device:canPowerOff() then
text = _("Power off"),
keep_menu_open = true,
callback = function()
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,
})
UIManager:broadcastEvent(Event:new("PowerOff"))
end
}
end

View File

@@ -27,11 +27,10 @@ if Device:isCervantes() then
end
if Device:hasFrontlight() then
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
common_settings.frontlight = {
text = _("Frontlight"),
callback = function()
ReaderFrontLight:onShowFlDialog()
UIManager:broadcastEvent(Event:new("ShowFlDialog"))
end,
}
end
@@ -166,10 +165,7 @@ common_settings.night_mode = {
text = _("Night mode"),
checked_func = function() return G_reader_settings:isTrue("night_mode") end,
callback = function()
local night_mode = G_reader_settings:isTrue("night_mode")
Screen:toggleNightMode()
UIManager:setDirty(nil, "full")
G_reader_settings:saveSetting("night_mode", not night_mode)
UIManager:broadcastEvent(Event:new("ToggleNightMode"))
end
}
common_settings.network = {

View File

@@ -19,8 +19,7 @@ return {
return G_reader_settings:isTrue("input_ignore_gsensor")
end,
callback = function()
G_reader_settings:flipNilOrFalse("input_ignore_gsensor")
Device:toggleGSensor(not G_reader_settings:isTrue("input_ignore_gsensor"))
UIManager:broadcastEvent(Event:new("ToggleGSensor"))
end,
})
end

View 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

View File

@@ -6,6 +6,7 @@ local BD = require("ui/bidi")
local ConfirmBox = require("ui/widget/confirmbox")
local DataStorage = require("datastorage")
local Device = require("device")
local Event = require("ui/event")
local InfoMessage = require("ui/widget/infomessage")
local MultiConfirmBox = require("ui/widget/multiconfirmbox")
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?"),
ok_text = _("Restart"),
ok_callback = function()
local savequit_caller
local save_quit = function()
Device:saveSettings()
UIManager:quit()
UIManager._exit_code = 85
end
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)
UIManager:broadcastEvent(Event:new("Exit", save_quit))
end,
})
end

View File

@@ -322,6 +322,10 @@ function FileChooser:changeToPath(path, focused_path)
self:onPathChanged(path)
end
function FileChooser:onFolderUp()
self:changeToPath(string.format("%s/..", self.path))
end
function FileChooser:changePageToPath(path)
if not path then return end
for num, item in ipairs(self.item_table) do