Add new drawer scripts
This commit is contained in:
26
community/actions-menu.lua
Normal file
26
community/actions-menu.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
-- name = "Actions menu"
|
||||
-- name_id = "actions"
|
||||
-- description = "Shows aio launcher actions"
|
||||
-- type = "drawer"
|
||||
-- aio_version = "4.7.99"
|
||||
-- author = "Evgeny Zobnin"
|
||||
-- version = "1.0"
|
||||
|
||||
function on_drawer_open()
|
||||
actions = aio:actions()
|
||||
labels = map(actions, function(it) return it.label end)
|
||||
drawer:show_list(labels)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
aio:do_action(actions[idx].name)
|
||||
drawer:close()
|
||||
end
|
||||
|
||||
function map(tbl, f)
|
||||
local ret = {}
|
||||
for k,v in pairs(tbl) do
|
||||
ret[k] = f(v)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
39
main/calendar-menu.lua
Normal file
39
main/calendar-menu.lua
Normal 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
51
main/contacts-menu.lua
Normal 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
114
main/tasks-menu.lua
Normal 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
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
ui:show_text("Click to freeze launcher")
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
while true do
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
while true do
|
||||
ui:show_text("Haha")
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
-- testing = "true"
|
||||
|
||||
ui:show_toast("Hello")
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_tick()
|
||||
while true do
|
||||
ui:show_text("bad")
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
ui:show_aaa()
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
ui:show_text("Tap to halt")
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
package.path = ";;"
|
||||
end
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
-- testing = "true"
|
||||
|
||||
function on_resume()
|
||||
for i = 1, 15 do
|
||||
system:copy_to_clipboard("aaa")
|
||||
|
||||
@@ -13,5 +13,5 @@ function on_resume()
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
calendar:show_event_dialog(events[idx].id)
|
||||
calendar:show_event_dialog(events[idx])
|
||||
end
|
||||
|
||||
7
samples/calendar-sample3.lua
Normal file
7
samples/calendar-sample3.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
function on_resume()
|
||||
ui:show_text("Tap to create new event")
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
calendar:open_new_event(os.time(), os.time() + 3600)
|
||||
end
|
||||
46
samples/drawer-sample.lua
Normal file
46
samples/drawer-sample.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
-- name = "Drawer Sample"
|
||||
-- type = "drawer"
|
||||
-- testing = "true"
|
||||
|
||||
local fmt = require "fmt"
|
||||
local list = {}
|
||||
local cur_tab = 1
|
||||
|
||||
function on_drawer_open()
|
||||
if cur_tab == 1 then
|
||||
show_list1()
|
||||
else
|
||||
show_list2()
|
||||
end
|
||||
|
||||
drawer:add_buttons({"fa:circle-1", "fa:circle-2"}, cur_tab)
|
||||
end
|
||||
|
||||
function show_list1()
|
||||
list = { "First line", fmt.bold("Second line"), fmt.red("Third line") }
|
||||
-- optional
|
||||
local icons = { "fa:circle-1", "fa:circle-2", "fa:circle-3" }
|
||||
-- optional
|
||||
local badges = { "Wow", "New", "11" }
|
||||
|
||||
drawer:show_list(list, icons, badges)
|
||||
end
|
||||
|
||||
function show_list2()
|
||||
list = {
|
||||
"You can display long text as side-menu items.",
|
||||
"This can be used, for example, to display a list of messages.",
|
||||
"Even if you don't use this output method, I think it's cool.",
|
||||
}
|
||||
|
||||
drawer:show_ext_list(list)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
debug:toast(list[idx].." clicked")
|
||||
end
|
||||
|
||||
function on_button_click(idx)
|
||||
cur_tab = idx
|
||||
on_drawer_open()
|
||||
end
|
||||
25
samples/drawer-sample3.lua
Normal file
25
samples/drawer-sample3.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
-- name = "Drawer Sample #3"
|
||||
-- type = "drawer"
|
||||
-- testing = "true"
|
||||
|
||||
local list = {
|
||||
"abc",
|
||||
"launch_count",
|
||||
"launch_time",
|
||||
"install_time",
|
||||
"appbox",
|
||||
"categories",
|
||||
"close",
|
||||
}
|
||||
|
||||
function on_drawer_open()
|
||||
drawer:show_list(list)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if list[idx] == "close" then
|
||||
drawer:close()
|
||||
else
|
||||
drawer:change_view(list[idx])
|
||||
end
|
||||
end
|
||||
26
samples/drawer-sample4.lua
Normal file
26
samples/drawer-sample4.lua
Normal file
@@ -0,0 +1,26 @@
|
||||
-- name = "Drawer sample #4"
|
||||
-- type = "drawer"
|
||||
-- testing = "true"
|
||||
|
||||
function on_drawer_open()
|
||||
pkgs = apps:list()
|
||||
apps:request_icons(pkgs)
|
||||
end
|
||||
|
||||
function on_icons_ready(icons)
|
||||
names = map(pkgs, function(it) return apps:name(it) end)
|
||||
drawer:show_list(names, icons, nil, true)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
apps:launch(pkgs[idx])
|
||||
end
|
||||
|
||||
function map(tbl, f)
|
||||
local ret = {}
|
||||
for k,v in pairs(tbl) do
|
||||
ret[k] = f(v)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
8
samples/drawer-test.lua
Normal file
8
samples/drawer-test.lua
Normal file
@@ -0,0 +1,8 @@
|
||||
-- name = "Drawer test"
|
||||
-- type = "drawer"
|
||||
-- testing = "true"
|
||||
|
||||
function on_drawer_open()
|
||||
drawer:show_list{ "Empty" }
|
||||
debug:toast("on_drawer_open() called!")
|
||||
end
|
||||
73
samples/notes-tests.lua
Normal file
73
samples/notes-tests.lua
Normal file
@@ -0,0 +1,73 @@
|
||||
-- name = "Notes tests"
|
||||
-- type = "drawer"
|
||||
-- aio_version = "4.7.99"
|
||||
-- author = "Evgeny Zobnin"
|
||||
-- version = "1.0"
|
||||
-- testing = "true"
|
||||
|
||||
local fmt = require "fmt"
|
||||
local notes_list = {}
|
||||
local test_note = {}
|
||||
|
||||
function on_drawer_open()
|
||||
refresh()
|
||||
end
|
||||
|
||||
function refresh()
|
||||
notes:load()
|
||||
end
|
||||
|
||||
function on_notes_loaded(new_notes)
|
||||
notes_list = new_notes
|
||||
local texts = map(notes_list, note_to_text)
|
||||
table.insert(texts, fmt.italic("Show new note dialog"))
|
||||
table.insert(texts, fmt.italic("Add test note"))
|
||||
table.insert(texts, fmt.italic("Change test note"))
|
||||
drawer:show_ext_list(texts)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == #notes_list+1 then
|
||||
notes:show_editor()
|
||||
drawer:close()
|
||||
elseif idx == #notes_list+2 then
|
||||
notes:add{text = "test note"}
|
||||
refresh()
|
||||
elseif idx == #notes_list+3 then
|
||||
test_note.text = "test note (changed)"
|
||||
test_note.color = 1
|
||||
test_note.position = test_note.position-3
|
||||
notes:save(test_note)
|
||||
refresh()
|
||||
else
|
||||
notes:show_editor(notes_list[idx].id)
|
||||
drawer:close()
|
||||
end
|
||||
end
|
||||
|
||||
function on_long_click(idx)
|
||||
if idx <= #notes_list then
|
||||
notes:remove(notes_list[idx].id)
|
||||
refresh()
|
||||
end
|
||||
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 map(tbl, f)
|
||||
local ret = {}
|
||||
for k,v in pairs(tbl) do
|
||||
ret[k] = f(v)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
13
samples/search-widget.lua
Normal file
13
samples/search-widget.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
-- name = "Search"
|
||||
-- description = "Simple widget to open search screen"
|
||||
-- type = "widget"
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- version = "1.0"
|
||||
|
||||
function on_resume()
|
||||
ui:show_text("Open search")
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
aio:do_action("search")
|
||||
end
|
||||
73
samples/tasks-tests.lua
Normal file
73
samples/tasks-tests.lua
Normal file
@@ -0,0 +1,73 @@
|
||||
-- name = "Tasks tests"
|
||||
-- type = "drawer"
|
||||
-- aio_version = "4.7.99"
|
||||
-- author = "Evgeny Zobnin"
|
||||
-- version = "1.0"
|
||||
-- testing = "true"
|
||||
|
||||
local fmt = require "fmt"
|
||||
local tasks_list = {}
|
||||
local test_task = {}
|
||||
|
||||
function on_drawer_open()
|
||||
refresh()
|
||||
end
|
||||
|
||||
function refresh()
|
||||
tasks:load()
|
||||
end
|
||||
|
||||
function on_tasks_loaded(new_tasks)
|
||||
tasks_list = new_tasks
|
||||
local texts = map(tasks_list, task_to_text)
|
||||
table.insert(texts, fmt.italic("Show new task dialog"))
|
||||
table.insert(texts, fmt.italic("Add test task"))
|
||||
table.insert(texts, fmt.italic("Change test task"))
|
||||
drawer:show_ext_list(texts)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == #tasks_list+1 then
|
||||
tasks:show_editor()
|
||||
elseif idx == #tasks_list+2 then
|
||||
tasks:add{text = "test task"}
|
||||
refresh()
|
||||
elseif idx == #tasks_list+3 then
|
||||
test_task.text = "test task (changed)"
|
||||
tasks:save(test_task)
|
||||
refresh()
|
||||
else
|
||||
tasks:show_editor(tasks_list[idx].id)
|
||||
end
|
||||
end
|
||||
|
||||
function on_long_click(idx)
|
||||
if idx <= #tasks_list then
|
||||
tasks:remove(tasks_list[idx].id)
|
||||
refresh()
|
||||
end
|
||||
end
|
||||
|
||||
function task_to_text(it)
|
||||
if it.text == "test task" then
|
||||
test_task = it
|
||||
end
|
||||
|
||||
if it.completed_date > 0 then
|
||||
return fmt.strike(it.text)
|
||||
elseif it.due_date < os.time() then
|
||||
return fmt.bold(fmt.red(it.text))
|
||||
elseif it.is_today then
|
||||
return fmt.bold(it.text)
|
||||
else
|
||||
return it.text
|
||||
end
|
||||
end
|
||||
|
||||
function map(tbl, f)
|
||||
local ret = {}
|
||||
for k,v in pairs(tbl) do
|
||||
ret[k] = f(v)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
Reference in New Issue
Block a user