mirror of
https://github.com/koreader/koreader.git
synced 2025-12-13 20:36:53 +01:00
progressbardialog: support dismissing the dialog
This commit is contained in:
committed by
Frans de Jonge
parent
d6310207f7
commit
ea3a8a7dbe
@@ -35,20 +35,30 @@ end)
|
||||
--]]
|
||||
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local ConfirmBox = require("ui/widget/confirmbox")
|
||||
local Device = require("device")
|
||||
local Font = require("ui/font")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local Geom = require("ui/geometry")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local ProgressWidget = require("ui/widget/progresswidget")
|
||||
local Size = require("ui/size")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local WidgetContainer = require("ui/widget/container/widgetcontainer")
|
||||
local dbg = require("dbg")
|
||||
local time = require("ui/time")
|
||||
local Input = Device.input
|
||||
local Screen = Device.screen
|
||||
local _ = require("gettext")
|
||||
|
||||
local ProgressbarDialog = WidgetContainer:extend {
|
||||
local ProgressbarDialog = InputContainer:extend {
|
||||
align = "center",
|
||||
vertical_align = "center",
|
||||
dismissable = true,
|
||||
dismiss_callback = nil,
|
||||
dismiss_text = nil,
|
||||
refresh_time_seconds = 3,
|
||||
}
|
||||
|
||||
@@ -56,6 +66,24 @@ function ProgressbarDialog:init()
|
||||
self.align = "center"
|
||||
self.dimen = Screen:getSize()
|
||||
|
||||
if self.dismissable then
|
||||
if Device:hasKeys() then
|
||||
self.key_events.AnyKeyPressed = { { Input.group.Any } }
|
||||
end
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events.TapClose = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
self.progress_bar_visible = self.progress_max ~= nil and self.progress_max > 0
|
||||
|
||||
-- used for internal state
|
||||
@@ -173,4 +201,38 @@ function ProgressbarDialog:close()
|
||||
UIManager:close(self, "ui")
|
||||
end
|
||||
|
||||
function ProgressbarDialog:onCloseWidget()
|
||||
if self.dismiss_box then
|
||||
UIManager:close(self.dismiss_box)
|
||||
self.dismiss_box = nil
|
||||
end
|
||||
if self.dismiss_callback then
|
||||
self.dismiss_callback()
|
||||
self.dismiss_callback = nil
|
||||
end
|
||||
end
|
||||
|
||||
function ProgressbarDialog:onDismiss()
|
||||
if self.dismiss_text then
|
||||
self.dismiss_box = ConfirmBox:new{
|
||||
text = self.dismiss_text,
|
||||
cancel_text = _("Cancel"),
|
||||
cancel_callback = function()
|
||||
self.dismiss_box = nil
|
||||
UIManager:close(self)
|
||||
end,
|
||||
ok_text = _("Continue"),
|
||||
ok_callback = function()
|
||||
self.dismiss_box = nil
|
||||
end,
|
||||
dismissable = false,
|
||||
}
|
||||
UIManager:show(self.dismiss_box)
|
||||
else
|
||||
UIManager:close(self)
|
||||
end
|
||||
end
|
||||
ProgressbarDialog.onAnyKeyPressed = ProgressbarDialog.onDismiss
|
||||
ProgressbarDialog.onTapClose = ProgressbarDialog.onDismiss
|
||||
|
||||
return ProgressbarDialog
|
||||
|
||||
Reference in New Issue
Block a user