mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
ReadTimer: allow repeat when time is up (#9844)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local DateTimeWidget = require("ui/widget/datetimewidget")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local logger = require("logger")
|
||||
@@ -10,6 +11,7 @@ local T = require("ffi/util").template
|
||||
local ReadTimer = WidgetContainer:extend{
|
||||
name = "readtimer",
|
||||
time = 0, -- The expected time of alarm if enabled, or 0.
|
||||
last_interval_time = 0,
|
||||
}
|
||||
|
||||
function ReadTimer:init()
|
||||
@@ -18,9 +20,31 @@ function ReadTimer:init()
|
||||
if self.time == 0 then return end
|
||||
|
||||
self.time = 0
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_("Read timer alarm\nTime's up. It's %1 now."), os.date("%c")),
|
||||
})
|
||||
local tip_text = _("Time is up")
|
||||
local confirm_box
|
||||
-- only interval support repeat
|
||||
if self.last_interval_time > 0 then
|
||||
logger.dbg("can_repeat, show confirm_box")
|
||||
confirm_box = ConfirmBox:new{
|
||||
text = tip_text,
|
||||
ok_text = _("Repeat"),
|
||||
ok_callback = function()
|
||||
logger.dbg("Schedule a new time:", self.last_interval_time)
|
||||
UIManager:close(confirm_box)
|
||||
self:rescheduleIn(self.last_interval_time)
|
||||
end,
|
||||
cancel_text = _("Done"),
|
||||
cancel_callback = function ()
|
||||
self.last_interval_time = 0
|
||||
end,
|
||||
}
|
||||
UIManager:show(confirm_box)
|
||||
else
|
||||
logger.dbg("can`t_repeat, show infomessage")
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = tip_text,
|
||||
})
|
||||
end
|
||||
end
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
@@ -93,6 +117,7 @@ function ReadTimer:addToMainMenu(menu_items)
|
||||
title_text = _("New alarm"),
|
||||
info_text = _("Enter a time in hours and minutes."),
|
||||
callback = function(time)
|
||||
self.last_interval_time = 0
|
||||
touchmenu_instance:closeMenu()
|
||||
self:unschedule()
|
||||
local then_t = now_t
|
||||
@@ -146,6 +171,7 @@ function ReadTimer:addToMainMenu(menu_items)
|
||||
self:unschedule()
|
||||
local seconds = time.hour * 3600 + time.min * 60
|
||||
if seconds > 0 then
|
||||
self.last_interval_time = seconds
|
||||
self:rescheduleIn(seconds)
|
||||
local user_duration_format = G_reader_settings:readSetting("duration_format")
|
||||
UIManager:show(InfoMessage:new{
|
||||
@@ -169,6 +195,7 @@ function ReadTimer:addToMainMenu(menu_items)
|
||||
return self:scheduled()
|
||||
end,
|
||||
callback = function(touchmenu_instance)
|
||||
self.last_interval_time = 0
|
||||
self:unschedule()
|
||||
touchmenu_instance:updateItems()
|
||||
end,
|
||||
|
||||
Reference in New Issue
Block a user