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

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