Notifications: options to show none/some/more (#7718)

Notification: adds some functions so it can be used as
a notification manager.
Have various bits of code emitting events that may generate
notifications advertize themselves as the source for following
notifications.
Add a menu to allow selecting some subsets of sources
to show or hide.
This commit is contained in:
zwim
2021-05-20 23:14:11 +02:00
committed by GitHub
parent 78fdce8e9f
commit 6e2be98edc
13 changed files with 289 additions and 42 deletions

View File

@@ -19,6 +19,26 @@ local VerticalGroup = require("ui/widget/verticalgroup")
local Input = Device.input
local Screen = Device.screen
local band = bit.band
-- The following constants are positions in a bitfield
local SOURCE_BOTTOM_MENU_ICON = 0x0001 -- icons in bottom menu
local SOURCE_BOTTOM_MENU_TOGGLE = 0x0002 -- toggles in bottom menu
local SOURCE_BOTTOM_MENU_FINE = 0x0004 -- toggles with fine-tuning ("increase", "+" etc)
local SOURCE_BOTTOM_MENU_MORE = 0x0008 -- three dots in bottom menu
local SOURCE_BOTTOM_MENU_PROGRESS = 0x0010 -- progress indicator on bottom menu
local SOURCE_DISPATCHER = 0x0020 -- dispatcher
local SOURCE_OTHER = 0x0040 -- all other sources (e.g. keyboard)
-- All bottom menu bits
local SOURCE_BOTTOM_MENU = SOURCE_BOTTOM_MENU_ICON + SOURCE_BOTTOM_MENU_TOGGLE + SOURCE_BOTTOM_MENU_FINE +
SOURCE_BOTTOM_MENU_MORE + SOURCE_BOTTOM_MENU_PROGRESS
-- these values can be changed here
local SOURCE_SOME = SOURCE_BOTTOM_MENU_FINE + SOURCE_DISPATCHER
local SOURCE_DEFAULT = SOURCE_SOME + SOURCE_BOTTOM_MENU_MORE + SOURCE_BOTTOM_MENU_PROGRESS
local SOURCE_ALL = SOURCE_BOTTOM_MENU + SOURCE_DISPATCHER + SOURCE_OTHER
local Notification = InputContainer:new{
face = Font:getFace("x_smallinfofont"),
text = "Null Message",
@@ -28,6 +48,21 @@ local Notification = InputContainer:new{
toast = true, -- closed on any event, and let the event propagate to next top widget
_nums_shown = {}, -- array of stacked notifications
SOURCE_BOTTOM_MENU_ICON = SOURCE_BOTTOM_MENU_ICON,
SOURCE_BOTTOM_MENU_TOGGLE = SOURCE_BOTTOM_MENU_TOGGLE,
SOURCE_BOTTOM_MENU_FINE = SOURCE_BOTTOM_MENU_FINE,
SOURCE_BOTTOM_MENU_MORE = SOURCE_BOTTOM_MENU_MORE,
SOURCE_BOTTOM_MENU_PROGRESS = SOURCE_BOTTOM_MENU_PROGRESS,
SOURCE_DISPATCHER = SOURCE_DISPATCHER,
SOURCE_OTHER = SOURCE_OTHER,
SOURCE_BOTTOM_MENU = SOURCE_BOTTOM_MENU,
SOURCE_NONE = 0,
SOURCE_SOME = SOURCE_SOME,
SOURCE_DEFAULT = SOURCE_DEFAULT,
SOURCE_ALL = SOURCE_ALL,
}
function Notification:init()
@@ -93,6 +128,33 @@ function Notification:init()
}
end
function Notification:setNotifySource(source)
self.notify_source = source
end
function Notification:resetNotifySource()
self.notify_source = Notification.SOURCE_OTHER
end
function Notification:getNotifySource()
return self.notify_source
end
-- show popups if `self.notify_source` is not masked by the setting `notification_sources_to_show_mask`
function Notification:notify(arg, refresh_after)
local mask = G_reader_settings:readSetting("notification_sources_to_show_mask") or self.SOURCE_DEFAULT
if self.notify_source and band(mask, self.notify_source) ~= 0 then
UIManager:show(Notification:new{
text = arg,
})
if refresh_after then
UIManager:forceRePaint()
end
return true
end
return false
end
function Notification:_cleanShownStack(num)
-- Clean stack of shown notifications
if num then