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 Geom = require("ui/geometry")
local Font = require("ui/font")
local InfoMessage = require("ui/widget/infomessage")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local RenderText = require("ui/rendertext")
@ -30,6 +31,7 @@ local UIManager = require("ui/uimanager")
local VerticalGroup = require("ui/widget/verticalgroup")
local VerticalSpan = require("ui/widget/verticalspan")
local _ = require("gettext")
local T = require("ffi/util").template
local Screen = Device.screen
local NumberPickerWidget = InputContainer:new{
@ -128,39 +130,55 @@ function NumberPickerWidget:paintWidget()
value = string.format(self.precision, value)
end
local input
local input_dialog
local callback_input = nil
if self.value_table == nil then
callback_input = function()
input = InputDialog:new{
input_dialog = InputDialog:new{
title = _("Enter number"),
input = self.value,
input_type = "number",
buttons = {
{
{
text = _("Cancel"),
callback = function()
UIManager:close(input)
UIManager:close(input_dialog)
end,
},
{
text = _("OK"),
is_enter_default = true,
callback = function()
input:closeInputDialog()
local input_value = tonumber(input:getInputText())
input_dialog:closeInputDialog()
local input_value = tonumber(input_dialog:getInputText())
if input_value and input_value >= self.value_min and input_value <= self.value_max then
self.value = input_value
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
UIManager:close(input)
end,
},
},
},
}
UIManager:show(input)
input:onShowKeyboard()
UIManager:show(input_dialog)
input_dialog:onShowKeyboard()
end
end

Loading…
Cancel
Save