Skip to content

Commit

Permalink
[UX] Gesture manager: add action - toggle wifi
Browse files Browse the repository at this point in the history
As suggested by @poire-z.

koreader#4727 (comment)

I wanted to make the gesture a `W`, but that's a bit too unwieldy. Instead there's the suggestion of a (backward) `W`.
  • Loading branch information
Frenzie committed Mar 5, 2019
1 parent 29f52cc commit 98976a9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions frontend/apps/reader/modules/readergesture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ local action_strings = {
toggle_gsensor = _("Toggle accelerometer"),
toggle_rotation = _("Toggle rotation"),
toggle_reflow = _("Toggle reflow"),
toggle_wifi = _("Toggle wifi"),

zoom_contentwidth = _("Zoom to fit content width"),
zoom_contentheight = _("Zoom to fit content height"),
Expand Down Expand Up @@ -118,6 +119,7 @@ local default_multiswipes = {
"northeast southeast",
-- "southwest northwest", -- visually ambiguous
-- "northwest southwest", -- visually ambiguous
"northwest southwest northwest",
}
local multiswipes = {}
local multiswipes_info_text = _([[
Expand Down Expand Up @@ -155,6 +157,7 @@ function ReaderGesture:init()
multiswipe_south_east_north_south = self.ges_mode == "gesture_reader" and "zoom_pageheight" or "nothing",
multiswipe_east_south_west_north = "full_refresh",
multiswipe_southeast_northeast = self.ges_mode == "gesture_reader" and "follow_nearest_link" or "nothing",
multiswipe_northwest_southwest_northwest = Device:hasWifiToggle() and "toggle_wifi",
}
local gm = G_reader_settings:readSetting(self.ges_mode)
if gm == nil then G_reader_settings:saveSetting(self.ges_mode, {}) end
Expand Down Expand Up @@ -330,6 +333,7 @@ function ReaderGesture:buildMenu(ges, default)
{"toggle_gsensor", Device:canToggleGSensor()},
{"toggle_rotation", not self.is_docless, true},
{"toggle_reflow", not self.is_docless, true},
{"toggle_wifi", Device:hasWifiToggle() and "toggle_wifi", true},

{"zoom_contentwidth", not self.is_docless},
{"zoom_contentheight", not self.is_docless},
Expand Down Expand Up @@ -697,6 +701,20 @@ function ReaderGesture:gestureAction(action, ges)
else
self.ui:handleEvent(Event:new("SetScreenMode", "portrait"))
end
elseif action == "toggle_wifi" then
local NetworkMgr = require("ui/network/manager")

if not NetworkMgr:isOnline() then
-- 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 = _("Wifi disabled."),
})
end
elseif action == "suspend" then
UIManager:suspend()
elseif action == "exit" then
Expand Down

0 comments on commit 98976a9

Please sign in to comment.