update calendar widget

This commit is contained in:
Evgeny
2021-09-14 12:10:56 +03:00
parent d941be94f4
commit e9904277c7

View File

@@ -2,7 +2,7 @@
-- description = "Monthly calendar with system calendar events"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "3.0"
-- version = "3.1"
local tab = {}
local line = " "
@@ -39,11 +39,13 @@ end
function on_click(i)
if widget_type == "table" then
if i == 1 then
system:vibrate(10)
local time = os.time{year=year,month=month,day=1}-24*60*60
year,month = os.date("%Y-%m",time):match("(%d+)-(%d+)")
year,month = year:gsub("^0",""),month:gsub("^0","")
on_alarm()
elseif i == 8 then
system:vibrate(10)
local time = os.time{year=year,month=month,day=1}+31*24*60*60
year,month = os.date("%Y-%m",time):match("(%d+)-(%d+)")
year,month = year:gsub("^0",""),month:gsub("^0","")
@@ -59,15 +61,16 @@ function on_click(i)
widget_type = "lines"
ui:show_table(get_lines(events),2, false, line)
end
return
else
return
end
else
elseif widget_type == "lines" then
if math.ceil(i/3) <= #events then
dialog_id = "event"
calendar:show_event_dialog(events[math.ceil(i/3)][1])
else
on_resume()
widget_type = "table"
ui:show_table(table_to_tables(tab,8),0, true, line)
end
end
end
@@ -98,7 +101,7 @@ function on_dialog_action(data)
return
end
end
local month,year = data:match("(%d+)%.(%d+)")
month,year = data:match("(%d+)%.(%d+)")
month,year = month:gsub("^0",""),year:gsub("^0","")
on_alarm()
elseif dialog_id == "settings" then
@@ -107,7 +110,7 @@ function on_dialog_action(data)
end
end
function get_cal(y,m,days)
function get_cal(y,m)
local color = ui:get_colors()
local events = get_my_events(y,m,0)
local from = os.time{year=y,month=m,day=1}
@@ -165,7 +168,6 @@ function format_day(y,m,d,events)
else
dd = "<font color=\""..color.primary_text.."\">"..dd.."</font>"
end
return dd
end
@@ -203,7 +205,10 @@ function get_my_events(y,m,d)
from =os.time{year=y,month=m,day=d,hour=0,min=0,sec=0}
to = os.time{year=y,month=m,day=d,hour=23,min=59,sec=59}
end
local events = calendar:get_events(from,to,settings:get())
local events = {}
if next(settings:get()) then
events = calendar:get_events(from,to,settings:get())
end
for i=1,#events do
local v = events[i]
if v.begin >= from and v["end"] <= to then
@@ -268,11 +273,9 @@ function get_lines(events)
table.insert(lines," ")
table.insert(lines," ")
end
if #lines/3 < #t then
table.insert(lines," ")
table.insert(lines,"☚ Back")
table.insert(lines," ")
end
return table_to_tables(lines,3)
end