mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
screen_rotation_menu_table: deduplicate (#10954)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user