add settings API
This commit is contained in:
@@ -14,17 +14,17 @@ local month = 30.43
|
||||
local milestones = {
|
||||
1, 3, 7, 14,
|
||||
month, month * 3, month * 6,
|
||||
year, year * 3, year * 5, year * 10, year * 20
|
||||
year, year * 3, year * 5, year * 10, year * 20, year * 100
|
||||
}
|
||||
|
||||
local milestones_formatted = {
|
||||
"1 day", "3 days", "1 week", "2 weeks",
|
||||
"1 months", "3 months", "6 months",
|
||||
"1 year", "3 years", "5 years", "10 years", "20 years"
|
||||
"1 day", "3 days", "1 week", "2 weeks",
|
||||
"1 months", "3 months", "6 months",
|
||||
"1 year", "3 years", "5 years", "10 years", "20 years", "100 years"
|
||||
}
|
||||
|
||||
function on_resume()
|
||||
local args = aio:get_args()
|
||||
local args = settings:get()
|
||||
|
||||
if next(args) == nil then
|
||||
ui:show_text("Tap to enter date")
|
||||
@@ -39,7 +39,7 @@ function on_resume()
|
||||
local passed_days = math.floor(passed:spandays())
|
||||
local idx = get_milestone_idx(passed)
|
||||
|
||||
ui:show_progress_bar(passed_days.." days / "..milestones_formatted[idx],
|
||||
ui:show_progress_bar(passed_days.." days / "..milestones_formatted[idx],
|
||||
passed_days, milestones[idx])
|
||||
end
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ 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)
|
||||
@@ -63,18 +63,18 @@ function prev_date(dat)
|
||||
end
|
||||
|
||||
function create_tab(result)
|
||||
local curs = aio:get_args()
|
||||
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
|
||||
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]]
|
||||
|
||||
@@ -29,7 +29,7 @@ local url = nil
|
||||
local curr_idx = nil
|
||||
|
||||
function on_resume()
|
||||
if next(aio:get_args()) == nil then
|
||||
if next(settings:get()) == nil then
|
||||
ui:show_text("Tap to enter Kodi address")
|
||||
return
|
||||
end
|
||||
@@ -41,7 +41,7 @@ function on_resume()
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if next(aio:get_args()) == nil then
|
||||
if next(settings:get()) == nil then
|
||||
aio:show_args_dialog()
|
||||
return
|
||||
end
|
||||
@@ -78,7 +78,7 @@ end
|
||||
|
||||
function on_network_result_cmd(result)
|
||||
local parsed = json.decode(result)
|
||||
|
||||
|
||||
if parsed.error ~= nil then
|
||||
show_error(parsed)
|
||||
end
|
||||
@@ -87,7 +87,7 @@ end
|
||||
-- utils
|
||||
|
||||
function init_url_from_args()
|
||||
local ip_port = aio:get_args()[1]:split(":")
|
||||
local ip_port = settings:get()[1]:split(":")
|
||||
url = "http://"..ip_port[1]..":"..ip_port[2].."/jsonrpc"
|
||||
end
|
||||
|
||||
|
||||
@@ -15,19 +15,19 @@ local click_url = "https://uptimerobot.com/dashboard#mainDashboard"
|
||||
local media_type = "application/x-www-form-urlencoded"
|
||||
|
||||
function on_alarm()
|
||||
if (next(aio:get_args()) == nil) then
|
||||
if (next(settings:get()) == nil) then
|
||||
ui:show_text("Tap to enter API key")
|
||||
return
|
||||
end
|
||||
|
||||
local key = aio:get_args()[1]
|
||||
local key = settings:get()[1]
|
||||
local body = "api_key="..key.."&format=json"
|
||||
|
||||
http:post(api_url.."getMonitors", body, media_type)
|
||||
end
|
||||
|
||||
function on_click()
|
||||
if (next(aio:get_args()) == nil) then
|
||||
if (next(settings:get()) == nil) then
|
||||
aio:show_args_dialog()
|
||||
else
|
||||
system:open_browser(click_url)
|
||||
|
||||
@@ -20,7 +20,7 @@ local dialog_id = ""
|
||||
local item_idx = 0
|
||||
|
||||
function on_resume()
|
||||
if next(aio:get_args()) == nil then
|
||||
if next(settings:get()) == nil then
|
||||
set_default_args()
|
||||
end
|
||||
|
||||
@@ -78,11 +78,11 @@ function on_dialog_action(data)
|
||||
local radio_idx = get_radio_idx()
|
||||
local args = data
|
||||
table.insert(args, radio_idx)
|
||||
aio:set_args(args)
|
||||
settings:set(args)
|
||||
elseif dialog_id == "style" then
|
||||
local args = get_checkbox_idx()
|
||||
table.insert(args, data)
|
||||
aio:set_args(args)
|
||||
settings:set(args)
|
||||
end
|
||||
|
||||
on_resume()
|
||||
@@ -96,11 +96,11 @@ function set_default_args()
|
||||
table.insert(args, i)
|
||||
end
|
||||
table.insert(args, 1)
|
||||
aio:set_args(args)
|
||||
settings:set(args)
|
||||
end
|
||||
|
||||
function get_checkbox_idx()
|
||||
local tab = aio:get_args()
|
||||
local tab = settings:get()
|
||||
table.remove(tab, #tab)
|
||||
for i = 1, #tab do
|
||||
tab[i] = tonumber(tab[i])
|
||||
@@ -109,7 +109,7 @@ function get_checkbox_idx()
|
||||
end
|
||||
|
||||
function get_radio_idx()
|
||||
local tab = aio:get_args()
|
||||
local tab = settings:get()
|
||||
return tonumber(tab[#tab])
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user