mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
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:
@@ -6,6 +6,7 @@ local InfoMessage = require("ui/widget/infomessage")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local _ = require("gettext")
|
||||
local T = require("ffi/util").template
|
||||
local logger = require("logger")
|
||||
|
||||
local optionsutil = {}
|
||||
|
||||
@@ -147,4 +148,58 @@ Default margins:
|
||||
end
|
||||
end
|
||||
|
||||
function optionsutil:generateOptionText()
|
||||
local CreOptions = require("ui/data/creoptions")
|
||||
|
||||
self.option_text_table = {}
|
||||
self.option_args_table = {}
|
||||
for i = 1, #CreOptions do
|
||||
for j = 1, #CreOptions[i].options do
|
||||
local option = CreOptions[i].options[j]
|
||||
if option.event then
|
||||
if option.labels then
|
||||
self.option_text_table[option.event] = option.labels
|
||||
elseif option.toggle then
|
||||
self.option_text_table[option.event] = option.toggle
|
||||
end
|
||||
self.option_args_table[option.event] = option.args
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function optionsutil:getOptionText(event, val)
|
||||
if not self.option_text_table then
|
||||
self:generateOptionText()
|
||||
end
|
||||
if not event or val == nil then
|
||||
logger.err("[OptionsCatalog:getOptionText] Either event or val not set. This should not happen!")
|
||||
return ""
|
||||
end
|
||||
if not self.option_text_table[event] then
|
||||
logger.err("[OptionsCatalog:getOptionText] Event:" .. event .. " not found in option_text_table")
|
||||
return ""
|
||||
end
|
||||
|
||||
local text
|
||||
if type(val) == "number" then
|
||||
text = self.option_text_table[event][val + 1] -- options count from zero
|
||||
end
|
||||
|
||||
-- if there are args, try to find the adequate toggle
|
||||
if self.option_args_table[event] then
|
||||
for i, args in pairs(self.option_args_table[event]) do
|
||||
if args == val then
|
||||
text = self.option_text_table[event][i]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if text then
|
||||
return text
|
||||
else
|
||||
return val
|
||||
end
|
||||
end
|
||||
|
||||
return optionsutil
|
||||
|
||||
Reference in New Issue
Block a user