[calendar-menu] use calendar colors instead of event colors
This commit is contained in:
@@ -4,15 +4,18 @@
|
|||||||
-- type = "drawer"
|
-- type = "drawer"
|
||||||
-- aio_version = "4.7.99"
|
-- aio_version = "4.7.99"
|
||||||
-- author = "Evgeny Zobnin"
|
-- author = "Evgeny Zobnin"
|
||||||
-- version = "1.0"
|
-- version = "1.1"
|
||||||
|
|
||||||
local fmt = require "fmt"
|
local fmt = require "fmt"
|
||||||
|
|
||||||
local have_permission = false
|
local have_permission = false
|
||||||
local events = {}
|
local events = {}
|
||||||
|
local calendars = {}
|
||||||
|
|
||||||
function on_drawer_open()
|
function on_drawer_open()
|
||||||
events = calendar:events()
|
events = calendar:events()
|
||||||
|
calendars = calendar:calendars()
|
||||||
|
add_cal_colors(events, calendars)
|
||||||
|
|
||||||
if events == "permission_error" then
|
if events == "permission_error" then
|
||||||
calendar:request_permission()
|
calendar:request_permission()
|
||||||
@@ -25,14 +28,25 @@ function on_drawer_open()
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
lines = map(events, function(it)
|
lines = map(function(it)
|
||||||
local date = fmt.colored(format_date(it.begin), it.color)
|
local date = fmt.colored(format_date(it.begin), it.calendar_color)
|
||||||
return date..fmt.space(4)..it.title
|
return date..fmt.space(4)..it.title
|
||||||
end)
|
end, events)
|
||||||
|
|
||||||
drawer:show_ext_list(lines)
|
drawer:show_ext_list(lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function add_cal_colors(events, cals)
|
||||||
|
for i, event in ipairs(events) do
|
||||||
|
for _, cal in ipairs(cals) do
|
||||||
|
if event.calendar_id == cal.id then
|
||||||
|
event.calendar_color = cal.color
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function format_date(date)
|
function format_date(date)
|
||||||
if system.format_date_localized then
|
if system.format_date_localized then
|
||||||
return system:format_date_localized("dd.MM", date)
|
return system:format_date_localized("dd.MM", date)
|
||||||
@@ -53,11 +67,3 @@ function on_long_click(idx)
|
|||||||
calendar:open_event(events[idx].id)
|
calendar:open_event(events[idx].id)
|
||||||
end
|
end
|
||||||
|
|
||||||
function map(tbl, f)
|
|
||||||
local ret = {}
|
|
||||||
for k,v in pairs(tbl) do
|
|
||||||
ret[k] = f(v)
|
|
||||||
end
|
|
||||||
return ret
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user