birthday widget: add expanded mode support

This commit is contained in:
Evgeny
2025-01-20 18:32:31 +08:00
parent d1e6efa1d4
commit b5b701ce1c

View File

@@ -3,7 +3,7 @@
-- description = "Shows upcoming birthdays from the contacts"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "1.1"
-- version = "1.2"
local prefs = require "prefs"
local fmt = require "fmt"
@@ -43,23 +43,40 @@ function redraw()
table.sort(contacts,function(a,b) return a.begin < b.begin end)
events = {}
local lines = {}
local lines_exp = {}
prev_begin = contacts[1].begin
for i,v in ipairs(contacts) do
local fmt_out = fmt_line(v)
local insert = 0
if #lines == 0 then
insert = 1
elseif not (fmt_out == lines[#lines]) then
insert = 1
end
if insert == 1 then
local fmt_out = fmt_line(v)
local insert = 0
if #lines == 0 then
insert = 1
elseif not (fmt_out == lines[#lines]) then
insert = 1
end
if insert == 1 then
if #lines_exp >= prefs.count and prev_begin ~= v.begin then
break
end
table.insert(events, v)
table.insert(lines, fmt_out)
if #lines == prefs.count then
break
if #lines < prefs.count then
table.insert(lines, fmt_out)
end
table.insert(lines_exp, fmt_out)
prev_begin = v.begin
end
end
ui:show_lines(lines)
if ui.set_expandable then
if #lines_exp == #lines then
ui:set_expandable(false)
else
ui:set_expandable(true)
end
end
if ui.is_expanded and ui:is_expanded() then
ui:show_lines(lines_exp)
else
ui:show_lines(lines)
end
end
function fmt_line(event)