screen_rotation_menu_table: deduplicate (#10954)

reviewable/pr10941/r3
hius07 8 months ago committed by GitHub
parent 40e2a838ae
commit 0c5240074c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,6 +6,26 @@ local _ = require("gettext")
local C_ = _.pgettext
local Screen = Device.screen
local function genMenuItem(text, mode)
return {
text_func = function()
return G_reader_settings:readSetting("fm_rotation_mode") == mode and text .. "" or text
end,
checked_func = function()
return Screen:getRotationMode() == mode
end,
radio = true,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", mode))
touchmenu_instance:closeMenu()
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", mode)
touchmenu_instance:updateItems()
end,
}
end
return {
text = _("Rotation"),
sub_item_table_func = function()
@ -22,9 +42,7 @@ return {
UIManager:broadcastEvent(Event:new("ToggleGSensor"))
end,
})
end
if Device:hasGSensor() then
table.insert(rotation_table, {
text = _("Lock auto rotation to current orientation"),
help_text = _([[
@ -61,90 +79,10 @@ When unchecked, the default rotation of the file browser and the default/saved r
})
if FileManager.instance then
table.insert(rotation_table, {
text_func = function()
local text = C_("Rotation", "⤹ 90°")
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE
end,
radio = true,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, {
text_func = function()
local text = C_("Rotation", "↑ 0°")
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.DEVICE_ROTATED_UPRIGHT then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.DEVICE_ROTATED_UPRIGHT
end,
radio = true,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_UPRIGHT))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.DEVICE_ROTATED_UPRIGHT)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, {
text_func = function()
local text = C_("Rotation", "⤸ 90°")
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.DEVICE_ROTATED_CLOCKWISE then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.DEVICE_ROTATED_CLOCKWISE
end,
radio = true,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_CLOCKWISE))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.DEVICE_ROTATED_CLOCKWISE)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, {
text_func = function()
local text = C_("Rotation", "↓ 180°")
if G_reader_settings:readSetting("fm_rotation_mode") == Screen.DEVICE_ROTATED_UPSIDE_DOWN then
text = text .. ""
end
return text
end,
checked_func = function()
return Screen:getRotationMode() == Screen.DEVICE_ROTATED_UPSIDE_DOWN
end,
radio = true,
callback = function(touchmenu_instance)
UIManager:broadcastEvent(Event:new("SetRotationMode", Screen.DEVICE_ROTATED_UPSIDE_DOWN))
if touchmenu_instance then touchmenu_instance:closeMenu() end
end,
hold_callback = function(touchmenu_instance)
G_reader_settings:saveSetting("fm_rotation_mode", Screen.DEVICE_ROTATED_UPSIDE_DOWN)
if touchmenu_instance then touchmenu_instance:updateItems() end
end,
})
table.insert(rotation_table, genMenuItem(C_("Rotation", "⤹ 90°"), Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE))
table.insert(rotation_table, genMenuItem(C_("Rotation", "↑ 0°"), Screen.DEVICE_ROTATED_UPRIGHT))
table.insert(rotation_table, genMenuItem(C_("Rotation", "⤸ 90°"), Screen.DEVICE_ROTATED_CLOCKWISE))
table.insert(rotation_table, genMenuItem(C_("Rotation", "↓ 180°"), Screen.DEVICE_ROTATED_UPSIDE_DOWN))
end
return rotation_table

Loading…
Cancel
Save