From b7e9d3d1d938d21efdd56d47e381628f7358e269 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Sat, 22 Oct 2022 13:57:10 +0400 Subject: [PATCH] add new apis --- README.md | 14 +++++++++++-- samples/calendar-sample2.lua | 38 ++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 samples/calendar-sample2.lua diff --git a/README.md b/README.md index 1116cc9..6810705 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,8 @@ The type of script is determined by the line (meta tag) at the beginning of the * 4.4.7 - added `intent` module; * 4.5.0 - the `aio` module has been significantly expanded, also added `system:currency()` and `ui:show_list_dialog()`; * 4.5.2 - added `anim` and `morph` packages, added `calendar:open_event()` function; -* 4.5.3 - removed get_ prefixes where they are not needed while maintaining backward compatibility. +* 4.5.3 - removed get_ prefixes where they are not needed while maintaining backward compatibility; +* 4.5.5 - added `on_action` callback and `calendar:add_event` function. # Widget scripts @@ -258,6 +259,14 @@ end This function will be called on add, remove or move any widget. +It is also possible to process an swiping to right action (if this action is selected in the settings). To do this, create a function `on_action`: + +``` +function on_action() + ui:show_toast("Action fired!") +end +``` + ## Application management * `apps:list([sort_by], [no_hidden])` - returns the package table of all installed applications, `sort_by` - sort option (see below), `no_hidden` - true if no hidden applications are needed; @@ -294,7 +303,8 @@ If there is a problem with the network, the `on_network_error_$id` callback will * `calendar:events([start_date], [end_date], [cal_table])` - returns table of event tables of all calendars, start\_date - event start date, end\_date - event end date, cal\_table - calendar ID table; * `calendar:calendars()` - returns table of calendars tables; * `calendar:show_event_dialog(id)` - shows the event dialog; -* `calendar:open_ovent(id)` - opens an event in the system calendar. +* `calendar:open_ovent(id)` - opens an event in the system calendar; +* `calendar:add_event(event_table)` - adds event to the system calendar. Event table format: diff --git a/samples/calendar-sample2.lua b/samples/calendar-sample2.lua new file mode 100644 index 0000000..4281bc7 --- /dev/null +++ b/samples/calendar-sample2.lua @@ -0,0 +1,38 @@ +--[[ +Keep in mind: there can be a delay of up to several minutes +between adding an event and its appearance +in the calendar and in the AIO widget. +--]] + +cals = {} + +function on_resume() + local names = {} + + cals = slice(calendar:calendars(), 1, 10) + + for k,v in ipairs(cals) do + names[k] = v.name + end + + ui:show_lines(names) +end + +function on_click(idx) + local cal_id = cals[idx].id + + local success = calendar:add_event{ + calendar_id = cal_id, + title = "test", + description = "test", + begin = os.time(), + ["end"] = os.time() + 3600, + allDay = false, + } + + if success then + ui:show_toast("Test event added") + else + ui:show_toast("Error") + end +end