Notification: refactor settings

Simplify the code, because the bit trickery was fairly nasty to follow.
KISS: flip one value at a time, either in or out.

Actually allow flipping *all* of the things via the UI, to help track
what the hell is actually happening when you touch a button.

Make some of 'em radio to make it clear when flipping one might affect
the other(s).

Brought on by https://www.mobileread.com/forums/showthread.php?t=358166
reviewable/pr11330/r1
NiLuJe 5 months ago
parent ccbfbabb25
commit 3131475e39

@ -1,19 +1,49 @@
local Notification = require("ui/widget/notification") local Notification = require("ui/widget/notification")
local TextViewer = require("ui/widget/textviewer") local TextViewer = require("ui/widget/textviewer")
local UIManager = require("ui/uimanager") local UIManager = require("ui/uimanager")
local logger = require("logger")
local _ = require("gettext") local _ = require("gettext")
local band = bit.band local band = bit.band
local bor = bit.bor local bor = bit.bor
local bnot = bit.bnot
local function getMask()
return G_reader_settings:readSetting("notification_sources_to_show_mask") or Notification.SOURCE_DEFAULT
end
local function setMask(source) local function setMask(source)
logger.dbg(string.format("Notification: Updating display mask from %#x to %#x", getMask(), source))
G_reader_settings:saveSetting("notification_sources_to_show_mask", source) G_reader_settings:saveSetting("notification_sources_to_show_mask", source)
end end
local function getMask() local function someEnabled()
return G_reader_settings:readSetting("notification_sources_to_show_mask") or Notification.SOURCE_DEFAULT return band(getMask(), Notification.SOURCE_SOME) == Notification.SOURCE_SOME
end
-- i.e., MORE - SOME
local SOURCE_MORE = band(Notification.SOURCE_MORE, bnot(Notification.SOURCE_SOME))
local function moreEnabled()
return band(getMask(), SOURCE_MORE) == SOURCE_MORE
end
local function dispatcherEnabled()
return band(getMask(), Notification.SOURCE_DISPATCHER) == Notification.SOURCE_DISPATCHER
end
-- i.e., ALL - DEFAULT
local SOURCE_MISC = band(Notification.SOURCE_ALL, bnot(Notification.SOURCE_DEFAULT))
local function miscEnabled()
return band(getMask(), SOURCE_MISC) == SOURCE_MISC
end
--[[
local function allEnabled()
return band(getMask(), Notification.SOURCE_ALL) == Notification.SOURCE_ALL
end end
--]]
-- NOTE: Default is MORE + DISPATCHER
return { return {
text = _("Notifications"), text = _("Notifications"),
help_text = _([[Notification popups may be shown at the top of screen on various occasions. help_text = _([[Notification popups may be shown at the top of screen on various occasions.
@ -26,58 +56,81 @@ This allows selecting which to show or hide.]]),
{ {
text = _("Some notifications from bottom menu"), text = _("Some notifications from bottom menu"),
help_text = _("Show notification popups for bottom menu settings with no visual feedback."), help_text = _("Show notification popups for bottom menu settings with no visual feedback."),
checked_func = function() checked_func = someEnabled,
return band(getMask(), Notification.SOURCE_BOTTOM_MENU) == band(Notification.SOURCE_SOME, Notification.SOURCE_BOTTOM_MENU)
end,
callback = function() callback = function()
if band(getMask(), Notification.SOURCE_BOTTOM_MENU) == band(Notification.SOURCE_SOME, Notification.SOURCE_BOTTOM_MENU) then if someEnabled() then
setMask(bor( -- Can't have more without some, so disable more in full
Notification.SOURCE_NONE, setMask(
band(getMask(), Notification.SOURCE_DISPATCHER))) band(getMask(), bnot(Notification.SOURCE_MORE)))
else else
setMask(bor( setMask(
band(Notification.SOURCE_SOME, Notification.SOURCE_BOTTOM_MENU), bor(getMask(), Notification.SOURCE_SOME))
band(getMask(), Notification.SOURCE_DISPATCHER)))
end end
end, end,
}, },
{ {
text = _("More notifications from bottom menu"), text = _("More notifications from bottom menu"),
help_text = _("Show notification popups for more bottom menu settings."), help_text = _("Show notification popups for more bottom menu settings."),
checked_func = function() checked_func = moreEnabled,
return band(getMask(), Notification.SOURCE_BOTTOM_MENU) == band(Notification.SOURCE_DEFAULT, Notification.SOURCE_BOTTOM_MENU) callback = function()
if moreEnabled() then
-- We *can* keep some without more, so only disable the diff between the two
setMask(
band(getMask(), bnot(SOURCE_MORE)))
else
-- But do enable the full set
setMask(
bor(getMask(), Notification.SOURCE_MORE))
end
end, end,
},
{
text = _("Notifications from miscellaneous sources"),
help_text = _("Show notification popups for even more bottom menu settings, as well as standalone & misc notifications."),
checked_func = miscEnabled,
callback = function() callback = function()
if band(getMask(), Notification.SOURCE_BOTTOM_MENU) == band(Notification.SOURCE_DEFAULT, Notification.SOURCE_BOTTOM_MENU) then if miscEnabled() then
setMask(bor( setMask(
Notification.SOURCE_NONE, band(getMask(), bnot(SOURCE_MISC)))
band(getMask(), Notification.SOURCE_DISPATCHER)))
else else
setMask(bor( setMask(
band(Notification.SOURCE_DEFAULT, Notification.SOURCE_BOTTOM_MENU), bor(getMask(), SOURCE_MISC))
band(getMask(), Notification.SOURCE_DISPATCHER)))
end end
end, end,
}, },
{ {
text = _("Notifications from gestures and profiles"), text = _("Notifications from gestures and profiles"),
help_text = _("Show notification popups for changes from gestures and the profiles plugin."), help_text = _("Show notification popups for changes from gestures and the profiles plugin."),
checked_func = function() checked_func = dispatcherEnabled,
return band(getMask(), Notification.SOURCE_DISPATCHER) == Notification.SOURCE_DISPATCHER callback = function()
if dispatcherEnabled() then
setMask(
band(getMask(), bnot(Notification.SOURCE_DISPATCHER)))
else
setMask(
bor(getMask(), Notification.SOURCE_DISPATCHER))
end
end, end,
separator = true,
},
--[[
{
text = _("Notifications from everything"),
help_text = _("Show all notification popups, no matter the source. This will flip all of the above at once."),
checked_func = allEnabled,
radio = true,
callback = function() callback = function()
if band(getMask(), Notification.SOURCE_DISPATCHER) == Notification.SOURCE_DISPATCHER then if allEnabled() then
setMask(bor( setMask(
Notification.SOURCE_NONE, band(getMask(), bnot(Notification.SOURCE_ALL)))
band(getMask(), Notification.SOURCE_BOTTOM_MENU)))
else else
setMask(bor( setMask(
Notification.SOURCE_DISPATCHER, bor(getMask(), Notification.SOURCE_ALL))
band(getMask(), Notification.SOURCE_BOTTOM_MENU)))
end end
end, end,
separator = true, separator = true,
}, },
--]]
{ {
text = _("Show past notifications"), text = _("Show past notifications"),
callback = function() callback = function()

@ -39,11 +39,12 @@ local SOURCE_BOTTOM_MENU = SOURCE_BOTTOM_MENU_ICON +
SOURCE_BOTTOM_MENU_PROGRESS SOURCE_BOTTOM_MENU_PROGRESS
-- these values can be changed here -- these values can be changed here
local SOURCE_SOME = SOURCE_BOTTOM_MENU_FINE + local SOURCE_SOME = SOURCE_BOTTOM_MENU_FINE
SOURCE_DISPATCHER local SOURCE_MORE = SOURCE_SOME +
local SOURCE_DEFAULT = SOURCE_SOME + SOURCE_BOTTOM_MENU_MORE +
SOURCE_BOTTOM_MENU_MORE + SOURCE_BOTTOM_MENU_PROGRESS
SOURCE_BOTTOM_MENU_PROGRESS local SOURCE_DEFAULT = SOURCE_MORE +
SOURCE_DISPATCHER
local SOURCE_ALL = SOURCE_BOTTOM_MENU + local SOURCE_ALL = SOURCE_BOTTOM_MENU +
SOURCE_DISPATCHER + SOURCE_DISPATCHER +
SOURCE_OTHER SOURCE_OTHER
@ -75,6 +76,7 @@ local Notification = InputContainer:extend{
SOURCE_NONE = 0, SOURCE_NONE = 0,
SOURCE_SOME = SOURCE_SOME, SOURCE_SOME = SOURCE_SOME,
SOURCE_MORE = SOURCE_MORE,
SOURCE_DEFAULT = SOURCE_DEFAULT, SOURCE_DEFAULT = SOURCE_DEFAULT,
SOURCE_ALL = SOURCE_ALL, SOURCE_ALL = SOURCE_ALL,
_past_messages = {}, -- a static class member to store the N last messages text _past_messages = {}, -- a static class member to store the N last messages text

Loading…
Cancel
Save