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

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
ui:show_text("Click to freeze launcher")
end

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
while true do
end

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
while true do
ui:show_text("Haha")

View File

@@ -1,2 +1,4 @@
-- testing = "true"
ui:show_toast("Hello")

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_tick()
while true do
ui:show_text("bad")

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
ui:show_aaa()
end

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
ui:show_text("Tap to halt")
end

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
package.path = ";;"
end

View File

@@ -1,3 +1,5 @@
-- testing = "true"
function on_resume()
for i = 1, 15 do
system:copy_to_clipboard("aaa")

View File

@@ -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

View 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
View 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

View 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

View 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
View 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
View 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
View 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
View 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