diff --git a/community/actions-menu.lua b/community/actions-menu.lua new file mode 100644 index 0000000..70467a4 --- /dev/null +++ b/community/actions-menu.lua @@ -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 diff --git a/main/calendar-menu.lua b/main/calendar-menu.lua new file mode 100644 index 0000000..4fb20da --- /dev/null +++ b/main/calendar-menu.lua @@ -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 + diff --git a/main/contacts-menu.lua b/main/contacts-menu.lua new file mode 100644 index 0000000..37e44cd --- /dev/null +++ b/main/contacts-menu.lua @@ -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 diff --git a/main/tasks-menu.lua b/main/tasks-menu.lua new file mode 100644 index 0000000..934a49c --- /dev/null +++ b/main/tasks-menu.lua @@ -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.."
"..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 diff --git a/samples/bad-script.lua b/samples/bad-script.lua index 85cde84..3e8c031 100644 --- a/samples/bad-script.lua +++ b/samples/bad-script.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() ui:show_text("Click to freeze launcher") end diff --git a/samples/bad-script0.lua b/samples/bad-script0.lua index d2bfdf2..9cc626f 100644 --- a/samples/bad-script0.lua +++ b/samples/bad-script0.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() while true do end diff --git a/samples/bad-script2.lua b/samples/bad-script2.lua index e38da0e..08f8214 100644 --- a/samples/bad-script2.lua +++ b/samples/bad-script2.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() while true do ui:show_text("Haha") diff --git a/samples/bad-script3.lua b/samples/bad-script3.lua index 102216e..a079711 100644 --- a/samples/bad-script3.lua +++ b/samples/bad-script3.lua @@ -1,2 +1,4 @@ +-- testing = "true" + ui:show_toast("Hello") diff --git a/samples/bad-script4.lua b/samples/bad-script4.lua index bb7bf92..1d01d92 100644 --- a/samples/bad-script4.lua +++ b/samples/bad-script4.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_tick() while true do ui:show_text("bad") diff --git a/samples/bad-script5.lua b/samples/bad-script5.lua index c9ca73c..8a7044b 100644 --- a/samples/bad-script5.lua +++ b/samples/bad-script5.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() ui:show_aaa() end diff --git a/samples/bad-script6.lua b/samples/bad-script6.lua index 4d7a22f..4c5ec50 100644 --- a/samples/bad-script6.lua +++ b/samples/bad-script6.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() ui:show_text("Tap to halt") end diff --git a/samples/bad-script7.lua b/samples/bad-script7.lua index 97906ed..8c05c52 100644 --- a/samples/bad-script7.lua +++ b/samples/bad-script7.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() package.path = ";;" end diff --git a/samples/bad-script8.lua b/samples/bad-script8.lua index d775744..f04a31f 100644 --- a/samples/bad-script8.lua +++ b/samples/bad-script8.lua @@ -1,3 +1,5 @@ +-- testing = "true" + function on_resume() for i = 1, 15 do system:copy_to_clipboard("aaa") diff --git a/samples/calendar-sample.lua b/samples/calendar-sample.lua index 546c68c..5a66d9a 100644 --- a/samples/calendar-sample.lua +++ b/samples/calendar-sample.lua @@ -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 diff --git a/samples/calendar-sample3.lua b/samples/calendar-sample3.lua new file mode 100644 index 0000000..3f4bc16 --- /dev/null +++ b/samples/calendar-sample3.lua @@ -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 diff --git a/samples/drawer-sample.lua b/samples/drawer-sample.lua new file mode 100644 index 0000000..96c3e10 --- /dev/null +++ b/samples/drawer-sample.lua @@ -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 diff --git a/samples/drawer-sample3.lua b/samples/drawer-sample3.lua new file mode 100644 index 0000000..30083ee --- /dev/null +++ b/samples/drawer-sample3.lua @@ -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 diff --git a/samples/drawer-sample4.lua b/samples/drawer-sample4.lua new file mode 100644 index 0000000..7cdc30a --- /dev/null +++ b/samples/drawer-sample4.lua @@ -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 + diff --git a/samples/drawer-test.lua b/samples/drawer-test.lua new file mode 100644 index 0000000..f9668d7 --- /dev/null +++ b/samples/drawer-test.lua @@ -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 diff --git a/samples/notes-tests.lua b/samples/notes-tests.lua new file mode 100644 index 0000000..7e7ee9f --- /dev/null +++ b/samples/notes-tests.lua @@ -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 diff --git a/samples/search-widget.lua b/samples/search-widget.lua new file mode 100644 index 0000000..8ed9c6d --- /dev/null +++ b/samples/search-widget.lua @@ -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 diff --git a/samples/tasks-tests.lua b/samples/tasks-tests.lua new file mode 100644 index 0000000..7b2290f --- /dev/null +++ b/samples/tasks-tests.lua @@ -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