Messages in numberpicker widget (#5353)

See: #5342
pull/5362/head
Robert 5 years ago committed by Frans de Jonge
parent 0dad707e2e
commit 9163a85b3c

@ -22,6 +22,7 @@ local Device = require("device")
local FrameContainer = require("ui/widget/container/framecontainer") local FrameContainer = require("ui/widget/container/framecontainer")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local Font = require("ui/font") local Font = require("ui/font")
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 RenderText = require("ui/rendertext") local RenderText = require("ui/rendertext")
@ -30,6 +31,7 @@ local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup") local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan") local VerticalSpan = require("ui/widget/verticalspan")
local _ = require("gettext") local _ = require("gettext")
local T = require("ffi/util").template
local Screen = Device.screen local Screen = Device.screen
local NumberPickerWidget = InputContainer:new{ local NumberPickerWidget = InputContainer:new{
@ -128,39 +130,55 @@ function NumberPickerWidget:paintWidget()
value = string.format(self.precision, value) value = string.format(self.precision, value)
end end
local input local input_dialog
local callback_input = nil local callback_input = nil
if self.value_table == nil then if self.value_table == nil then
callback_input = function() callback_input = function()
input = InputDialog:new{ input_dialog = InputDialog:new{
title = _("Enter number"), title = _("Enter number"),
input = self.value,
input_type = "number", input_type = "number",
buttons = { buttons = {
{ {
{ {
text = _("Cancel"), text = _("Cancel"),
callback = function() callback = function()
UIManager:close(input) UIManager:close(input_dialog)
end, end,
}, },
{ {
text = _("OK"), text = _("OK"),
is_enter_default = true, is_enter_default = true,
callback = function() callback = function()
input:closeInputDialog() input_dialog:closeInputDialog()
local input_value = tonumber(input:getInputText()) local input_value = tonumber(input_dialog:getInputText())
if input_value and input_value >= self.value_min and input_value <= self.value_max then if input_value and input_value >= self.value_min and input_value <= self.value_max then
self.value = input_value self.value = input_value
self:update() self:update()
UIManager:close(input_dialog)
elseif input_value and input_value < self.value_min then
UIManager:show(InfoMessage:new{
text = T(_("This value should be %1 or more."), self.value_min),
timeout = 2,
})
elseif input_value and input_value > self.value_max then
UIManager:show(InfoMessage:new{
text = T(_("This value should be %1 or less."), self.value_max),
timeout = 2,
})
else
UIManager:show(InfoMessage:new{
text = _("Invalid value. Please enter a valid value."),
timeout = 2
})
end end
UIManager:close(input)
end, end,
}, },
}, },
}, },
} }
UIManager:show(input) UIManager:show(input_dialog)
input:onShowKeyboard() input_dialog:onShowKeyboard()
end end
end end

Loading…
Cancel
Save