Time reader with normal time format v2 (#3279)

pull/3285/head
Robert 7 years ago committed by Frans de Jonge
parent 3a9651702f
commit f45188fb9d

@ -1,6 +1,5 @@
local InfoMessage = require("ui/widget/infomessage") local InfoMessage = require("ui/widget/infomessage")
local InputDialog = require("ui/widget/inputdialog") local TimeWidget = require("ui/widget/timewidget")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local WidgetContainer = require("ui/widget/container/widgetcontainer") local WidgetContainer = require("ui/widget/container/widgetcontainer")
local T = require("ffi/util").template local T = require("ffi/util").template
@ -54,59 +53,83 @@ function ReadTimer:addToMainMenu(menu_items)
checked_func = function() checked_func = function()
return self:scheduled() return self:scheduled()
end, end,
sub_item_table = {
{
text = _("Time"),
callback = function() callback = function()
local description = _("When should the countdown timer notify you?") local now_t = os.date("*t")
local buttons = {{ local curr_hour = now_t.hour
text = _("Close"), local curr_min = now_t.min
callback = function() local curr_sec_from_midnight = curr_hour*3600 + curr_min*60
UIManager:close(self.input) local time_widget = TimeWidget:new{
end, hour = curr_hour,
}, { min = curr_min,
text = _("Start timer"), ok_text = _("Set timer"),
callback = function() title_text = _("Set reader timer"),
callback = function(time)
self:unschedule() self:unschedule()
local seconds = self.input:getInputValue() * 60 local timer_sec_from_mignight = time.hour*3600 + time.min*60
if seconds > 0 then local seconds
if timer_sec_from_mignight > curr_sec_from_midnight then
seconds = timer_sec_from_mignight - curr_sec_from_midnight
else
seconds = 24*3600 - (curr_sec_from_midnight - timer_sec_from_mignight)
end
if seconds > 0 and seconds < 18*3600 then
self.time = os.time() + seconds self.time = os.time() + seconds
UIManager:scheduleIn(seconds, self.alarm_callback) UIManager:scheduleIn(seconds, self.alarm_callback)
UIManager:show(InfoMessage:new{
text = T(_("Timer set at: %1:%2"), string.format("%02d", time.hour),
string.format("%02d", time.min)),
timeout = 3,
})
--current time or time > 18h
elseif seconds == 0 or seconds >= 18*3600 then
UIManager:show(InfoMessage:new{
text = _("Timer could not be set. You have selected current time or time in past"),
timeout = 3,
})
end end
UIManager:close(self.input)
if self.ui == nil or self.ui.document == nil then
self.ui.menu:onCloseFileManagerMenu()
else
self.ui.menu:onTapCloseMenu()
end end
}
UIManager:show(time_widget)
end, end,
}} },
if self:scheduled() then {
description = description .. text = _("Minutes from now"),
T(_("\n\nYou have already set up a timer for %1 minutes from now. Setting a new one will overwrite it."),
string.format("%.2f", self:remainingMinutes()))
table.insert(buttons, {
text = _("Stop"),
callback = function() callback = function()
local time_widget = TimeWidget:new{
hour = 0,
min = 0,
hour_max = 17,
ok_text = _("Set timer"),
title_text = _("Set reader timer from now (hours:minutes)"),
callback = function(time)
self:unschedule() self:unschedule()
if self.ui == nil or self.ui.document == nil then local seconds = time.hour * 3600 + time.min * 60
self.ui.menu:onCloseFileManagerMenu() if seconds > 0 then
else self.time = os.time() + seconds
self.ui.menu:onTapCloseMenu() UIManager:scheduleIn(seconds, self.alarm_callback)
end UIManager:show(InfoMessage:new{
UIManager:close(self.input) text = T(_("Timer is set to %1 hour(s) and %2 minute(s)"), time.hour, time.min),
end, timeout = 3,
}) })
end end
description = description .. _("\n\n - Positive number is required.") end
self.input = InputDialog:new{
title = _("Read timer"),
description = description,
input_type = "number",
input_hint = _("time in minutes"),
buttons = { buttons },
} }
self.input:onShowKeyboard() UIManager:show(time_widget)
UIManager:show(self.input) end,
},
{
text = _("Stop timer"),
enabled_func = function()
return self:scheduled()
end,
callback = function()
self:unschedule()
end, end,
},
},
} }
end end

Loading…
Cancel
Save