2019-12-06 21:55:39 +00:00
|
|
|
local BD = require("ui/bidi")
|
2019-09-17 12:50:03 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
|
|
|
local BottomContainer = require("ui/widget/container/bottomcontainer")
|
|
|
|
local Button = require("ui/widget/button")
|
2020-07-30 13:13:54 +00:00
|
|
|
local CenterContainer = require("ui/widget/container/centercontainer")
|
|
|
|
local CheckMark = require("ui/widget/checkmark")
|
2019-09-17 12:50:03 +00:00
|
|
|
local Device = require("device")
|
|
|
|
local Font = require("ui/font")
|
2022-03-12 11:16:50 +00:00
|
|
|
local FocusManager = require("ui/widget/focusmanager")
|
2019-09-17 12:50:03 +00:00
|
|
|
local FrameContainer = require("ui/widget/container/framecontainer")
|
|
|
|
local Geom = require("ui/geometry")
|
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2022-01-10 18:14:40 +00:00
|
|
|
local LeftContainer = require("ui/widget/container/leftcontainer")
|
2019-09-17 12:50:03 +00:00
|
|
|
local LineWidget = require("ui/widget/linewidget")
|
|
|
|
local OverlapGroup = require("ui/widget/overlapgroup")
|
|
|
|
local Size = require("ui/size")
|
|
|
|
local TextWidget = require("ui/widget/textwidget")
|
2022-01-08 16:45:54 +00:00
|
|
|
local TitleBar = require("ui/widget/titlebar")
|
2019-09-17 12:50:03 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
local VerticalGroup = require("ui/widget/verticalgroup")
|
|
|
|
local VerticalSpan = require("ui/widget/verticalspan")
|
|
|
|
local Screen = Device.screen
|
2021-04-16 20:27:52 +00:00
|
|
|
local util = require("util")
|
2019-09-17 12:50:03 +00:00
|
|
|
local T = require("ffi/util").template
|
|
|
|
local _ = require("gettext")
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local SortItemWidget = InputContainer:extend{
|
2020-07-30 13:13:54 +00:00
|
|
|
item = nil,
|
|
|
|
face = Font:getFace("smallinfofont"),
|
2019-09-17 12:50:03 +00:00
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
}
|
|
|
|
|
|
|
|
function SortItemWidget:init()
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
self.dimen = Geom:new{x = 0, y = 0, w = self.width, h = self.height}
|
2022-03-12 11:16:50 +00:00
|
|
|
self.ges_events.Tap = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "tap",
|
|
|
|
range = self.dimen,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
2022-03-12 11:16:50 +00:00
|
|
|
}
|
|
|
|
self.ges_events.Hold = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "hold",
|
|
|
|
range = self.dimen,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
2022-03-12 11:16:50 +00:00
|
|
|
}
|
2019-09-17 12:50:03 +00:00
|
|
|
|
2020-07-30 13:13:54 +00:00
|
|
|
local item_checkable = false
|
|
|
|
local item_checked = self.item.checked
|
|
|
|
if self.item.checked_func then
|
|
|
|
item_checkable = true
|
|
|
|
item_checked = self.item.checked_func()
|
|
|
|
end
|
2020-10-05 12:11:11 +00:00
|
|
|
self.checkmark_widget = CheckMark:new{
|
2020-07-30 13:13:54 +00:00
|
|
|
checkable = item_checkable,
|
|
|
|
checked = item_checked,
|
|
|
|
}
|
|
|
|
|
|
|
|
local checked_widget = CheckMark:new{ -- for layout, to :getSize()
|
|
|
|
checked = true,
|
|
|
|
}
|
|
|
|
|
2021-04-16 20:00:02 +00:00
|
|
|
local text_max_width = self.width - 2 * Size.padding.default - checked_widget:getSize().w
|
2019-09-17 12:50:03 +00:00
|
|
|
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
padding = 0,
|
|
|
|
bordersize = 0,
|
2022-03-12 11:16:50 +00:00
|
|
|
focusable = true,
|
|
|
|
focus_border_size = Size.border.thin,
|
2022-01-10 18:14:40 +00:00
|
|
|
LeftContainer:new{ -- needed only for auto UI mirroring
|
|
|
|
dimen = Geom:new{
|
|
|
|
w = self.width,
|
|
|
|
h = self.height,
|
2019-09-17 12:50:03 +00:00
|
|
|
},
|
2022-11-20 04:33:44 +00:00
|
|
|
HorizontalGroup:new{
|
2022-01-10 18:14:40 +00:00
|
|
|
align = "center",
|
|
|
|
CenterContainer:new{
|
|
|
|
dimen = Geom:new{ w = checked_widget:getSize().w },
|
|
|
|
self.checkmark_widget,
|
|
|
|
},
|
|
|
|
TextWidget:new{
|
|
|
|
text = self.item.text,
|
|
|
|
max_width = text_max_width,
|
2022-11-12 20:22:58 +00:00
|
|
|
face = self.item.face or self.face,
|
2022-01-10 18:14:40 +00:00
|
|
|
},
|
2020-07-30 13:13:54 +00:00
|
|
|
},
|
2019-09-17 12:50:03 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
self[1].invert = self.invert
|
|
|
|
end
|
|
|
|
|
2020-10-05 12:11:11 +00:00
|
|
|
function SortItemWidget:onTap(_, ges)
|
2022-07-31 07:02:09 +00:00
|
|
|
if self.item.checked_func and ( self.show_parent.sort_disabled or ges.pos:intersectWith(self.checkmark_widget.dimen) ) then
|
2020-10-05 12:11:11 +00:00
|
|
|
if self.item.callback then
|
|
|
|
self.item:callback()
|
|
|
|
end
|
2022-07-31 07:02:09 +00:00
|
|
|
elseif self.show_parent.sort_disabled then
|
2022-11-12 20:22:58 +00:00
|
|
|
if self.item.callback then
|
|
|
|
self.item:callback()
|
|
|
|
else
|
|
|
|
return true
|
|
|
|
end
|
2020-10-05 12:11:11 +00:00
|
|
|
elseif self.show_parent.marked == self.index then
|
2019-09-17 12:50:03 +00:00
|
|
|
self.show_parent.marked = 0
|
|
|
|
else
|
|
|
|
self.show_parent.marked = self.index
|
|
|
|
end
|
|
|
|
self.show_parent:_populateItems()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortItemWidget:onHold()
|
2022-11-12 20:22:58 +00:00
|
|
|
if self.item.hold_callback then
|
|
|
|
self.item:hold_callback(function() self.show_parent:_populateItems() end)
|
|
|
|
elseif self.item.callback then
|
2020-07-30 13:13:54 +00:00
|
|
|
self.item:callback()
|
|
|
|
self.show_parent:_populateItems()
|
|
|
|
end
|
2019-09-17 12:50:03 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
local SortWidget = FocusManager:extend{
|
2019-09-17 12:50:03 +00:00
|
|
|
title = "",
|
|
|
|
width = nil,
|
|
|
|
height = nil,
|
|
|
|
-- index for the first item to show
|
|
|
|
show_page = 1,
|
|
|
|
-- table of items to sort
|
2021-04-16 20:27:52 +00:00
|
|
|
item_table = nil, -- mandatory (array)
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = nil,
|
2022-07-31 07:02:09 +00:00
|
|
|
sort_disabled = false
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function SortWidget:init()
|
2022-03-12 11:16:50 +00:00
|
|
|
self.layout = {}
|
2021-04-16 20:27:52 +00:00
|
|
|
-- no item is selected on start
|
|
|
|
self.marked = 0
|
|
|
|
self.orig_item_table = nil
|
|
|
|
|
2019-09-17 12:50:03 +00:00
|
|
|
self.dimen = Geom:new{
|
Clarify our OOP semantics across the codebase (#9586)
Basically:
* Use `extend` for class definitions
* Use `new` for object instantiations
That includes some minor code cleanups along the way:
* Updated `Widget`'s docs to make the semantics clearer.
* Removed `should_restrict_JIT` (it's been dead code since https://github.com/koreader/android-luajit-launcher/pull/283)
* Minor refactoring of LuaSettings/LuaData/LuaDefaults/DocSettings to behave (mostly, they are instantiated via `open` instead of `new`) like everything else and handle inheritance properly (i.e., DocSettings is now a proper LuaSettings subclass).
* Default to `WidgetContainer` instead of `InputContainer` for stuff that doesn't actually setup key/gesture events.
* Ditto for explicit `*Listener` only classes, make sure they're based on `EventListener` instead of something uselessly fancier.
* Unless absolutely necessary, do not store references in class objects, ever; only values. Instead, always store references in instances, to avoid both sneaky inheritance issues, and sneaky GC pinning of stale references.
* ReaderUI: Fix one such issue with its `active_widgets` array, with critical implications, as it essentially pinned *all* of ReaderUI's modules, including their reference to the `Document` instance (i.e., that was a big-ass leak).
* Terminal: Make sure the shell is killed on plugin teardown.
* InputText: Fix Home/End/Del physical keys to behave sensibly.
* InputContainer/WidgetContainer: If necessary, compute self.dimen at paintTo time (previously, only InputContainers did, which might have had something to do with random widgets unconcerned about input using it as a baseclass instead of WidgetContainer...).
* OverlapGroup: Compute self.dimen at *init* time, because for some reason it needs to do that, but do it directly in OverlapGroup instead of going through a weird WidgetContainer method that it was the sole user of.
* ReaderCropping: Under no circumstances should a Document instance member (here, self.bbox) risk being `nil`ed!
* Kobo: Minor code cleanups.
2022-10-06 00:14:48 +00:00
|
|
|
x = 0,
|
|
|
|
y = 0,
|
2019-09-17 12:50:03 +00:00
|
|
|
w = self.width or Screen:getWidth(),
|
|
|
|
h = self.height or Screen:getHeight(),
|
|
|
|
}
|
2022-11-20 04:33:44 +00:00
|
|
|
|
2020-08-03 13:56:44 +00:00
|
|
|
if Device:hasKeys() then
|
2022-10-27 00:01:51 +00:00
|
|
|
self.key_events.Close = { { Device.input.group.Back } }
|
|
|
|
self.key_events.NextPage = { { Device.input.group.PgFwd } }
|
|
|
|
self.key_events.PrevPage = { { Device.input.group.PgBack } }
|
2020-08-03 13:56:44 +00:00
|
|
|
end
|
2019-09-17 12:50:03 +00:00
|
|
|
if Device:isTouchDevice() then
|
|
|
|
self.ges_events.Swipe = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
|
|
|
range = self.dimen,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
local padding = Size.padding.large
|
|
|
|
self.width_widget = self.dimen.w - 2 * padding
|
|
|
|
self.item_width = self.dimen.w - 2 * padding
|
2022-10-10 20:21:27 +00:00
|
|
|
self.footer_center_width = math.floor(self.width_widget * (22/100))
|
|
|
|
self.footer_button_width = math.floor(self.width_widget * (12/100))
|
2019-09-17 12:50:03 +00:00
|
|
|
self.item_height = Size.item.height_big
|
|
|
|
-- group for footer
|
2021-04-16 20:00:02 +00:00
|
|
|
local chevron_left = "chevron.left"
|
|
|
|
local chevron_right = "chevron.right"
|
|
|
|
local chevron_first = "chevron.first"
|
|
|
|
local chevron_last = "chevron.last"
|
2020-01-04 00:18:51 +00:00
|
|
|
if BD.mirroredUILayout() then
|
2021-04-16 20:00:02 +00:00
|
|
|
chevron_left, chevron_right = chevron_right, chevron_left
|
|
|
|
chevron_first, chevron_last = chevron_last, chevron_first
|
2020-01-04 00:18:51 +00:00
|
|
|
end
|
2019-09-17 12:50:03 +00:00
|
|
|
self.footer_left = Button:new{
|
2021-04-16 20:00:02 +00:00
|
|
|
icon = chevron_left,
|
|
|
|
width = self.footer_button_width,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function() self:prevPage() end,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.footer_right = Button:new{
|
2021-04-16 20:00:02 +00:00
|
|
|
icon = chevron_right,
|
|
|
|
width = self.footer_button_width,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function() self:nextPage() end,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.footer_first_up = Button:new{
|
2021-04-16 20:00:02 +00:00
|
|
|
icon = chevron_first,
|
|
|
|
width = self.footer_button_width,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function()
|
|
|
|
if self.marked > 0 then
|
|
|
|
self:moveItem(-1)
|
|
|
|
else
|
|
|
|
self:goToPage(1)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.footer_last_down = Button:new{
|
2021-04-16 20:00:02 +00:00
|
|
|
icon = chevron_last,
|
|
|
|
width = self.footer_button_width,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function()
|
|
|
|
if self.marked > 0 then
|
|
|
|
self:moveItem(1)
|
|
|
|
else
|
|
|
|
self:goToPage(self.pages)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.footer_cancel = Button:new{
|
2021-04-16 20:27:52 +00:00
|
|
|
icon = "exit",
|
2021-04-16 20:00:02 +00:00
|
|
|
width = self.footer_button_width,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function() self:onClose() end,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.footer_ok = Button:new{
|
2021-04-16 20:00:02 +00:00
|
|
|
icon = "check",
|
|
|
|
width = self.footer_button_width,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function() self:onReturn() end,
|
|
|
|
bordersize = 0,
|
|
|
|
radius = 0,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.footer_page = Button:new{
|
|
|
|
text = "",
|
2021-02-25 23:48:05 +00:00
|
|
|
hold_input = {
|
2019-09-17 12:50:03 +00:00
|
|
|
title = _("Enter page number"),
|
|
|
|
hint_func = function()
|
|
|
|
return "(" .. "1 - " .. self.pages .. ")"
|
|
|
|
end,
|
2021-04-16 20:00:02 +00:00
|
|
|
type = "number",
|
|
|
|
deny_blank_input = true,
|
2019-09-17 12:50:03 +00:00
|
|
|
callback = function(input)
|
|
|
|
local page = tonumber(input)
|
|
|
|
if page and page >= 1 and page <= self.pages then
|
|
|
|
self:goToPage(page)
|
|
|
|
end
|
|
|
|
end,
|
2021-08-10 19:19:07 +00:00
|
|
|
ok_text = _("Go to page"),
|
2019-09-17 12:50:03 +00:00
|
|
|
},
|
2021-02-25 23:48:05 +00:00
|
|
|
call_hold_input_on_tap = true,
|
2019-09-17 12:50:03 +00:00
|
|
|
bordersize = 0,
|
|
|
|
margin = 0,
|
|
|
|
text_font_face = "pgfont",
|
|
|
|
text_font_bold = false,
|
2021-04-16 20:00:02 +00:00
|
|
|
width = self.footer_center_width,
|
2021-01-31 01:51:40 +00:00
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
self.page_info = HorizontalGroup:new{
|
|
|
|
self.footer_cancel,
|
|
|
|
self.footer_first_up,
|
|
|
|
self.footer_left,
|
|
|
|
self.footer_page,
|
|
|
|
self.footer_right,
|
|
|
|
self.footer_last_down,
|
|
|
|
self.footer_ok,
|
|
|
|
}
|
2022-03-12 11:16:50 +00:00
|
|
|
table.insert(self.layout, {
|
|
|
|
self.footer_cancel,
|
|
|
|
self.footer_ok,
|
|
|
|
})
|
2019-09-17 12:50:03 +00:00
|
|
|
local bottom_line = LineWidget:new{
|
|
|
|
dimen = Geom:new{ w = self.item_width, h = Size.line.thick },
|
|
|
|
background = Blitbuffer.COLOR_DARK_GRAY,
|
|
|
|
}
|
|
|
|
local vertical_footer = VerticalGroup:new{
|
|
|
|
bottom_line,
|
2021-04-16 20:00:02 +00:00
|
|
|
self.page_info,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
local footer = BottomContainer:new{
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
vertical_footer,
|
|
|
|
}
|
|
|
|
-- setup title bar
|
2022-01-08 16:45:54 +00:00
|
|
|
self.title_bar = TitleBar:new{
|
|
|
|
width = self.dimen.w,
|
|
|
|
align = "left",
|
|
|
|
with_bottom_line = true,
|
|
|
|
bottom_line_color = Blitbuffer.COLOR_DARK_GRAY,
|
|
|
|
bottom_line_h_padding = padding,
|
2019-09-17 12:50:03 +00:00
|
|
|
title = self.title,
|
2022-01-08 16:45:54 +00:00
|
|
|
close_callback = function() self:onClose() end,
|
|
|
|
show_parent = self,
|
2019-09-17 12:50:03 +00:00
|
|
|
}
|
|
|
|
-- setup main content
|
2021-04-16 20:00:02 +00:00
|
|
|
self.item_margin = math.floor(self.item_height / 8)
|
2019-09-17 12:50:03 +00:00
|
|
|
local line_height = self.item_height + self.item_margin
|
2022-01-08 16:45:54 +00:00
|
|
|
local content_height = self.dimen.h - self.title_bar:getHeight() - vertical_footer:getSize().h - padding
|
2019-09-17 12:50:03 +00:00
|
|
|
self.items_per_page = math.floor(content_height / line_height)
|
|
|
|
self.pages = math.ceil(#self.item_table / self.items_per_page)
|
|
|
|
self.main_content = VerticalGroup:new{}
|
|
|
|
|
|
|
|
self:_populateItems()
|
|
|
|
|
2022-01-08 16:45:54 +00:00
|
|
|
local padding_below_title = 0
|
|
|
|
if self.pages > 1 then -- center content vertically
|
|
|
|
padding_below_title = (content_height - self.items_per_page * line_height) / 2
|
|
|
|
end
|
2019-09-17 12:50:03 +00:00
|
|
|
local frame_content = FrameContainer:new{
|
|
|
|
height = self.dimen.h,
|
2022-01-08 16:45:54 +00:00
|
|
|
padding = 0,
|
2019-09-17 12:50:03 +00:00
|
|
|
bordersize = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
VerticalGroup:new{
|
|
|
|
self.title_bar,
|
2022-01-08 16:45:54 +00:00
|
|
|
VerticalSpan:new{ width = padding_below_title },
|
2019-09-17 12:50:03 +00:00
|
|
|
self.main_content,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
local content = OverlapGroup:new{
|
|
|
|
dimen = self.dimen:copy(),
|
|
|
|
frame_content,
|
|
|
|
footer,
|
|
|
|
}
|
|
|
|
-- assemble page
|
|
|
|
self[1] = FrameContainer:new{
|
|
|
|
height = self.dimen.h,
|
|
|
|
padding = 0,
|
|
|
|
bordersize = 0,
|
|
|
|
background = Blitbuffer.COLOR_WHITE,
|
|
|
|
content
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:nextPage()
|
|
|
|
local new_page = math.min(self.show_page+1, self.pages)
|
|
|
|
if new_page > self.show_page then
|
|
|
|
self.show_page = new_page
|
|
|
|
if self.marked > 0 then
|
|
|
|
self:moveItem(self.items_per_page * (self.show_page - 1) + 1 - self.marked)
|
|
|
|
end
|
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:prevPage()
|
|
|
|
local new_page = math.max(self.show_page-1, 1)
|
|
|
|
if new_page < self.show_page then
|
|
|
|
self.show_page = new_page
|
|
|
|
if self.marked > 0 then
|
|
|
|
self:moveItem(self.items_per_page * (self.show_page - 1) + 1 - self.marked)
|
|
|
|
end
|
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:goToPage(page)
|
|
|
|
self.show_page = page
|
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:moveItem(diff)
|
|
|
|
local move_to = self.marked + diff
|
|
|
|
if move_to > 0 and move_to <= #self.item_table then
|
2021-04-16 20:27:52 +00:00
|
|
|
-- Remember the original state to support Cancel
|
|
|
|
if not self.orig_item_table then
|
|
|
|
self.orig_item_table = util.tableDeepCopy(self.item_table)
|
|
|
|
end
|
2020-10-05 13:25:59 +00:00
|
|
|
table.insert(self.item_table, move_to, table.remove(self.item_table, self.marked))
|
2021-04-16 20:00:02 +00:00
|
|
|
self.show_page = math.ceil(move_to / self.items_per_page)
|
2020-10-05 13:25:59 +00:00
|
|
|
self.marked = move_to
|
2019-09-17 12:50:03 +00:00
|
|
|
self:_populateItems()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- make sure self.item_margin and self.item_height are set before calling this
|
|
|
|
function SortWidget:_populateItems()
|
|
|
|
self.main_content:clear()
|
2022-03-12 11:16:50 +00:00
|
|
|
self.layout = { self.layout[#self.layout] } -- keep footer
|
2019-09-17 12:50:03 +00:00
|
|
|
local idx_offset = (self.show_page - 1) * self.items_per_page
|
|
|
|
local page_last
|
|
|
|
if idx_offset + self.items_per_page <= #self.item_table then
|
|
|
|
page_last = idx_offset + self.items_per_page
|
|
|
|
else
|
|
|
|
page_last = #self.item_table
|
|
|
|
end
|
|
|
|
for idx = idx_offset + 1, page_last do
|
|
|
|
table.insert(self.main_content, VerticalSpan:new{ width = self.item_margin })
|
|
|
|
local invert_status = false
|
|
|
|
if idx == self.marked then
|
|
|
|
invert_status = true
|
|
|
|
end
|
2022-03-12 11:16:50 +00:00
|
|
|
local item = SortItemWidget:new{
|
|
|
|
height = self.item_height,
|
|
|
|
width = self.item_width,
|
|
|
|
item = self.item_table[idx],
|
|
|
|
invert = invert_status,
|
|
|
|
index = idx,
|
|
|
|
show_parent = self,
|
|
|
|
}
|
|
|
|
table.insert(self.layout, #self.layout, {item})
|
2019-09-17 12:50:03 +00:00
|
|
|
table.insert(
|
|
|
|
self.main_content,
|
2022-03-12 11:16:50 +00:00
|
|
|
item
|
2019-09-17 12:50:03 +00:00
|
|
|
)
|
|
|
|
end
|
2021-04-16 20:00:02 +00:00
|
|
|
self.footer_page:setText(T(_("Page %1 of %2"), self.show_page, self.pages), self.footer_center_width)
|
|
|
|
if self.pages > 1 then
|
|
|
|
self.footer_page:enable()
|
|
|
|
else
|
|
|
|
self.footer_page:disableWithoutDimming()
|
|
|
|
end
|
|
|
|
local chevron_first = "chevron.first"
|
|
|
|
local chevron_last = "chevron.last"
|
2020-01-04 00:18:51 +00:00
|
|
|
if BD.mirroredUILayout() then
|
2021-04-16 20:00:02 +00:00
|
|
|
chevron_first, chevron_last = chevron_last, chevron_first
|
2020-01-04 00:18:51 +00:00
|
|
|
end
|
2019-09-17 12:50:03 +00:00
|
|
|
if self.marked > 0 then
|
2021-04-16 20:27:52 +00:00
|
|
|
self.footer_cancel:setIcon("cancel", self.footer_button_width)
|
|
|
|
self.footer_cancel.callback = function() self:onCancel() end
|
|
|
|
self.footer_first_up:setIcon("move.up", self.footer_button_width)
|
|
|
|
self.footer_last_down:setIcon("move.down", self.footer_button_width)
|
2019-09-17 12:50:03 +00:00
|
|
|
else
|
2021-04-16 20:27:52 +00:00
|
|
|
self.footer_cancel:setIcon("exit", self.footer_button_width)
|
|
|
|
self.footer_cancel.callback = function() self:onClose() end
|
2021-04-16 20:00:02 +00:00
|
|
|
self.footer_first_up:setIcon(chevron_first, self.footer_button_width)
|
|
|
|
self.footer_last_down:setIcon(chevron_last, self.footer_button_width)
|
2019-09-17 12:50:03 +00:00
|
|
|
end
|
|
|
|
self.footer_left:enableDisable(self.show_page > 1)
|
|
|
|
self.footer_right:enableDisable(self.show_page < self.pages)
|
2021-04-16 20:00:02 +00:00
|
|
|
self.footer_first_up:enableDisable(self.show_page > 1 or (self.marked > 0 and self.marked > 1))
|
2019-09-17 12:50:03 +00:00
|
|
|
self.footer_last_down:enableDisable(self.show_page < self.pages or (self.marked > 0 and self.marked < #self.item_table))
|
|
|
|
UIManager:setDirty(self, function()
|
|
|
|
return "ui", self.dimen
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:onNextPage()
|
|
|
|
self:nextPage()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:onPrevPage()
|
|
|
|
self:prevPage()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:onSwipe(arg, ges_ev)
|
2019-12-06 21:55:39 +00:00
|
|
|
local direction = BD.flipDirectionIfMirroredUILayout(ges_ev.direction)
|
|
|
|
if direction == "west" then
|
2019-09-17 12:50:03 +00:00
|
|
|
self:onNextPage()
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "east" then
|
2019-09-17 12:50:03 +00:00
|
|
|
self:onPrevPage()
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "south" then
|
2019-09-17 12:50:03 +00:00
|
|
|
-- Allow easier closing with swipe down
|
|
|
|
self:onClose()
|
2019-12-06 21:55:39 +00:00
|
|
|
elseif direction == "north" then
|
2019-09-17 12:50:03 +00:00
|
|
|
-- no use for now
|
|
|
|
do end -- luacheck: ignore 541
|
|
|
|
else -- diagonal swipe
|
|
|
|
-- trigger full refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
|
|
|
-- a long diagonal swipe may also be used for taking a screenshot,
|
|
|
|
-- so let it propagate
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function SortWidget:onClose()
|
|
|
|
UIManager:close(self)
|
|
|
|
UIManager:setDirty(nil, "ui")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2021-04-16 20:27:52 +00:00
|
|
|
function SortWidget:onCancel()
|
|
|
|
self.marked = 0
|
|
|
|
if self.orig_item_table then
|
|
|
|
-- We can't break the reference to self.item_table, as that's what the callback uses to update the original data...
|
|
|
|
-- So, do this in two passes: empty it, then re-fill it from the copy.
|
|
|
|
for i = #self.item_table, 1, -1 do
|
|
|
|
self.item_table[i] = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
for __, item in ipairs(self.orig_item_table) do
|
|
|
|
table.insert(self.item_table, item)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.orig_item_table = nil
|
|
|
|
end
|
|
|
|
|
|
|
|
self:goToPage(self.show_page)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2019-09-17 12:50:03 +00:00
|
|
|
function SortWidget:onReturn()
|
2021-04-16 20:27:52 +00:00
|
|
|
-- The callback we were passed is usually responsible for passing along the re-ordered table itself,
|
|
|
|
-- as well as items' enabled flag, if any, meaning we have to honor it even if nothing was moved.
|
|
|
|
if self.callback then
|
|
|
|
self:callback()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- If we're not in the middle of moving stuff around, just exit.
|
|
|
|
if self.marked == 0 then
|
|
|
|
return self:onClose()
|
|
|
|
end
|
|
|
|
|
|
|
|
self.marked = 0
|
|
|
|
self.orig_item_table = nil
|
|
|
|
self:goToPage(self.show_page)
|
2019-09-17 12:50:03 +00:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return SortWidget
|