Move useless scripts to samples
This commit is contained in:
@@ -4,38 +4,40 @@
|
|||||||
-- type = "search"
|
-- type = "search"
|
||||||
-- lang = "ru"
|
-- lang = "ru"
|
||||||
-- author = "Andrey Gavrilov"
|
-- author = "Andrey Gavrilov"
|
||||||
-- version = "1.0"
|
-- version = "1.1"
|
||||||
|
|
||||||
local num = ""
|
|
||||||
|
|
||||||
function on_search(input)
|
function on_search(input)
|
||||||
num = input:match("^n (.+)")
|
local num = input:match("^(+?7?%d%d%d%d%d%d%d%d%d%d+)$")
|
||||||
if not num then
|
if not num then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
search:show({"Оператор "..num})
|
show_operator(num)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click()
|
function show_operator(num)
|
||||||
|
local json = require "json"
|
||||||
local uri = "http://rosreestr.subnets.ru/?get=num&format=json&num=" .. num:gsub("%D", "")
|
local uri = "http://rosreestr.subnets.ru/?get=num&format=json&num=" .. num:gsub("%D", "")
|
||||||
http:get(uri)
|
local tab = {}
|
||||||
return false
|
local result = shttp:get(uri)
|
||||||
end
|
if not result.error then
|
||||||
|
local t = json.decode(result.body)
|
||||||
function on_network_result(result)
|
if not t.error then
|
||||||
local json = require "json"
|
if not t["0"].country then
|
||||||
local t = json.decode(result)
|
if not t["0"].moved2operator then
|
||||||
if not t.error then
|
table.insert(tab, t["0"].operator)
|
||||||
if not t["0"].country then
|
else
|
||||||
if not t["0"].moved2operator then
|
table.insert(tab, t["0"].moved2operator)
|
||||||
search:show({t["0"].operator, t["0"].region})
|
end
|
||||||
|
table.insert(tab, t["0"].region)
|
||||||
else
|
else
|
||||||
search:show({t["0"].moved2operator, t["0"].region})
|
table.insert(tab, t["0"].country)
|
||||||
|
table.insert(tab, t["0"].description)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
search:show({t["0"].country, t["0"].description})
|
table.insert(tab, t.error)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
search:show({t.error})
|
table.insert(tab, result.error)
|
||||||
end
|
end
|
||||||
|
search:show_lines({table.concat(tab, ", ")}, {aio:colors().button})
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
-- name = "Sudoku"
|
-- name = "Sudoku"
|
||||||
-- description = "Sudoku games"
|
-- description = "Sudoku games"
|
||||||
-- type = "Game"
|
-- type = "widget"
|
||||||
-- author = "Andrey Gavrilov"
|
-- author = "Andrey Gavrilov"
|
||||||
-- version = "1.0"
|
-- version = "1.0"
|
||||||
|
|
||||||
|
|||||||
@@ -1,195 +1,195 @@
|
|||||||
-- name = "Курс валюты"
|
-- name = "Курс валюты"
|
||||||
-- description = "Виджет курса валюты. Нажмите на виджет, чтобы изменить валюту. Базовая валюта и дата меняются в контекстном меню."
|
-- description = "Виджет курса валюты. Нажмите на виджет, чтобы изменить валюту. Базовая валюта и дата меняются в контекстном меню."
|
||||||
-- data_source = "https://exchangerate.host/"
|
-- data_source = "https://exchangerate.host/"
|
||||||
-- type = "widget"
|
-- type = "widget"
|
||||||
-- author = "Andrey Gavrilov"
|
-- author = "Andrey Gavrilov"
|
||||||
-- version = "2.0"
|
-- version = "2.0"
|
||||||
-- lang = "ru"
|
-- lang = "ru"
|
||||||
|
|
||||||
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 = ui:get_colors().secondary_text
|
||||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
local equals = "<font color=\""..text_color.."\"> = </font>"
|
||||||
|
|
||||||
-- константы --
|
-- константы --
|
||||||
local curs = {"usd", "eur", "gbp", "chf", "aed", "cny", "inr", "btc", "other"}
|
local curs = {"usd", "eur", "gbp", "chf", "aed", "cny", "inr", "btc", "other"}
|
||||||
local curs_n = {"Доллар США", "Евро", "Фунт стерлингов", "Швейцарский франк", "Дирхам ОАЭ", "Китайский юань", "Индийская рупия", "Биткойн", "Другая"}
|
local curs_n = {"Доллар США", "Евро", "Фунт стерлингов", "Швейцарский франк", "Дирхам ОАЭ", "Китайский юань", "Индийская рупия", "Биткойн", "Другая"}
|
||||||
local base_curs = {"rub", "usd", "other_b"}
|
local base_curs = {"rub", "usd", "other_b"}
|
||||||
local base_curs_n = {"Российский рубль", "Доллар США", "Другая"}
|
local base_curs_n = {"Российский рубль", "Доллар США", "Другая"}
|
||||||
|
|
||||||
-- переменные --
|
-- переменные --
|
||||||
local dialog_id = ""
|
local dialog_id = ""
|
||||||
local cur_idx = 1
|
local cur_idx = 1
|
||||||
local cur = curs[cur_idx]
|
local cur = curs[cur_idx]
|
||||||
local base_cur_idx = 1
|
local base_cur_idx = 1
|
||||||
local base_cur = base_curs[base_cur_idx]
|
local base_cur = base_curs[base_cur_idx]
|
||||||
local date = ""
|
local date = ""
|
||||||
local line = ""
|
local line = ""
|
||||||
local tab = {}
|
local tab = {}
|
||||||
local amount = "1"
|
local amount = "1"
|
||||||
local rate = 0
|
local rate = 0
|
||||||
|
|
||||||
function on_alarm()
|
function on_alarm()
|
||||||
date = os.date("%Y-%m-%d")
|
date = os.date("%Y-%m-%d")
|
||||||
get_rates(date)
|
get_rates(date)
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_rates(date)
|
function get_rates(date)
|
||||||
http:get("https://api.exchangerate.host/fluctuation?start_date="..prev_date(date).."&end_date="..date.."&symbols="..string.upper(base_cur).."&base="..string.upper(cur).."&amount="..amount)
|
http:get("https://api.exchangerate.host/fluctuation?start_date="..prev_date(date).."&end_date="..date.."&symbols="..string.upper(base_cur).."&base="..string.upper(cur).."&amount="..amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_network_result(result)
|
function on_network_result(result)
|
||||||
t = json.decode(result)
|
t = json.decode(result)
|
||||||
if t.rates[string.upper(base_cur)].end_rate == nil then
|
if t.rates[string.upper(base_cur)].end_rate == nil then
|
||||||
date = prev_date(date)
|
date = prev_date(date)
|
||||||
get_rates(date)
|
get_rates(date)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
rate = round(t.rates[string.upper(base_cur)].end_rate,4)
|
rate = round(t.rates[string.upper(base_cur)].end_rate,4)
|
||||||
local change = round(-t.rates[string.upper(base_cur)].change_pct*100,2)
|
local change = round(-t.rates[string.upper(base_cur)].change_pct*100,2)
|
||||||
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:get_default_title().." ("..date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")..")")
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
if idx == 1 then
|
if idx == 1 then
|
||||||
date = prev_date(date)
|
date = prev_date(date)
|
||||||
get_rates(date)
|
get_rates(date)
|
||||||
ui:show_toast("Загрузка")
|
ui:show_toast("Загрузка")
|
||||||
elseif idx == 2 then
|
elseif idx == 2 then
|
||||||
dialog_id ="amount"
|
dialog_id ="amount"
|
||||||
ui:show_edit_dialog("Введите количество", "", amount)
|
ui:show_edit_dialog("Введите количество", "", amount)
|
||||||
elseif idx == 3 then
|
elseif idx == 3 then
|
||||||
dialog_id = "cur"
|
dialog_id = "cur"
|
||||||
ui:show_radio_dialog("Выберите валюту", curs_n, cur_idx)
|
ui:show_radio_dialog("Выберите валюту", curs_n, cur_idx)
|
||||||
elseif idx == 6 then
|
elseif idx == 6 then
|
||||||
dialog_id = "base_cur"
|
dialog_id = "base_cur"
|
||||||
ui:show_radio_dialog("Выберите базовую валюту", base_curs_n, base_cur_idx)
|
ui:show_radio_dialog("Выберите базовую валюту", base_curs_n, base_cur_idx)
|
||||||
elseif idx == 8 then
|
elseif idx == 8 then
|
||||||
date = next_date(date)
|
date = next_date(date)
|
||||||
get_rates(date)
|
get_rates(date)
|
||||||
ui:show_toast("Загрузка")
|
ui:show_toast("Загрузка")
|
||||||
else
|
else
|
||||||
dialog_id = "date"
|
dialog_id = "date"
|
||||||
ui:show_edit_dialog("Введите дату курса", "Формат даты - 31.12.2020. Пустое значение - текущая дата", date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1"))
|
ui:show_edit_dialog("Введите дату курса", "Формат даты - 31.12.2020. Пустое значение - текущая дата", date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_long_click(idx)
|
function on_long_click(idx)
|
||||||
item_idx = idx
|
item_idx = idx
|
||||||
|
|
||||||
ui:show_context_menu({
|
ui:show_context_menu({
|
||||||
{"share-alt","Поделиться"},
|
{"share-alt","Поделиться"},
|
||||||
{"copy","Копировать"},
|
{"copy","Копировать"},
|
||||||
{"redo","Перезагрузить"}
|
{"redo","Перезагрузить"}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_dialog_action(data)
|
function on_dialog_action(data)
|
||||||
if data == -1 then
|
if data == -1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if dialog_id == "date" then
|
if dialog_id == "date" then
|
||||||
if get_date(date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")) == get_date(data) then
|
if get_date(date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1")) == get_date(data) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
date = get_date(data)
|
date = get_date(data)
|
||||||
elseif dialog_id == "cur" then
|
elseif dialog_id == "cur" then
|
||||||
if data == cur_idx and cur == curs[data] then
|
if data == cur_idx and cur == curs[data] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
cur_idx = data
|
cur_idx = data
|
||||||
if curs[data] == "other" then
|
if curs[data] == "other" then
|
||||||
dialog_id = "other"
|
dialog_id = "other"
|
||||||
ui:show_edit_dialog("Введите валюту", "", string.lower(cur))
|
ui:show_edit_dialog("Введите валюту", "", string.lower(cur))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
cur = string.upper(curs[data])
|
cur = string.upper(curs[data])
|
||||||
elseif dialog_id == "base_cur" then
|
elseif dialog_id == "base_cur" then
|
||||||
if data == base_cur_idx and base_cur == base_curs[data] then
|
if data == base_cur_idx and base_cur == base_curs[data] then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
base_cur_idx = data
|
base_cur_idx = data
|
||||||
if base_curs[data] == "other_b" then
|
if base_curs[data] == "other_b" then
|
||||||
dialog_id = "other_b"
|
dialog_id = "other_b"
|
||||||
ui:show_edit_dialog("Введите базовую валюту", "", string.lower(base_cur))
|
ui:show_edit_dialog("Введите базовую валюту", "", string.lower(base_cur))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
base_cur = string.upper(base_curs[data])
|
base_cur = string.upper(base_curs[data])
|
||||||
elseif dialog_id == "other" then
|
elseif dialog_id == "other" then
|
||||||
if data == cur then
|
if data == cur then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
cur = string.upper(data)
|
cur = string.upper(data)
|
||||||
elseif dialog_id == "other_b" then
|
elseif dialog_id == "other_b" then
|
||||||
if data == base_cur then
|
if data == base_cur then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
base_cur = string.upper(data)
|
base_cur = string.upper(data)
|
||||||
elseif dialog_id == "amount" then
|
elseif dialog_id == "amount" then
|
||||||
if amount == data:gsub(",",".") then
|
if amount == data:gsub(",",".") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
amount = data:gsub(",","."):gsub("-","")
|
amount = data:gsub(",","."):gsub("-","")
|
||||||
if amount == "" then
|
if amount == "" then
|
||||||
amount = "1"
|
amount = "1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
get_rates(date)
|
get_rates(date)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_context_menu_click(menu_idx)
|
function on_context_menu_click(menu_idx)
|
||||||
if menu_idx == 2 then
|
if menu_idx == 2 then
|
||||||
system:copy_to_clipboard(rate)
|
system:copy_to_clipboard(rate)
|
||||||
elseif menu_idx == 1 then
|
elseif menu_idx == 1 then
|
||||||
system:share_text(date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1").." "..line:gsub("(.+)<.+>(.+)<.+>(.+)<.+>(.+)<.+>", "%1%2%3%4"))
|
system:share_text(date:gsub("(%d+)-(%d+)-(%d+)", "%3.%2.%1").." "..line:gsub("(.+)<.+>(.+)<.+>(.+)<.+>(.+)<.+>", "%1%2%3%4"))
|
||||||
elseif menu_idx == 3 then
|
elseif menu_idx == 3 then
|
||||||
cur_idx = 1
|
cur_idx = 1
|
||||||
cur = string.upper(curs[cur_idx])
|
cur = string.upper(curs[cur_idx])
|
||||||
base_cur_idx = 1
|
base_cur_idx = 1
|
||||||
base_cur = string.upper(base_curs[base_cur_idx])
|
base_cur = string.upper(base_curs[base_cur_idx])
|
||||||
amount = "1"
|
amount = "1"
|
||||||
get_rates(os.date("%Y-%m-%d"))
|
get_rates(os.date("%Y-%m-%d"))
|
||||||
ui:show_toast("Начальные установки")
|
ui:show_toast("Начальные установки")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- утилиты --
|
-- утилиты --
|
||||||
function get_formatted_change_text(change)
|
function get_formatted_change_text(change)
|
||||||
if change > 0 then
|
if change > 0 then
|
||||||
return "<font color=\""..color.green_700.."\"> +"..change.."%</font>"
|
return "<font color=\""..color.green_700.."\"> +"..change.."%</font>"
|
||||||
elseif change < 0 then
|
elseif change < 0 then
|
||||||
return "<font color=\""..color.red_A700.."\"> "..change.."%</font>"
|
return "<font color=\""..color.red_A700.."\"> "..change.."%</font>"
|
||||||
else
|
else
|
||||||
return "<font color=\""..text_color.."\"> "..change.."%</font>"
|
return "<font color=\""..text_color.."\"> "..change.."%</font>"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function prev_date(date)
|
function prev_date(date)
|
||||||
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
|
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
|
||||||
return os.date("%Y-%m-%d", os.time{year=y, month=m, day=d} - (60*60*24))
|
return os.date("%Y-%m-%d", os.time{year=y, month=m, day=d} - (60*60*24))
|
||||||
end
|
end
|
||||||
|
|
||||||
function next_date(date)
|
function next_date(date)
|
||||||
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
|
local y, m, d = date:match("(%d+)-(%d+)-(%d+)")
|
||||||
return os.date("%Y-%m-%d", os.time{year=y, month=m, day=d} + (60*60*24))
|
return os.date("%Y-%m-%d", os.time{year=y, month=m, day=d} + (60*60*24))
|
||||||
end
|
end
|
||||||
|
|
||||||
function divide_number(n, str)
|
function divide_number(n, str)
|
||||||
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
|
local left,num,right = string.match(n,'^([^%d]*%d)(%d*)(.-)$')
|
||||||
return left..(num:reverse():gsub('(%d%d%d)','%1'..str):reverse())..right
|
return left..(num:reverse():gsub('(%d%d%d)','%1'..str):reverse())..right
|
||||||
end
|
end
|
||||||
|
|
||||||
function get_date(date)
|
function get_date(date)
|
||||||
local d, m, Y = date:match("(%d+).(%d+).(%d+)")
|
local d, m, Y = date:match("(%d+).(%d+).(%d+)")
|
||||||
local d0, m0, Y0 = os.date("%d.%m.%Y"):match("(%d+).(%d+).(%d+)")
|
local d0, m0, Y0 = os.date("%d.%m.%Y"):match("(%d+).(%d+).(%d+)")
|
||||||
local time = os.time{day=d or 0, month=m or 0, year=Y or 0}
|
local time = os.time{day=d or 0, month=m or 0, year=Y or 0}
|
||||||
local time0 = os.time{day=d0, month=m0, year=Y0}
|
local time0 = os.time{day=d0, month=m0, year=Y0}
|
||||||
local str = string.format("%04d-%02d-%02d", Y or 0, m or 0, d or 0)
|
local str = string.format("%04d-%02d-%02d", Y or 0, m or 0, d or 0)
|
||||||
if not (str == os.date("%Y-%m-%d", time) and time <= time0 - 24*60*60) then
|
if not (str == os.date("%Y-%m-%d", time) and time <= time0 - 24*60*60) then
|
||||||
str = os.date("%Y-%m-%d")
|
str = os.date("%Y-%m-%d")
|
||||||
end
|
end
|
||||||
return str
|
return str
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user