mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
refactoring: buildin hold on menu entry to input
This commit is contained in:
@@ -98,6 +98,7 @@ function FileManagerMenu:setUpdateItemTable()
|
||||
})
|
||||
|
||||
table.insert(self.tab_item_table.setting, Screen:getDPIMenuTable())
|
||||
table.insert(self.tab_item_table.setting, UIManager:getRefreshMenuTable())
|
||||
table.insert(self.tab_item_table.setting, Language:getLangMenuTable())
|
||||
|
||||
-- info tab
|
||||
|
||||
@@ -90,7 +90,7 @@ function ReaderMenu:setUpdateItemTable()
|
||||
end
|
||||
})
|
||||
table.insert(self.tab_item_table.setting, Screen:getDPIMenuTable())
|
||||
table.insert(self.tab_item_table.setting, self:genRefreshRateMenu())
|
||||
table.insert(self.tab_item_table.setting, UIManager:getRefreshMenuTable())
|
||||
table.insert(self.tab_item_table.setting, {
|
||||
text = _("Show advanced options"),
|
||||
checked_func = function() return G_reader_settings:readSetting("show_advanced") end,
|
||||
@@ -121,88 +121,6 @@ function ReaderMenu:setUpdateItemTable()
|
||||
})
|
||||
end
|
||||
|
||||
function ReaderMenu:genRefreshRateMenu()
|
||||
local custom_1 = function() return G_reader_settings:readSetting("refresh_rate_1") or 12 end
|
||||
local custom_2 = function() return G_reader_settings:readSetting("refresh_rate_2") or 22 end
|
||||
local custom_3 = function() return G_reader_settings:readSetting("refresh_rate_3") or 99 end
|
||||
return {
|
||||
text = _("E-ink full refresh rate"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Every page"),
|
||||
checked_func = function() return UIManager:getRefreshRate() == 1 end,
|
||||
callback = function() UIManager:setRefreshRate(1) end,
|
||||
},
|
||||
{
|
||||
text = _("Every 6 pages"),
|
||||
checked_func = function() return UIManager:getRefreshRate() == 6 end,
|
||||
callback = function() UIManager:setRefreshRate(6) end,
|
||||
},
|
||||
{
|
||||
text_func = function() return _("Custom ") .. "1: " .. custom_1() .. _(" pages") end,
|
||||
checked_func = function() return UIManager:getRefreshRate() == custom_1() end,
|
||||
callback = function() UIManager:setRefreshRate(custom_1()) end,
|
||||
hold_callback = function() self:makeCustomRateDialog("refresh_rate_1") end,
|
||||
},
|
||||
{
|
||||
text_func = function() return _("Custom ") .. "2: " .. custom_2() .. _(" pages") end,
|
||||
checked_func = function() return UIManager:getRefreshRate() == custom_2() end,
|
||||
callback = function() UIManager:setRefreshRate(custom_2()) end,
|
||||
hold_callback = function() self:makeCustomRateDialog("refresh_rate_2") end,
|
||||
},
|
||||
{
|
||||
text_func = function() return _("Custom ") .. "3: " .. custom_3() .. _(" pages") end,
|
||||
checked_func = function() return UIManager:getRefreshRate() == custom_3() end,
|
||||
callback = function() UIManager:setRefreshRate(custom_3()) end,
|
||||
hold_callback = function() self:makeCustomRateDialog("refresh_rate_3") end,
|
||||
},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function ReaderMenu:makeCustomRate(custom_rate)
|
||||
local number = tonumber(self.custom_dialog:getInputText())
|
||||
G_reader_settings:saveSetting(custom_rate, number)
|
||||
end
|
||||
|
||||
function ReaderMenu:makeCustomRateDialog(custom_rate)
|
||||
self.custom_dialog = InputDialog:new{
|
||||
title = _("Input page number for a full refresh"),
|
||||
input_hint = "(1 - 99)",
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
callback = function()
|
||||
self:closeMakeCustomDialog()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("OK"),
|
||||
callback = function()
|
||||
self:makeCustomRate(custom_rate)
|
||||
self:closeMakeCustomDialog()
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
input_type = "number",
|
||||
enter_callback = function()
|
||||
self:makeCustomRate(custom_rate)
|
||||
self:closeMakeCustomDialog()
|
||||
end,
|
||||
width = Screen:getWidth() * 0.8,
|
||||
height = Screen:getHeight() * 0.2,
|
||||
}
|
||||
self.custom_dialog:onShowKeyboard()
|
||||
UIManager:show(self.custom_dialog)
|
||||
end
|
||||
|
||||
function ReaderMenu:closeMakeCustomDialog()
|
||||
self.custom_dialog:onClose()
|
||||
UIManager:close(self.custom_dialog)
|
||||
end
|
||||
|
||||
function ReaderMenu:onShowReaderMenu()
|
||||
if #self.tab_item_table.setting == 0 then
|
||||
self:setUpdateItemTable()
|
||||
|
||||
@@ -440,6 +440,55 @@ function UIManager:run()
|
||||
end
|
||||
end
|
||||
|
||||
function UIManager:getRefreshMenuTable()
|
||||
local function custom_1() return G_reader_settings:readSetting("refresh_rate_1") or 12 end
|
||||
local function custom_2() return G_reader_settings:readSetting("refresh_rate_2") or 22 end
|
||||
local function custom_3() return G_reader_settings:readSetting("refresh_rate_3") or 99 end
|
||||
local function custom_input(name)
|
||||
return {
|
||||
title = _("Input page number for a full refresh"),
|
||||
type = "number",
|
||||
hint = "(1 - 99)",
|
||||
callback = function(input)
|
||||
G_reader_settings:saveSetting(name, tonumber(input))
|
||||
end,
|
||||
}
|
||||
end
|
||||
return {
|
||||
text = _("E-ink full refresh rate"),
|
||||
sub_item_table = {
|
||||
{
|
||||
text = _("Every page"),
|
||||
checked_func = function() return UIManager:getRefreshRate() == 1 end,
|
||||
callback = function() UIManager:setRefreshRate(1) end,
|
||||
},
|
||||
{
|
||||
text = _("Every 6 pages"),
|
||||
checked_func = function() return UIManager:getRefreshRate() == 6 end,
|
||||
callback = function() UIManager:setRefreshRate(6) end,
|
||||
},
|
||||
{
|
||||
text_func = function() return _("Custom ") .. "1: " .. custom_1() .. _(" pages") end,
|
||||
checked_func = function() return UIManager:getRefreshRate() == custom_1() end,
|
||||
callback = function() UIManager:setRefreshRate(custom_1()) end,
|
||||
hold_input = custom_input("refresh_rate_1")
|
||||
},
|
||||
{
|
||||
text_func = function() return _("Custom ") .. "2: " .. custom_2() .. _(" pages") end,
|
||||
checked_func = function() return UIManager:getRefreshRate() == custom_2() end,
|
||||
callback = function() UIManager:setRefreshRate(custom_2()) end,
|
||||
hold_input = custom_input("refresh_rate_2")
|
||||
},
|
||||
{
|
||||
text_func = function() return _("Custom ") .. "3: " .. custom_3() .. _(" pages") end,
|
||||
checked_func = function() return UIManager:getRefreshRate() == custom_3() end,
|
||||
callback = function() UIManager:setRefreshRate(custom_3()) end,
|
||||
hold_input = custom_input("refresh_rate_3")
|
||||
},
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
UIManager:init()
|
||||
return UIManager
|
||||
|
||||
|
||||
@@ -3,21 +3,21 @@ local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local Font = require("ui/font")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
local Screen = require("ui/screen")
|
||||
local Device = require("ui/device")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local VerticalSpan = require("ui/widget/verticalspan")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local LineWidget = require("ui/widget/linewidget")
|
||||
local IconButton = require("ui/widget/iconbutton")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Button = require("ui/widget/button")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Device = require("ui/device")
|
||||
local Screen = require("ui/screen")
|
||||
local Geom = require("ui/geometry")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -487,45 +487,93 @@ function TouchMenu:onSwipe(arg, ges_ev)
|
||||
end
|
||||
|
||||
function TouchMenu:onMenuSelect(item)
|
||||
local sub_item_table = item.sub_item_table
|
||||
if item.sub_item_table_func then
|
||||
sub_item_table = item.sub_item_table_func()
|
||||
end
|
||||
if sub_item_table == nil then
|
||||
local callback = item.callback
|
||||
if item.callback_func then
|
||||
callback = item.callback_func()
|
||||
end
|
||||
if callback then
|
||||
-- put stuff in scheduler so we can See
|
||||
-- the effect of inverted menu item
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
self:closeMenu()
|
||||
callback()
|
||||
end)
|
||||
end
|
||||
if item.tap_input then
|
||||
self:closeMenu()
|
||||
self:onMenuInput(item.tap_input)
|
||||
else
|
||||
table.insert(self.item_table_stack, self.item_table)
|
||||
self.item_table = sub_item_table
|
||||
self:updateItems()
|
||||
local sub_item_table = item.sub_item_table
|
||||
if item.sub_item_table_func then
|
||||
sub_item_table = item.sub_item_table_func()
|
||||
end
|
||||
if sub_item_table == nil then
|
||||
local callback = item.callback
|
||||
if item.callback_func then
|
||||
callback = item.callback_func()
|
||||
end
|
||||
if callback then
|
||||
-- put stuff in scheduler so we can See
|
||||
-- the effect of inverted menu item
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
self:closeMenu()
|
||||
callback()
|
||||
end)
|
||||
end
|
||||
else
|
||||
table.insert(self.item_table_stack, self.item_table)
|
||||
self.item_table = sub_item_table
|
||||
self:updateItems()
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function TouchMenu:onMenuHold(item)
|
||||
local callback = item.hold_callback
|
||||
if item.hold_callback_func then
|
||||
callback = item.hold_callback_func()
|
||||
end
|
||||
if callback then
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
self:closeMenu()
|
||||
callback()
|
||||
end)
|
||||
if item.hold_input then
|
||||
self:closeMenu()
|
||||
self:onMenuInput(item.hold_input)
|
||||
else
|
||||
local callback = item.hold_callback
|
||||
if item.hold_callback_func then
|
||||
callback = item.hold_callback_func()
|
||||
end
|
||||
if callback then
|
||||
UIManager:scheduleIn(0.1, function()
|
||||
self:closeMenu()
|
||||
callback()
|
||||
end)
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function TouchMenu:onMenuInput(input)
|
||||
self.input_dialog = InputDialog:new{
|
||||
title = input.title or "",
|
||||
input_hint = input.hint or "",
|
||||
input_type = input.type or "number",
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
callback = function()
|
||||
self:closeInputDialog()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("OK"),
|
||||
callback = function()
|
||||
input.callback(self.input_dialog:getInputText())
|
||||
self:closeInputDialog()
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
enter_callback = function()
|
||||
input.callback(self.input_dialog:getInputText())
|
||||
self:closeInputDialog()
|
||||
end,
|
||||
width = Screen:getWidth() * 0.8,
|
||||
height = Screen:getHeight() * 0.2,
|
||||
}
|
||||
self.input_dialog:onShowKeyboard()
|
||||
UIManager:show(self.input_dialog)
|
||||
end
|
||||
|
||||
function TouchMenu:closeInputDialog()
|
||||
self.input_dialog:onClose()
|
||||
UIManager:close(self.input_dialog)
|
||||
end
|
||||
|
||||
function TouchMenu:onTapCloseAllMenus(arg, ges_ev)
|
||||
if ges_ev.pos:notIntersectWith(self.dimen) then
|
||||
self:closeMenu()
|
||||
|
||||
Reference in New Issue
Block a user