Update app widgets samples and community scripts

This commit is contained in:
Evgeny
2024-03-19 14:50:28 +04:00
parent 83150d0654
commit d8d9c12e07
2 changed files with 56 additions and 27 deletions

View File

@@ -1,4 +1,9 @@
-- name = "Android widgets sample (Google Tasks)" -- name = "Google Tasks"
-- description = "AIO wrapper for the official Google Tasks app widget"
-- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- aio_version = "4.1.99"
-- uses_app = "com.google.android.apps.tasks"
local prefs = require "prefs" local prefs = require "prefs"
local fmt = require "fmt" local fmt = require "fmt"
@@ -24,15 +29,17 @@ function on_app_widget_updated(bridge)
-- Remove "A fresh start" -- Remove "A fresh start"
table.remove(tab, #tab-1) table.remove(tab, #tab-1)
curr_tab = tab curr_tab = deep_copy(tab)
w_bridge = bridge w_bridge = bridge
-- Change "Anything to add?" string to "Add task"
tab[#tab] = fmt.secondary("Add task")
ui:show_lines(tab) ui:show_lines(tab)
end end
function on_click(idx) function on_click(idx)
--w_bridge:click(curr_tab[idx]) w_bridge:click(curr_tab[idx])
w_bridge:click("text_2")
end end
function setup_app_widget() function setup_app_widget()
@@ -44,3 +51,19 @@ function setup_app_widget()
return return
end end
end end
function deep_copy(orig)
local orig_type = type(orig)
local copy
if orig_type == 'table' then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[deep_copy(orig_key)] = deep_copy(orig_value)
end
setmetatable(copy, deep_copy(getmetatable(orig)))
else
copy = orig
end
return copy
end

View File

@@ -8,6 +8,8 @@
local prefs = require "prefs" local prefs = require "prefs"
local fmt = require "fmt" local fmt = require "fmt"
local widget = "com.todoist/com.todoist.appwidget.provider.ItemListAppWidgetProvider"
local curr_tab = {} local curr_tab = {}
local w_bridge = nil local w_bridge = nil
local colors = {} local colors = {}
@@ -22,30 +24,23 @@ end
function on_app_widget_updated(bridge) function on_app_widget_updated(bridge)
w_bridge = bridge w_bridge = bridge
colors = bridge:dump_colors() colors = bridge:dump_colors()
curr_tab = parse(bridge:dump_table()) curr_tab = bridge:dump_table()
curr_tab = parse(curr_tab)
ui:show_lines(curr_tab.lines) ui:show_lines(curr_tab.lines)
end end
function parse(t) function parse(t)
local tab = {} local tab = {}
tab["list"] = t.v_layout_1.frame_layout_1.relative_layout_1.text_1
local footer = t.v_layout_1.frame_layout_2
for k,v in pairs(footer) do
if k:sub(1,8) == "relative" then
footer = v
break
end
end
local images = {} local images = {}
local texts = {}
local lines = {} local lines = {}
local clicks = {}
local tasks = t.v_layout_1.frame_layout_2.list_layout_1 local tasks = t.v_layout_1.frame_layout_2.list_layout_1
if tasks == nil then tasks = {} end if not tasks then tasks = {} end
local tkeys = {} local tkeys = {}
for k,v in pairs(tasks) do for k,v in pairs(tasks) do
table.insert(tkeys,k) table.insert(tkeys,k)
end end
table.sort(tkeys) table.sort(tkeys,function (a,b) return tonumber(a:match("%d+")) < tonumber(b:match("%d+")) end)
for i1,v1 in ipairs(tkeys) do for i1,v1 in ipairs(tkeys) do
for k2,v2 in pairs(tasks[v1]) do for k2,v2 in pairs(tasks[v1]) do
for k3,v3 in pairs(v2) do for k3,v3 in pairs(v2) do
@@ -56,14 +51,14 @@ function parse(t)
local subtexts = {} local subtexts = {}
for k4,v4 in pairs(v3) do for k4,v4 in pairs(v3) do
if k4:sub(1,4) == "text" then if k4:sub(1,4) == "text" then
table.insert(texts,v4) table.insert(clicks,k4)
text = v4 text = v4
local color = colors[images[#texts]] local color = colors[images[#images]]
if color ~= "#909090" and color then if color ~= "#909090" and color then
text = fmt.colored(fmt.bold(text),color) text = fmt.colored(fmt.bold(text),color)
end end
elseif k4:sub(1,8) == "h_layout" then elseif k4:sub(1,8) == "h_layout" then
subtexts = recursion(v4,subtexts,#subtexts,false) subtexts = recursion(v4,subtexts,1,false)
end end
end end
table.insert(lines,text..table.concat(subtexts)) table.insert(lines,text..table.concat(subtexts))
@@ -71,19 +66,30 @@ function parse(t)
end end
end end
end end
local footer = t.v_layout_1.frame_layout_2
for k,v in pairs(footer) do
if k:sub(1,8) == "relative" then
footer = v
break
end
end
for k1,v1 in pairs(footer) do for k1,v1 in pairs(footer) do
for k2,v2 in pairs(v1) do for k2,v2 in pairs(v1) do
if k2:sub(1,4) == "text" then if k2:sub(1,4) == "text" then
table.insert(images,k2) table.insert(images,k2)
table.insert(texts,v2) table.insert(clicks,k2)
table.insert(lines,fmt.secondary("Add task")) local add_task = "Add task"
if #lines ~= 0 then
add_task = fmt.secondary(add_task)
end
table.insert(lines,add_task)
break break
end end
end end
end end
tab["images"] = images tab["images"] = images
tab["texts"] = texts
tab["lines"] = lines tab["lines"] = lines
tab["clicks"] = clicks
return tab return tab
end end
@@ -95,25 +101,25 @@ function recursion(t,tab,idx,flag)
table.insert(tab,idx,fmt.secondary(" - ") .. fmt.colored(v,colors[k])) table.insert(tab,idx,fmt.secondary(" - ") .. fmt.colored(v,colors[k]))
end end
elseif k:sub(1,8) == "h_layout" then elseif k:sub(1,8) == "h_layout" then
tab = recursion(v,tab,1,true) tab = recursion(v,tab,#tab+1,true)
end end
end end
return tab return tab
end end
function on_click(idx) function on_click(idx)
w_bridge:click(curr_tab.texts[idx]) w_bridge:click(curr_tab.clicks[idx])
end end
function setup_app_widget() function setup_app_widget()
local id = widgets:setup("com.todoist/com.todoist.appwidget.provider.ItemListAppWidgetProvider") local id = widgets:setup(widget)
if (id ~= nil) then if (id ~= nil) then
prefs.wid = id prefs.wid = id
else else
ui:show_text("Can't add widget") ui:show_toast("Can't add widget")
end end
end end
function on_settings() function on_settings()
w_bridge:click(curr_tab.list) w_bridge:click("text_1")
end end