Add new drawer scripts

This commit is contained in:
Evgeny
2023-07-14 21:18:05 +04:00
parent 082df0cd09
commit 92f6e0de16
22 changed files with 520 additions and 1 deletions

39
main/calendar-menu.lua Normal file
View File

@@ -0,0 +1,39 @@
-- name = "Calendar menu"
-- name_id = "calendar"
-- description = "Shows events from system calendar"
-- type = "drawer"
-- aio_version = "4.7.99"
-- author = "Evgeny Zobnin"
-- version = "1.0"
local fmt = require "fmt"
local events = {}
function on_drawer_open()
events = calendar:events()
lines = map(events, function(it)
local date = fmt.colored(os.date("%d.%m", it.begin), it.color)
return date..fmt.space(4)..it.title
end)
drawer:show_ext_list(lines)
end
function on_click(idx)
calendar:show_event_dialog(events[idx].id)
end
function on_long_click(idx)
calendar:open_event(events[idx].id)
end
function map(tbl, f)
local ret = {}
for k,v in pairs(tbl) do
ret[k] = f(v)
end
return ret
end

51
main/contacts-menu.lua Normal file
View File

@@ -0,0 +1,51 @@
-- name = "Contacts menu"
-- name_id = "contacts"
-- description = "Shows phone contacts in the side menu"
-- type = "drawer"
-- aio_version = "4.7.99"
-- author = "Evgeny Zobnin"
-- version = "1.0"
function on_drawer_open()
contacts = distinct_by_name(
sort_by_name(phone:contacts())
)
names = map(contacts, function(it) return it.name end)
keys = map(contacts, function(it) return it.lookup_key end)
phone:request_icons(keys)
end
function on_icons_ready(icons)
drawer:show_list(names, icons, nil, true)
end
function on_click(idx)
phone:show_contact_dialog(contacts[idx].lookup_key)
end
function map(tbl, f)
local ret = {}
for k,v in pairs(tbl) do
ret[k] = f(v)
end
return ret
end
function sort_by_name(tbl)
table.sort(tbl, function(a,b) return a.name:lower() < b.name:lower() end)
return tbl
end
function distinct_by_name(tbl)
local ret = {}
local names = {}
for _, contact in ipairs(tbl) do
if not names[contact.name] then
table.insert(ret, contact)
end
names[contact.name] = true
end
return ret
end

114
main/tasks-menu.lua Normal file
View File

@@ -0,0 +1,114 @@
-- name = "Notes & tasks menu"
-- name_id = "notes"
-- description = "Shows tasks in the side menu"
-- type = "drawer"
-- aio_version = "4.7.99"
-- author = "Evgeny Zobnin"
-- version = "1.0"
local fmt = require "fmt"
local prefs = require "prefs"
local primary_color = aio:colors().primary_color
local secondary_color = aio:colors().secondary_color
local bottom_buttons = {
"fa:note_sticky", -- notes tab
"fa:list-check", -- tasks tab
"fa:pipe", -- separator
"fa:note_medical", -- new note button
"fa:square_plus" -- new task button
}
local notes_list = {}
local tasks_list = {}
if prefs.curr_tab == nil then
prefs.curr_tab = 1
end
function on_drawer_open()
drawer:add_buttons(bottom_buttons, prefs.curr_tab)
if prefs.curr_tab == 1 then
notes:load()
else
tasks:load()
end
end
function on_tasks_loaded(new_tasks)
tasks_list = new_tasks
local texts = map(tasks_list, task_to_text)
drawer:show_ext_list(texts)
end
function on_notes_loaded(new_notes)
notes_list = new_notes
local texts = map(notes_list, note_to_text)
drawer:show_ext_list(texts)
end
function note_to_text(it)
if it.text == "test note" then
test_note = it
end
if it.color ~= 6 then
return fmt.colored(it.text, notes:colors()[it.color])
else
return it.text
end
end
function task_to_text(it)
local text = ""
local date_str = os.date("%b, %d, %H:%M", it.due_date)
if it.completed_date > 0 then
text = fmt.strike(it.text)
elseif it.due_date < os.time() then
text = fmt.bold(fmt.red(it.text))
elseif it.is_today then
text = fmt.bold(it.text)
else
text = it.text
end
return text.."<br/>"..fmt.space(4)..fmt.small(date_str)
end
function on_click(idx)
if prefs.curr_tab == 1 then
on_note_click(idx)
else
on_task_click(idx)
end
end
function on_note_click(idx)
notes:show_editor(notes_list[idx].id)
end
function on_task_click(idx)
tasks:show_editor(tasks_list[idx].id)
end
function on_button_click(idx)
if idx < 3 then
prefs.curr_tab = idx
on_drawer_open()
elseif idx == 4 then
notes:show_editor()
elseif idx == 5 then
tasks:show_editor()
end
end
function map(tbl, f)
local ret = {}
for k,v in pairs(tbl) do
ret[k] = f(v)
end
return ret
end