[UX] Gesture manager: add Exit and Restart action and a few gestures (#4725)

* [UX] Gesture manager: add action - Exit and Restart

Also:
- add and show some separators in the gestures list
- fix gesture removal, and also remove it from settings
- add missing east west east
- add 6 remaining of the 8 knob 3/4 rotations
- add 3 easy knob full rotation (down + east + west)

* Show and allow removing gestures only in settings

* small optimisation (no loop needed on each multiswipe check)

* keep menu open and updated when recording multiswipe
pull/4732/head
poire-z 5 years ago committed by Frans de Jonge
parent 8ecdf9d888
commit c510a5b1b1

@ -49,6 +49,8 @@ local action_strings = {
full_refresh = _("Full screen refresh"), full_refresh = _("Full screen refresh"),
night_mode = _("Night mode"), night_mode = _("Night mode"),
suspend = _("Suspend"), suspend = _("Suspend"),
exit = _("Exit KOReader"),
restart = _("Restart KOReader"),
show_menu = _("Show menu"), show_menu = _("Show menu"),
show_config_menu = _("Show bottom menu"), show_config_menu = _("Show bottom menu"),
show_frontlight_dialog = _("Show frontlight dialog"), show_frontlight_dialog = _("Show frontlight dialog"),
@ -77,6 +79,7 @@ local default_multiswipes = {
"east west", "east west",
"north south", "north south",
"south north", "south north",
true, -- separator
"north west", "north west",
"north east", "north east",
"south west", "south west",
@ -85,15 +88,33 @@ local default_multiswipes = {
"west north", "west north",
"east south", "east south",
"west south", "west south",
true, -- separator
"north south north", "north south north",
"south north south", "south north south",
"west east west", "west east west",
"east west east",
true, -- separator
"south west north",
"north east south",
"north west south",
"west south east",
"west north east",
"east south west",
"east north west", "east north west",
"south east north", "south east north",
true, -- separator
"east north west east", "east north west east",
"south east north south", "south east north south",
true, -- separator
"east south west north", "east south west north",
"west south east north",
"south east north west",
"south west north east",
true, -- separator
"southeast northeast", "southeast northeast",
"northeast southeast",
-- "southwest northwest", -- visually ambiguous
-- "northwest southwest", -- visually ambiguous
} }
local multiswipes = {} local multiswipes = {}
local multiswipes_info_text = _([[ local multiswipes_info_text = _([[
@ -175,6 +196,7 @@ function ReaderGesture:addToMainMenu(menu_items)
{ {
text = _("Multiswipe recorder"), text = _("Multiswipe recorder"),
enabled_func = function() return self.multiswipes_enabled end, enabled_func = function() return self.multiswipes_enabled end,
keep_menu_open = true,
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
local multiswipe_recorder local multiswipe_recorder
multiswipe_recorder = InputDialog:new{ multiswipe_recorder = InputDialog:new{
@ -210,6 +232,7 @@ function ReaderGesture:addToMainMenu(menu_items)
custom_multiswipes:addTableItem("multiswipes", recorded_multiswipe) custom_multiswipes:addTableItem("multiswipes", recorded_multiswipe)
-- TODO implement some nicer method in TouchMenu than this ugly hack for updating the menu -- TODO implement some nicer method in TouchMenu than this ugly hack for updating the menu
touchmenu_instance.item_table[3] = self:genMultiswipeSubmenu() touchmenu_instance.item_table[3] = self:genMultiswipeSubmenu()
touchmenu_instance:updateItems()
UIManager:close(multiswipe_recorder) UIManager:close(multiswipe_recorder)
end, end,
}, },
@ -292,6 +315,9 @@ function ReaderGesture:buildMenu(ges, default)
{"full_refresh", true}, {"full_refresh", true},
{"night_mode", true}, {"night_mode", true},
{"suspend", true}, {"suspend", true},
{"exit", true},
{"restart", not Device:isAndroid()},
{"show_menu", true}, {"show_menu", true},
{"show_config_menu", not self.is_docless}, {"show_config_menu", not self.is_docless},
{"show_frontlight_dialog", Device:hasFrontlight()}, {"show_frontlight_dialog", Device:hasFrontlight()},
@ -341,43 +367,83 @@ function ReaderGesture:buildMultiswipeMenu()
local menu = {} local menu = {}
multiswipes = {} multiswipes = {}
-- Build a list of gestures in settings, so we can show those
-- that don't appear anymore in default or custom lists, and
-- allow removing them (as they will still work)
local settings_gestures = {}
for k, v in pairs(gesture_manager) do
if k:sub(1, 11) == "multiswipe_" then
k = k:sub(12):gsub("_", " ")
settings_gestures[k] = v
end
end
for k, v in pairs(default_multiswipes) do for k, v in pairs(default_multiswipes) do
table.insert(multiswipes, v) table.insert(multiswipes, v)
settings_gestures[v] = nil -- remove from settings list
end end
if custom_multiswipes_table then if custom_multiswipes_table and #custom_multiswipes_table > 0 then
table.insert(multiswipes, true) -- add separator
for k, v in pairs(custom_multiswipes_table) do for k, v in pairs(custom_multiswipes_table) do
table.insert(multiswipes, v) table.insert(multiswipes, v)
settings_gestures[v] = nil -- remove from settings list
end
end
if next(settings_gestures) then -- there are old gestures in settings
table.insert(multiswipes, true) -- add separator
for k, v in pairs(settings_gestures) do
table.insert(multiswipes, k)
end end
end end
for i=1, #multiswipes do for i=1, #multiswipes do
local multiswipe = multiswipes[i] local separator = false
local friendly_multiswipe_name = self:friendlyMultiswipeName(multiswipe) if i < #multiswipes and multiswipes[i+1] == true then
local safe_multiswipe_name = "multiswipe_"..self:safeMultiswipeName(multiswipe) separator = true
local default_action = self.default_gesture[safe_multiswipe_name] and self.default_gesture[safe_multiswipe_name] or "nothing" end
table.insert(menu, { if type(multiswipes[i]) == "string" then -- skip separators (true)
text_func = function() local multiswipe = multiswipes[i]
local action_name = gesture_manager[safe_multiswipe_name] ~= "nothing" and action_strings[gesture_manager[safe_multiswipe_name]] or _("Available") local friendly_multiswipe_name = self:friendlyMultiswipeName(multiswipe)
return T(_("%1 (%2)"), friendly_multiswipe_name, action_name) -- friendly_multiswipe_name = friendly_multiswipe_name .. os.time() -- for debugging menu updates
end, local safe_multiswipe_name = "multiswipe_"..self:safeMultiswipeName(multiswipe)
sub_item_table = self:buildMenu(safe_multiswipe_name, default_action), local default_action = self.default_gesture[safe_multiswipe_name] and self.default_gesture[safe_multiswipe_name] or "nothing"
hold_callback = function(touchmenu_instance) table.insert(menu, {
if i > #default_multiswipes then text_func = function()
UIManager:show(ConfirmBox:new{ local action_name = gesture_manager[safe_multiswipe_name] ~= "nothing" and action_strings[gesture_manager[safe_multiswipe_name]] or _("Available")
text = T(_("Remove custom multiswipe %1?"), friendly_multiswipe_name), return T(_("%1 (%2)"), friendly_multiswipe_name, action_name)
ok_text = _("Remove"), end,
ok_callback = function() sub_item_table = self:buildMenu(safe_multiswipe_name, default_action),
-- multiswipes are a combined table, first defaults, then custom hold_callback = function(touchmenu_instance)
-- so the right index is minus #defalt_multiswipes if i > #default_multiswipes + 1 then -- +1 for added separator (true)
custom_multiswipes:removeTableItem("multiswipes", i-#default_multiswipes) UIManager:show(ConfirmBox:new{
touchmenu_instance.item_table = self:buildMultiswipeMenu() text = T(_("Remove custom multiswipe %1?"), friendly_multiswipe_name),
touchmenu_instance:updateItems() ok_text = _("Remove"),
end, ok_callback = function()
}) -- Remove associated action from settings
end gesture_manager[safe_multiswipe_name] = nil
end, -- multiswipes are a combined table, first defaults, then custom
}) -- so the right index is minus #defalt_multiswipes minus 1 added separator
custom_multiswipes:removeTableItem("multiswipes", i-#default_multiswipes-1)
-- touchmenu_instance.item_table = self:buildMultiswipeMenu()
-- We need to update touchmenu_instance.item_table in-place for the upper
-- menu to have it updated too
local item_table = touchmenu_instance.item_table
while #item_table > 0 do
table.remove(item_table, #item_table)
end
for __, v in ipairs(self:buildMultiswipeMenu()) do
table.insert(item_table, v)
end
touchmenu_instance:updateItems()
end,
})
end
end,
separator = separator,
})
end
end end
return menu return menu
@ -624,6 +690,10 @@ function ReaderGesture:gestureAction(action, ges)
end end
elseif action == "suspend" then elseif action == "suspend" then
UIManager:suspend() UIManager:suspend()
elseif action == "exit" then
self.ui.menu:exitOrRestart()
elseif action == "restart" then
self.ui.menu:exitOrRestart(function() UIManager:restartKOReader() 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
@ -646,10 +716,9 @@ function ReaderGesture:multiswipeAction(multiswipe_directions, ges)
if not self.multiswipes_enabled then return end if not self.multiswipes_enabled then return end
local gesture_manager = G_reader_settings:readSetting(self.ges_mode) local gesture_manager = G_reader_settings:readSetting(self.ges_mode)
local multiswipe_gesture_name = "multiswipe_"..self:safeMultiswipeName(multiswipe_directions) local multiswipe_gesture_name = "multiswipe_"..self:safeMultiswipeName(multiswipe_directions)
for gesture, action in pairs(gesture_manager) do local action = gesture_manager[multiswipe_gesture_name]
if gesture == multiswipe_gesture_name then if action and action ~= "nothing" then
return self:gestureAction(action, ges) return self:gestureAction(action, ges)
end
end end
end end

Loading…
Cancel
Save