Cleanup samples
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
all_apps = {}
|
all_apps = {}
|
||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
all_apps = apps:list("launch_count")
|
all_apps = apps:apps("launch_count")
|
||||||
|
|
||||||
if (next(all_apps) == nil) then
|
if (next(all_apps) == nil) then
|
||||||
ui:show_text("The list of apps is not ready yet")
|
ui:show_text("The list of apps is not ready yet")
|
||||||
@@ -18,14 +18,13 @@ function on_resume()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
--apps:launch(all_apps[idx])
|
apps:launch(all_apps[idx].pkg)
|
||||||
apps:show_edit_dialog(all_apps[idx])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- utils
|
-- utils
|
||||||
|
|
||||||
function get_formatted_name(pkg)
|
function get_formatted_name(app)
|
||||||
return "<font color=\""..apps:get_color(pkg).."\">"..apps:get_name(pkg).."</color>"
|
return "<font color=\""..app.color.."\">"..app.name.."</color>"
|
||||||
end
|
end
|
||||||
|
|
||||||
function table_to_tables(tab, num)
|
function table_to_tables(tab, num)
|
||||||
|
|||||||
@@ -1,360 +0,0 @@
|
|||||||
-- name = "My apps"
|
|
||||||
-- description = "Simple apps widget"
|
|
||||||
-- type = "widget"
|
|
||||||
-- version = "1.0"
|
|
||||||
-- author = "Andrey Gavrilov"
|
|
||||||
|
|
||||||
local utf8 = require "utf8"
|
|
||||||
local dialog_id = ""
|
|
||||||
local app_idx = 0
|
|
||||||
|
|
||||||
function on_resume()
|
|
||||||
update_args()
|
|
||||||
local folding = false
|
|
||||||
if settings:get_kv()["folding"] == "true" then
|
|
||||||
folding = true
|
|
||||||
end
|
|
||||||
ui:set_folding_flag(folding)
|
|
||||||
redraw()
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_alarm()
|
|
||||||
local args = settings:get_kv()
|
|
||||||
if next(args) == nil then
|
|
||||||
args["no_hidden"] = true
|
|
||||||
args["columns"] = 4
|
|
||||||
args["trim"] = 10
|
|
||||||
args["folding"] = false
|
|
||||||
args["1"] = "com.android.settings"
|
|
||||||
settings:set_kv(args)
|
|
||||||
redraw()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_settings()
|
|
||||||
dialog_id = "settings"
|
|
||||||
local tab = {"Applications list","No hidden setting","Columns number","Trim app name","Autofolding setting","Widget title"}
|
|
||||||
ui:show_radio_dialog("Settings",tab)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_dialog_action(data)
|
|
||||||
if data == -1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if dialog_id == "settings" then
|
|
||||||
if data == 1 then
|
|
||||||
dialog_id = "apps"
|
|
||||||
local tab = get_all_apps("abc",settings:get_kv()["no_hidden"])
|
|
||||||
ui:show_checkbox_dialog("Select apps",tab[2],args_to_idx(tab[1]))
|
|
||||||
return
|
|
||||||
elseif data == 2 then
|
|
||||||
dialog_id = "no_hidden"
|
|
||||||
local tab = {"Not show hidden applications"}
|
|
||||||
local tt = {}
|
|
||||||
if tostring(settings:get_kv()["no_hidden"]) == "true" then
|
|
||||||
tt = {1}
|
|
||||||
end
|
|
||||||
ui:show_checkbox_dialog("No hidden settings",tab,tt)
|
|
||||||
return
|
|
||||||
elseif data == 3 then
|
|
||||||
dialog_id = "columns"
|
|
||||||
ui:show_edit_dialog("Columns number","",settings:get_kv()["columns"])
|
|
||||||
return
|
|
||||||
elseif data == 4 then
|
|
||||||
dialog_id = "trim"
|
|
||||||
ui:show_edit_dialog("Trim app name","0 - not trim",settings:get_kv()["trim"])
|
|
||||||
return
|
|
||||||
elseif data == 5 then
|
|
||||||
dialog_id = "folding"
|
|
||||||
local tab = {"Autofolding"}
|
|
||||||
local tt = {}
|
|
||||||
if tostring(settings:get_kv()["folding"]) == "true" then
|
|
||||||
tt = {1}
|
|
||||||
end
|
|
||||||
ui:show_checkbox_dialog("Autofolding settings",tab,tt)
|
|
||||||
return
|
|
||||||
elseif data == 6 then
|
|
||||||
dialog_id = "name"
|
|
||||||
ui:show_edit_dialog("Set widget title","Empty - default title",ui:get_default_title())
|
|
||||||
return
|
|
||||||
end
|
|
||||||
elseif dialog_id == "no_hidden" then
|
|
||||||
local args = settings:get_kv()
|
|
||||||
if next(data) == nil then
|
|
||||||
args["no_hidden"] = false
|
|
||||||
else
|
|
||||||
args["no_hidden"] = true
|
|
||||||
end
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
elseif dialog_id == "apps" then
|
|
||||||
settings:set_kv(idx_to_args(data))
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
elseif dialog_id == "columns" then
|
|
||||||
if data == tostring(tonumber(data)) then
|
|
||||||
if tonumber(data) == 0 then
|
|
||||||
data = "1"
|
|
||||||
end
|
|
||||||
local args = settings:get_kv()
|
|
||||||
args["columns"] = math.floor(tonumber(data))
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif dialog_id == "trim" then
|
|
||||||
if data == tostring(tonumber(data)) then
|
|
||||||
local args = settings:get_kv()
|
|
||||||
args["trim"] = math.floor(tonumber(data))
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
end
|
|
||||||
return
|
|
||||||
elseif dialog_id == "folding" then
|
|
||||||
local args = settings:get_kv()
|
|
||||||
if next(data) == nil then
|
|
||||||
args["folding"] = false
|
|
||||||
else
|
|
||||||
args["folding"] = true
|
|
||||||
end
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
elseif dialog_id == "name" then
|
|
||||||
local title = ui:get_default_title()
|
|
||||||
if data ~= "" then
|
|
||||||
title = data
|
|
||||||
end
|
|
||||||
ui:set_title(title)
|
|
||||||
return
|
|
||||||
elseif dialog_id == "move" then
|
|
||||||
if data == tostring(tonumber(data)) then
|
|
||||||
local idx = math.floor(tonumber(data))
|
|
||||||
local args = settings:get_kv()
|
|
||||||
if idx < 1 then
|
|
||||||
idx = 1
|
|
||||||
elseif idx > max_key(args) then
|
|
||||||
idx = max_key(args)
|
|
||||||
end
|
|
||||||
local from = args[tostring(app_idx)]
|
|
||||||
local to = args[tostring(idx)]
|
|
||||||
args[tostring(app_idx)] = to
|
|
||||||
args[tostring(idx)] = from
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_context_menu_click(idx)
|
|
||||||
if idx == 4 then
|
|
||||||
apps:show_edit_dialog(settings:get_kv()[tostring(app_idx)])
|
|
||||||
elseif idx == 1 then
|
|
||||||
local args = settings:get_kv()
|
|
||||||
if app_idx == max_key(args) then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local from = args[tostring(app_idx)]
|
|
||||||
local to = args[tostring(app_idx+1)]
|
|
||||||
args[tostring(app_idx)] = to
|
|
||||||
args[tostring(app_idx+1)] = from
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
elseif idx == 3 then
|
|
||||||
local args = settings:get_kv()
|
|
||||||
if app_idx == 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local from = args[tostring(app_idx)]
|
|
||||||
local to = args[tostring(app_idx-1)]
|
|
||||||
args[tostring(app_idx)] = to
|
|
||||||
args[tostring(app_idx-1)] = from
|
|
||||||
settings:set_kv(args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
elseif idx == 2 then
|
|
||||||
local args = settings:get_kv()
|
|
||||||
local new_args = {}
|
|
||||||
for k,v in pairs(args) do
|
|
||||||
if k ~= tostring(app_idx) then
|
|
||||||
new_args[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
settings:set_kv(new_args)
|
|
||||||
update_args()
|
|
||||||
redraw()
|
|
||||||
return
|
|
||||||
elseif idx == 5 then
|
|
||||||
dialog_id = "move"
|
|
||||||
local text = "Number from 1 to "..tostring(max_key(settings:get_kv()))
|
|
||||||
ui:show_edit_dialog("Set position",text,app_idx)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function redraw()
|
|
||||||
local cols = tonumber(settings:get_kv()["columns"])
|
|
||||||
if cols == 0 or cols == nil then
|
|
||||||
cols = 1
|
|
||||||
end
|
|
||||||
ui:show_table(table_to_tables(tab_from_args(), cols))
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_click(idx)
|
|
||||||
apps:launch(settings:get_kv()[tostring(idx)])
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_long_click(idx)
|
|
||||||
app_idx = idx
|
|
||||||
ui:show_context_menu({
|
|
||||||
{ "chevron-right", "Forward" },
|
|
||||||
{ "times", "Remove" },
|
|
||||||
{ "chevron-left", "Back" },
|
|
||||||
{ "edit", "Edit" },
|
|
||||||
{ "exchange", "Move" }
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function tab_from_args()
|
|
||||||
local args = settings:get_kv()
|
|
||||||
local len = tonumber(args["trim"])
|
|
||||||
if len == nil then
|
|
||||||
len = 0
|
|
||||||
end
|
|
||||||
local tab = {}
|
|
||||||
for k,v in pairs(args) do
|
|
||||||
if k == tostring(tonumber(k)) then
|
|
||||||
tab[tonumber(k)] = get_formatted_name(v,len)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return tab
|
|
||||||
end
|
|
||||||
|
|
||||||
function get_formatted_name(pkg,len)
|
|
||||||
local str = apps:get_name(pkg)
|
|
||||||
if utf8.len(str) > len and len > 0 then
|
|
||||||
str = utf8.sub(str,1,len-1):gsub("[%. ]*$","").."."
|
|
||||||
end
|
|
||||||
return "<font color=\""..apps:get_color(pkg).."\">"..str.."</font>"
|
|
||||||
end
|
|
||||||
|
|
||||||
function table_to_tables(tab, num)
|
|
||||||
local out_tab = {}
|
|
||||||
local row = {}
|
|
||||||
|
|
||||||
for k,v in ipairs(tab) do
|
|
||||||
table.insert(row, v)
|
|
||||||
if k % num == 0 then
|
|
||||||
table.insert(out_tab, row)
|
|
||||||
row = {}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if row ~= {} then
|
|
||||||
table.insert(out_tab, row)
|
|
||||||
end
|
|
||||||
return out_tab
|
|
||||||
end
|
|
||||||
|
|
||||||
function get_all_apps(sort_by,no_hidden)
|
|
||||||
if tostring(no_hidden) == "true" then
|
|
||||||
no_hidden = true
|
|
||||||
else
|
|
||||||
no_hidden = false
|
|
||||||
end
|
|
||||||
local t = settings:get_kv()
|
|
||||||
local all_apps = apps:get_list(sort_by,no_hidden)
|
|
||||||
local apps_names = {}
|
|
||||||
for k,v in ipairs(all_apps) do
|
|
||||||
apps_names[k] = apps:get_name(v)
|
|
||||||
end
|
|
||||||
return {all_apps,apps_names}
|
|
||||||
end
|
|
||||||
|
|
||||||
function args_to_idx(tab)
|
|
||||||
local args = settings:get_kv()
|
|
||||||
local t = {}
|
|
||||||
for k,v in pairs(args) do
|
|
||||||
local idx = get_index(tab,v)
|
|
||||||
if idx > 0 then
|
|
||||||
table.insert(t,idx)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return t
|
|
||||||
end
|
|
||||||
|
|
||||||
function idx_to_args(tab)
|
|
||||||
local args = settings:get_kv()
|
|
||||||
local all_apps = get_all_apps("abc",args["no_hidden"])[1]
|
|
||||||
local new_args = {}
|
|
||||||
for i,v in ipairs(tab) do
|
|
||||||
if get_key(args,all_apps[tonumber(v)]) == 0 then
|
|
||||||
new_args[tostring(max_key(args)+i)] = all_apps[tonumber(v)]
|
|
||||||
else
|
|
||||||
new_args[get_key(args,all_apps[tonumber(v)])] = all_apps[tonumber(v)]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
new_args = sort_by_key(new_args)
|
|
||||||
new_args["no_hidden"] = args["no_hidden"]
|
|
||||||
new_args["columns"] = args["columns"]
|
|
||||||
new_args["trim"] = args["trim"]
|
|
||||||
new_args["folding"] = args["folding"]
|
|
||||||
return new_args
|
|
||||||
end
|
|
||||||
|
|
||||||
function update_args()
|
|
||||||
local args = settings:get_kv()
|
|
||||||
local all_apps = get_all_apps("abc",args["no_hidden"])[1]
|
|
||||||
local new_args = {}
|
|
||||||
for k,v in pairs(args) do
|
|
||||||
if k == tostring(tonumber(k)) then
|
|
||||||
if get_index(all_apps,v) ~= 0 then
|
|
||||||
new_args[k] = v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
new_args = sort_by_key(new_args)
|
|
||||||
new_args["no_hidden"] = args["no_hidden"]
|
|
||||||
new_args["columns"] = args["columns"]
|
|
||||||
new_args["trim"] = args["trim"]
|
|
||||||
new_args["folding"] = args["folding"]
|
|
||||||
settings:set_kv(new_args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function sort_by_key(tab)
|
|
||||||
local t = {}
|
|
||||||
local tt = {}
|
|
||||||
for k,v in pairs(tab) do
|
|
||||||
table.insert(t,tonumber(k))
|
|
||||||
end
|
|
||||||
table.sort(t)
|
|
||||||
for i,v in ipairs(t) do
|
|
||||||
for kk,vv in pairs(tab) do
|
|
||||||
if kk == tostring(v) then
|
|
||||||
tt[tostring(i)] = vv
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return tt
|
|
||||||
end
|
|
||||||
|
|
||||||
function max_key(tab)
|
|
||||||
local t = {}
|
|
||||||
for k,v in pairs(tab) do
|
|
||||||
if k == tostring(tonumber(k)) then
|
|
||||||
table.insert(t,k)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
table.sort(t)
|
|
||||||
return #t
|
|
||||||
end
|
|
||||||
@@ -6,6 +6,6 @@ end
|
|||||||
|
|
||||||
function on_click()
|
function on_click()
|
||||||
while true do
|
while true do
|
||||||
system:copy_to_clipboard("http://google.com")
|
system:to_clipboard("http://google.com")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
for i = 1, 15 do
|
for i = 1, 15 do
|
||||||
system:copy_to_clipboard("aaa")
|
system:to_clipboard("aaa")
|
||||||
ui:show_text(i)
|
ui:show_text(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -11,6 +11,6 @@ function on_alarm()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_network_result(result)
|
function on_network_result(result)
|
||||||
local price = ajson:get_value(result, "object object:USD string:last")
|
local price = ajson:read(result, "object object:USD string:last")
|
||||||
ui:show_text("1 BTC"..equals..price.." USD")
|
ui:show_text("1 BTC"..equals..price.." USD")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
function on_alarm()
|
function on_alarm()
|
||||||
ui:show_text("Введите выражение")
|
ui:show_text("Enter an expression")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click()
|
function on_click()
|
||||||
ui:show_edit_dialog("Введите выражение")
|
ui:show_edit_dialog("Enter an expression")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_dialog_action(text)
|
function on_dialog_action(text)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ events = {}
|
|||||||
function on_resume()
|
function on_resume()
|
||||||
local ev_titles = {}
|
local ev_titles = {}
|
||||||
|
|
||||||
events = slice(calendar:get_events(), 1, 10)
|
events = slice(calendar:events(), 1, 10)
|
||||||
|
|
||||||
for k,v in ipairs(events) do
|
for k,v in ipairs(events) do
|
||||||
ev_titles[k] = v.title
|
ev_titles[k] = v.title
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
-- version = "1.0"
|
-- version = "1.0"
|
||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
local clipboard = system:get_from_clipboard()
|
local clipboard = system:clipboard()
|
||||||
ui:show_text(clipboard)
|
ui:show_text(clipboard)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ function on_resume()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function on_click()
|
function on_click()
|
||||||
system:copy_to_clipboard("test", true)
|
system:to_clipboard("test", true)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
function on_resume()
|
function on_resume()
|
||||||
local colors = ui:get_colors()
|
local colors = aio:colors()
|
||||||
local colors_strings = stringify_table(colors)
|
local colors_strings = stringify_table(colors)
|
||||||
|
|
||||||
ui:show_lines(colors_strings)
|
ui:show_lines(colors_strings)
|
||||||
|
|||||||
@@ -3,33 +3,30 @@
|
|||||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||||
-- version = "1.0"
|
-- version = "1.0"
|
||||||
|
|
||||||
local first_launch = true
|
|
||||||
|
|
||||||
local no_tab = {}
|
local no_tab = {}
|
||||||
local messages_tab = {}
|
local messages_tab = {}
|
||||||
local keys_tab = {}
|
local keys_tab = {}
|
||||||
local folded_string = ""
|
local folded_string = ""
|
||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
-- AIO Launcher will call get_current automatically on resume
|
update_notifications()
|
||||||
if (first_launch) then
|
end
|
||||||
first_launch = false
|
|
||||||
notify:get_current()
|
function on_notifications_updated()
|
||||||
|
update_notifications()
|
||||||
|
end
|
||||||
|
|
||||||
|
function update_notifications()
|
||||||
|
no_tab = {}
|
||||||
|
local notifications = notify:list()
|
||||||
|
|
||||||
|
for _, n in pairs(notifications) do
|
||||||
|
-- Skip not clearable and non messenger notifications
|
||||||
|
if (n.is_clearable == true and table_size(n.messages) > 0) then
|
||||||
|
no_tab[n.key] = n
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
function on_notify_posted(n)
|
|
||||||
-- Skip not clearable and non messenger notifications
|
|
||||||
if (n.is_clearable == false) then return end
|
|
||||||
if (table_size(n.messages) == 0) then return end
|
|
||||||
|
|
||||||
notify:consumed(n.key)
|
|
||||||
no_tab[n.key] = n
|
|
||||||
redraw()
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_notify_removed(n)
|
|
||||||
no_tab[n.key] = nil
|
|
||||||
redraw()
|
redraw()
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -39,10 +36,10 @@ end
|
|||||||
|
|
||||||
function redraw()
|
function redraw()
|
||||||
if (table_size(no_tab) == 0) then
|
if (table_size(no_tab) == 0) then
|
||||||
aio:hide_widget()
|
ui:hide_widget()
|
||||||
ui:show_text("Empty")
|
ui:show_text("Empty")
|
||||||
else
|
else
|
||||||
aio:show_widget()
|
ui:show_widget()
|
||||||
draw_ui()
|
draw_ui()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
-- name = "Currencies"
|
|
||||||
-- description = "Currency rates widget. Click on the date to change it."
|
|
||||||
-- data_source = "github.com/fawazahmed0/currency-api#readme"
|
|
||||||
-- type = "widget"
|
|
||||||
-- author = "Andrey Gavrilov"
|
|
||||||
-- version = "1.0"
|
|
||||||
-- arguments_help = "Enter the list of currency pairs in the format usd:rub btc:usd"
|
|
||||||
-- arguments_default = "usd:rub eur:rub"
|
|
||||||
|
|
||||||
json = require "json"
|
|
||||||
|
|
||||||
-- constants
|
|
||||||
local red_color = "#f44336"
|
|
||||||
local green_color = "#48ad47"
|
|
||||||
local text_color = ui:get_colors().secondary_text
|
|
||||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
|
||||||
|
|
||||||
-- global vars
|
|
||||||
local result_curr = ""
|
|
||||||
local tabl = {}
|
|
||||||
|
|
||||||
function on_resume()
|
|
||||||
ui:set_folding_flag(true)
|
|
||||||
ui:show_lines(tabl)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_alarm()
|
|
||||||
get_rates("latest", "curr")
|
|
||||||
end
|
|
||||||
|
|
||||||
function get_rates(loc_date,id)
|
|
||||||
http:get("https://cdn.jsdelivr.net/gh/fawazahmed0/currency-api@1/"..loc_date.."/currencies/usd.json",id)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_network_result_curr(result)
|
|
||||||
result_curr = result
|
|
||||||
|
|
||||||
local t = json.decode(result)
|
|
||||||
local dat = t.date
|
|
||||||
local prev_date = prev_date(dat)
|
|
||||||
|
|
||||||
get_rates(prev_date, "prev")
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_network_result_prev(result)
|
|
||||||
tabl = create_tab(result)
|
|
||||||
ui:show_lines(tabl)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_click(idx)
|
|
||||||
ui:show_edit_dialog("Enter the date", "Enter the date in the format 2020.12.31. A blank value is the current date.")
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_dialog_action(dat)
|
|
||||||
if dat == "" then dat = "latest" end
|
|
||||||
get_rates(dat:gsub(".", "-"), "curr")
|
|
||||||
end
|
|
||||||
|
|
||||||
function prev_date(dat)
|
|
||||||
local prev_date = dat:split("-")
|
|
||||||
local prev_time = os.time{year=prev_date[1], month=prev_date[2], day=prev_date[3]} - (60*60*24)
|
|
||||||
return os.date("%Y-%m-%d", prev_time)
|
|
||||||
end
|
|
||||||
|
|
||||||
function create_tab(result)
|
|
||||||
local curs = settings:get()
|
|
||||||
local tab = {}
|
|
||||||
local t_c = json.decode(result_curr)
|
|
||||||
local t_p = json.decode(result)
|
|
||||||
|
|
||||||
-- set title
|
|
||||||
local dat = t_c.date
|
|
||||||
ui:set_title(ui:get_default_title().." "..dat:gsub("-", "."))
|
|
||||||
|
|
||||||
for idx = 1, #curs, 1 do
|
|
||||||
local cur = curs[idx]:split(":")
|
|
||||||
|
|
||||||
local rate_curr1 = t_c.usd[cur[1]]
|
|
||||||
local rate_curr2 = t_c.usd[cur[2]]
|
|
||||||
local rate_prev1 = t_p.usd[cur[1]]
|
|
||||||
local rate_prev2 = t_p.usd[cur[2]]
|
|
||||||
|
|
||||||
local rate_curr = round(rate_curr2/rate_curr1, 4)
|
|
||||||
local rate_prev = round(rate_prev2/rate_prev1, 4)
|
|
||||||
local change = round((rate_curr-rate_prev)/rate_prev*100,2)
|
|
||||||
|
|
||||||
local line = "1 "..string.upper(cur[1])..equals..rate_curr.." "..string.upper(cur[2])
|
|
||||||
line = line..get_formatted_change_text(change)
|
|
||||||
|
|
||||||
table.insert(tab, line)
|
|
||||||
end
|
|
||||||
return tab
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_settings()
|
|
||||||
settings:show_dialog()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- utils --
|
|
||||||
|
|
||||||
function get_formatted_change_text(change)
|
|
||||||
if change > 0 then
|
|
||||||
return "<font color=\""..green_color.."\"><small> +"..change.."%</small></font>"
|
|
||||||
elseif change < 0 then
|
|
||||||
return "<font color=\""..red_color.."\"><small> "..change.."%</small></font>"
|
|
||||||
else
|
|
||||||
return "<font color=\""..text_color.."\"><small> "..change.."%</small></font>"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
-- name = "Exchange rates"
|
|
||||||
-- description = "Shows currency rate by code"
|
|
||||||
-- data_source = "https://api.exchangerate.host"
|
|
||||||
-- type = "search"
|
|
||||||
-- author = "Evgeny Zobbin & Andrey Gavrilov"
|
|
||||||
-- version = "1.0"
|
|
||||||
|
|
||||||
-- modules
|
|
||||||
local json = require "json"
|
|
||||||
local md_color = require "md_colors"
|
|
||||||
|
|
||||||
-- constants
|
|
||||||
local host = "https://api.exchangerate.host"
|
|
||||||
local red = md_colors.red_500
|
|
||||||
local base_currency = system:get_currency()
|
|
||||||
|
|
||||||
-- variables
|
|
||||||
local req_currency = ""
|
|
||||||
local req_amount = 1
|
|
||||||
local result = 0
|
|
||||||
|
|
||||||
function on_search(inp)
|
|
||||||
req_currency = ""
|
|
||||||
req_amount = 1
|
|
||||||
result = 0
|
|
||||||
|
|
||||||
local a,c = inp:match("^(%d*)%s?(%a%a%a)$")
|
|
||||||
if c == nil then return end
|
|
||||||
|
|
||||||
req_currency = c:upper()
|
|
||||||
|
|
||||||
if get_index(supported, req_currency) == 0 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if a ~= "" then
|
|
||||||
req_amount = a
|
|
||||||
end
|
|
||||||
|
|
||||||
search:show({"Exchange rate for "..req_amount.." "..req_currency},{red})
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_click()
|
|
||||||
if result == 0 then
|
|
||||||
http:get(host.."/convert?from="..req_currency.."&to="..base_currency.."&amount="..req_amount)
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
system:copy_to_clipboard(result)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_long_click()
|
|
||||||
system:copy_to_clipboard(result)
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_network_result(res)
|
|
||||||
local tab = json.decode(res)
|
|
||||||
|
|
||||||
if tab.success then
|
|
||||||
search:show({tab.query.amount.." "..tab.query.from.." = "..tab.result.." "..tab.query.to}, {red})
|
|
||||||
else
|
|
||||||
search:show({"No data"},{red})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- curl -s -XGET 'https://api.exchangerate.host/symbols?format=csv' | cut -d ',' -f 2 | grep -v code | sed 's/$/,/' | tr '\n' ' '
|
|
||||||
supported = {
|
|
||||||
"AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS", "AUD", "AWG", "AZN", "BAM", "BBD", "BDT", "BGN", "BHD", "BIF", "BMD", "BND", "BOB", "BRL", "BSD", "BTC", "BTN", "BWP", "BYN", "BZD", "CAD", "CDF", "CHF", "CLF", "CLP", "CNH", "CNY", "COP", "CRC", "CUC", "CUP", "CVE", "CZK", "DJF", "DKK", "DOP", "DZD", "EGP", "ERN", "ETB", "EUR", "FJD", "FKP", "GBP", "GEL", "GGP", "GHS", "GIP", "GMD", "GNF", "GTQ", "GYD", "HKD", "HNL", "HRK", "HTG", "HUF", "IDR", "ILS", "IMP", "INR", "IQD", "IRR", "ISK", "JEP", "JMD", "JOD", "JPY", "KES", "KGS", "KHR", "KMF", "KPW", "KRW", "KWD", "KYD", "KZT", "LAK", "LBP", "LKR", "LRD", "LSL", "LYD", "MAD", "MDL", "MGA", "MKD", "MMK", "MNT", "MOP", "MRO", "MRU", "MUR", "MVR", "MWK", "MXN", "MYR", "MZN", "NAD", "NGN", "NIO", "NOK", "NPR", "NZD", "OMR", "PAB", "PEN", "PGK", "PHP", "PKR", "PLN", "PYG", "QAR", "RON", "RSD", "RUB", "RWF", "SAR", "SBD", "SCR", "SDG", "SEK", "SGD", "SHP", "SLL", "SOS", "SRD", "SSP", "STD", "STN", "SVC", "SYP", "SZL", "THB", "TJS", "TMT", "TND", "TOP", "TRY", "TTD", "TWD", "TZS", "UAH", "UGX", "USD", "UYU", "UZS", "VEF", "VES", "VND", "VUV", "WST", "XAF", "XAG", "XAU", "XCD", "XDR", "XOF", "XPD", "XPF", "XPT", "YER", "ZAR", "ZMW", "ZWL",
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
local json = require "json"
|
local json = require "json"
|
||||||
local color = require "md_colors"
|
local color = require "md_colors"
|
||||||
local text_color = ui:get_colors().secondary_text
|
local text_color = aio:colors().secondary_text
|
||||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
local equals = "<font color=\""..text_color.."\"> = </font>"
|
||||||
|
|
||||||
-- константы --
|
-- константы --
|
||||||
@@ -50,7 +50,7 @@ function on_network_result(result)
|
|||||||
line = amount.." "..string.upper(cur).." "..equals.." "..divide_number(rate," ").." "..string.upper(base_cur)..get_formatted_change_text(change)
|
line = amount.." "..string.upper(cur).." "..equals.." "..divide_number(rate," ").." "..string.upper(base_cur)..get_formatted_change_text(change)
|
||||||
tab = {{"ᐊ", amount, string.upper(cur), equals, divide_number(rate," "), string.upper(base_cur), get_formatted_change_text(change), "ᐅ"}}
|
tab = {{"ᐊ", amount, string.upper(cur), equals, divide_number(rate," "), string.upper(base_cur), get_formatted_change_text(change), "ᐅ"}}
|
||||||
ui:show_table(tab, 7)
|
ui:show_table(tab, 7)
|
||||||
ui:set_title(ui:get_default_title().." ("..date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")..")")
|
ui:set_title(ui:default_title().." ("..date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")..")")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-- name = "Drawer Sample"
|
-- name = "Drawer Sample #1"
|
||||||
-- type = "drawer"
|
-- type = "drawer"
|
||||||
-- testing = "true"
|
-- testing = "true"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
-- name = "Drawer Sample #3"
|
-- name = "Drawer Sample #2"
|
||||||
-- type = "drawer"
|
-- type = "drawer"
|
||||||
-- testing = "true"
|
-- testing = "true"
|
||||||
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
-- 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(function(it) return apps:name(it) end, pkgs)
|
|
||||||
drawer:show_list(names, icons, nil, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
function on_click(idx)
|
|
||||||
apps:launch(pkgs[idx])
|
|
||||||
end
|
|
||||||
@@ -7,14 +7,14 @@ end
|
|||||||
|
|
||||||
function on_network_result_ip(result)
|
function on_network_result_ip(result)
|
||||||
local location = {
|
local location = {
|
||||||
ajson:get_value(result, "object string:latitude"),
|
ajson:read(result, "object string:latitude"),
|
||||||
ajson:get_value(result, "object string:longitude")
|
ajson:read(result, "object string:longitude")
|
||||||
}
|
}
|
||||||
http:get(addr_service_url.."&lat="..location[1].."&lon=".. location[2].."&addressdetails=1", "addr")
|
http:get(addr_service_url.."&lat="..location[1].."&lon=".. location[2].."&addressdetails=1", "addr")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_network_result_addr(result)
|
function on_network_result_addr(result)
|
||||||
local adr = ajson:get_value(result, "object string:display_name")
|
local adr = ajson:read(result, "object string:display_name")
|
||||||
ui:show_text(adr)
|
ui:show_text(adr)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
function on_resume()
|
function on_resume()
|
||||||
ui:show_text("Phone language: "..system:get_lang())
|
ui:show_text("Phone language: "..system:lang())
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ function on_alarm()
|
|||||||
table.insert(buttons,button)
|
table.insert(buttons,button)
|
||||||
table.insert(colors,v.color)
|
table.insert(colors,v.color)
|
||||||
end
|
end
|
||||||
local color = ui:get_colors()
|
local color = aio:colors()
|
||||||
table.insert(buttons,"+")
|
table.insert(buttons,"+")
|
||||||
table.insert(colors,color.secondary_text)
|
table.insert(colors,color.secondary_text)
|
||||||
ui:show_buttons(buttons,colors)
|
ui:show_buttons(buttons,colors)
|
||||||
@@ -44,7 +44,7 @@ function on_dialog_action(data)
|
|||||||
if data ~= -1 then
|
if data ~= -1 then
|
||||||
if diag_id == "new" then
|
if diag_id == "new" then
|
||||||
if data ~= "" then
|
if data ~= "" then
|
||||||
local color = ui:get_colors()
|
local color = aio:colors()
|
||||||
local note = {}
|
local note = {}
|
||||||
note.text = data
|
note.text = data
|
||||||
note.color = color.button
|
note.color = color.button
|
||||||
@@ -85,7 +85,7 @@ end
|
|||||||
|
|
||||||
function on_context_menu_click(idx)
|
function on_context_menu_click(idx)
|
||||||
local md_color = require "md_colors"
|
local md_color = require "md_colors"
|
||||||
local color = ui:get_colors()
|
local color = aio:colors()
|
||||||
if idx == 1 then
|
if idx == 1 then
|
||||||
move(-1)
|
move(-1)
|
||||||
elseif idx == 2 then
|
elseif idx == 2 then
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ local green = md_colors.green_400
|
|||||||
function on_search(input)
|
function on_search(input)
|
||||||
text_from = input
|
text_from = input
|
||||||
text_to = ""
|
text_to = ""
|
||||||
search:show({input},{green})
|
search:show_lines({input},{green})
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
function on_alarm()
|
function on_alarm()
|
||||||
local location = system:get_location()
|
local location = system:location()
|
||||||
http:get("https://nominatim.openstreetmap.org/reverse?format=json&lat=".. location[1].."&lon=".. location[2].."&addressdetails=1")
|
http:get("https://nominatim.openstreetmap.org/reverse?format=json&lat=".. location[1].."&lon=".. location[2].."&addressdetails=1")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_network_result(result)
|
function on_network_result(result)
|
||||||
local adr = ajson:get_value(result, "object string:display_name")
|
local adr = ajson:read(result, "object string:display_name")
|
||||||
ui:show_text(adr)
|
ui:show_text(adr)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,13 +14,13 @@ function on_alarm()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if response.code >= 200 and response.code < 300 then
|
if response.code >= 200 and response.code < 300 then
|
||||||
joke = ajson:get_value(response.body, "object object:value string:joke")
|
joke = ajson:read(response.body, "object object:value string:joke")
|
||||||
ui:show_text(joke)
|
ui:show_text(joke)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click()
|
function on_click()
|
||||||
if joke ~= nil then
|
if joke ~= nil then
|
||||||
system:copy_to_clipboard(joke)
|
system:to_clipboard(joke)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
function on_resume()
|
function on_resume()
|
||||||
ui:set_title("New title")
|
ui:set_title("New title")
|
||||||
ui:show_text("Original title: "..ui:get_default_title())
|
ui:show_text("Original title: "..ui:default_title())
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local fmt = require "fmt"
|
local fmt = require "fmt"
|
||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
local widgets = aio:get_active_widgets()
|
local widgets = aio:active_widgets()
|
||||||
local tab = {}
|
local tab = {}
|
||||||
|
|
||||||
for k,v in pairs(widgets) do
|
for k,v in pairs(widgets) do
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
local fmt = require "fmt"
|
local fmt = require "fmt"
|
||||||
|
|
||||||
function on_resume()
|
function on_resume()
|
||||||
local widgets = aio:get_available_widgets()
|
local widgets = aio:available_widgets()
|
||||||
local tab = {}
|
local tab = {}
|
||||||
|
|
||||||
for k,v in pairs(widgets) do
|
for k,v in pairs(widgets) do
|
||||||
|
|||||||
Reference in New Issue
Block a user