mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
add notification widget and used it in readerbookmark
This commit is contained in:
52
frontend/ui/notification.lua
Normal file
52
frontend/ui/notification.lua
Normal file
@@ -0,0 +1,52 @@
|
||||
require "ui/ui"
|
||||
require "ui/widget"
|
||||
|
||||
--[[
|
||||
Widget that displays a tiny notification on top of screen
|
||||
--]]
|
||||
Notification = InputContainer:new{
|
||||
face = Font:getFace("infofont", 20),
|
||||
text = "Null Message",
|
||||
timeout = nil,
|
||||
|
||||
key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any }, seqtext = "any key", doc = "close dialog" }
|
||||
}
|
||||
}
|
||||
|
||||
function Notification:init()
|
||||
-- we construct the actual content here because self.text is only available now
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = Geom:new{
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight()/10,
|
||||
},
|
||||
ignore = "height",
|
||||
FrameContainer:new{
|
||||
background = 0,
|
||||
radius = 0,
|
||||
HorizontalGroup:new{
|
||||
align = "center",
|
||||
TextBoxWidget:new{
|
||||
text = self.text,
|
||||
face = self.face,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
function Notification:onShow()
|
||||
-- triggered by the UIManager after we got successfully shown (not yet painted)
|
||||
if self.timeout then
|
||||
UIManager:scheduleIn(self.timeout, function() UIManager:close(self) end)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function Notification:onAnyKeyPressed()
|
||||
-- triggered by our defined key events
|
||||
UIManager:close(self)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
require "ui/notification"
|
||||
|
||||
ReaderBookmark = InputContainer:new{
|
||||
bm_menu_title = "Bookmarks",
|
||||
bookmarks = nil,
|
||||
@@ -51,7 +53,7 @@ function ReaderBookmark:onAddBookmark()
|
||||
if not self:addBookmark(pn_or_xp) then
|
||||
noti_text = "Page already marked!"
|
||||
end
|
||||
UIManager:show(InfoMessage:new{
|
||||
UIManager:show(Notification:new{
|
||||
text = noti_text,
|
||||
timeout = 3
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user