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