From 6d713a3cc00c8b81d820eb63c481ddd636d2a01d Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 9 Apr 2024 11:07:31 +0400 Subject: [PATCH] Update scripts zip --- main/widgets-on-off.lua | 230 ++++++++++++++++++---------------------- scripts.md5 | 2 +- scripts.zip | Bin 22197 -> 22429 bytes 3 files changed, 107 insertions(+), 125 deletions(-) diff --git a/main/widgets-on-off.lua b/main/widgets-on-off.lua index 2d69992..3fee690 100644 --- a/main/widgets-on-off.lua +++ b/main/widgets-on-off.lua @@ -1,109 +1,43 @@ --- name = "Переключатель виджетов" +-- name = "Widgets switcher" -- description = "Turns screen widgets on and off when buttons are pressed" -- type = "widget" +-- arguments_help = "Don't change the arguments directly, use the long click menu." -- author = "Andrey Gavrilov" -- version = "2.1" -prefs = require "prefs" -prefs._name = "widgets" +--constants-- + +local enabled_color = aio:colors().progress_good +local disabled_color = aio:colors().button + +local widgets = {"weather","weatheronly","clock","alarm","worldclock","monitor","traffic","player","apps","appbox","applist","appfolders","contacts","notify","dialogs","dialer","timer","stopwatch","mail","notes","tasks", "health", "feed","telegram","calendar","calendarw","exchange","finance","bitcoin","control","recorder","calculator","empty"} + +local icons = {"fa:user-clock","fa:sun-cloud","fa:clock","fa:alarm-clock","fa:business-time","fa:network-wired","fa:exchange","fa:play-circle","fa:robot","fa:th","fa:list","fa:folder","fa:address-card","fa:bell","fa:comment-alt-minus","fa:phone-alt","fa:chess-clock","fa:stopwatch","fa:at","fa:sticky-note","fa:calendar-check", "fa:heart-pulse", "fa:rss-square","fa:paper-plane","fa:calendar-alt","fa:calendar-week","fa:euro-sign","fa:chart-line","fa:coins","fa:wifi","fa:microphone-alt","fa:calculator-alt","fa:eraser"} + +local names = {"Clock & weather","Weather","Clock","Alarm","World clock","Monitor","Traffic","Player","Frequent apps","My apps","App list","App folders","Contacts","Notify","Dialogs","Dialer","Timer","Stopwatch","Mail","Notes","Tasks", "Health", "Feed","Telegram","Calendar","Weekly calendar","Exchange","Finance","Bitcoin","Control panel","Recorder","Calculator","Empty widget"} + +--variables-- local pos = 0 -local color = aio:colors() -local buttons,colors = {},{} -function on_alarm() - widgets = get_widgets() - if not prefs.widgets then - prefs.widgets = widgets.name - end - indexes = get_indexes(prefs.widgets, widgets.name) - ui:show_buttons(get_buttons()) -end - -function on_long_click(idx) - system:vibrate(10) - pos = idx - if idx > #prefs.widgets then - return - end - ui:show_context_menu({{"angle-left",""},{"ban",""},{"angle-right",""},{widgets.icon[indexes[idx]],widgets.label[indexes[idx]]}}) +function on_resume() + if next(settings:get()) == nil then + set_default_args() + end + ui:set_folding_flag(true) + local buttons,colors = get_buttons() + ui:show_buttons(buttons, colors) end function on_click(idx) - system:vibrate(10) - if idx > #prefs.widgets then - on_settings() - return - end - local widget = prefs.widgets[idx] - if not aio:is_widget_added(widget) then - aio:add_widget(widget, get_pos()) - aio:fold_widget(widget, false) - else - aio:remove_widget(widget) - end - on_alarm() + pos = idx + redraw() end -function on_dialog_action(data) - if data == -1 then - return - end - local tab = {} - for i,v in ipairs(data) do - tab[i] = widgets.name[v] - end - prefs.widgets = tab - on_alarm() -end - -function on_settings() - ui:show_checkbox_dialog("Select widgets", widgets.label, indexes) -end - -function get_indexes(tab1,tab2) - local tab = {} - for i1,v1 in ipairs(tab1) do - for i2,v2 in ipairs(tab2) do - if v1 == v2 then - tab[i1] = i2 - break - end - end - end - return tab -end - -function get_buttons() - local enabled_color = aio:colors().progress_good - local disabled_color = aio:colors().button - buttons,colors = {},{} - for i,v in ipairs(indexes) do - table.insert(buttons, "fa:" .. widgets.icon[v]) - table.insert(colors, widgets.enabled[v] and enabled_color or disabled_color) - end - --table.insert(buttons, "fa:gear") - --table.insert(colors, color.disabled_icon) - return buttons,colors -end - -function move(x) - local tab = prefs.widgets - if (pos*x == -1) or (pos*x == #tab) then - return - end - local cur = tab[pos] - tab[pos] = tab[pos+x] - tab[pos+x] = cur - prefs.widgets = tab - on_alarm() -end - -function remove() - local tab = prefs.widgets - table.remove(tab,pos) - prefs.widgets = tab - on_alarm() +function on_long_click(idx) + pos = idx + local tab = settings:get() + ui:show_context_menu({{"angle-left",""},{"ban",""},{"angle-right",""},{icons[get_checkbox_idx()[idx]]:gsub("fa:",""),names[get_checkbox_idx()[idx]]}}) end function on_context_menu_click(menu_idx) @@ -113,42 +47,90 @@ function on_context_menu_click(menu_idx) remove() elseif menu_idx == 3 then move(1) + elseif menu_idx == 4 then + redraw() end end -function on_widget_action(action, name) - on_alarm() +function on_dialog_action(data) + if data == -1 then + return + end + settings:set(data) + on_resume() end -function get_pos() - local name = aio:self_name() - local tab = aio:active_widgets() - for _,v in ipairs(tab) do - if v.name == name then - return v.position+1 - end - end - return 4 +function on_settings() + ui:show_checkbox_dialog("Select widgets", names, get_checkbox_idx()) end -function get_widgets() - local tab = {} - tab.icon = {} - tab.name = {} - tab.label = {} - tab.enabled = {} - for i,v in ipairs(aio:available_widgets()) do - if v.type == "builtin" then - table.insert(tab.icon, v.icon) - table.insert(tab.name, v.name) - table.insert(tab.label, v.label) - table.insert(tab.enabled, v.enabled) - end - end - local cal_widget = "my-calendar.lua" - table.insert(tab.icon, "calendar-days") - table.insert(tab.name, cal_widget) - table.insert(tab.label, "Месячный календарь") - table.insert(tab.enabled, aio:is_widget_added(cal_widget)) - return tab +--utilities-- + +function redraw() + local buttons,colors = get_buttons() + local checkbox_idx = get_checkbox_idx() + local widget = widgets[checkbox_idx[pos]] + if aio:is_widget_added(widget) then + aio:remove_widget(widget) + colors[pos] = disabled_color + else + aio:add_widget(widget) + colors[pos] = enabled_color + end + ui:show_buttons(buttons, colors) +end + +function set_default_args() + local args = {} + for i = 1, #widgets do + table.insert(args, i) + end + settings:set(args) +end + +function get_checkbox_idx() + local tab = settings:get() + for i = 1, #tab do + tab[i] = tonumber(tab[i]) + end + return tab +end + +function get_buttons() + local buttons,colors = {},{} + local checkbox_idx = get_checkbox_idx() + for i = 1, #checkbox_idx do + table.insert(buttons, icons[checkbox_idx[i]]) + local widget = widgets[checkbox_idx[i]] + if widget ~= nil then + if aio:is_widget_added(widget) then + table.insert(colors, enabled_color) + else + table.insert(colors, disabled_color) + end + end + end + return buttons,colors +end + +function move(x) + local tab = settings:get() + if (pos == 1 and x < 0) or (pos == #tab and x > 0) then + return + end + local cur = tab[pos] + local prev = tab[pos+x] + tab[pos+x] = cur + tab[pos] = prev + settings:set(tab) + local buttons,colors = get_buttons() + ui:show_buttons(buttons, colors) +end + +function remove() + local tab = settings:get() + table.remove(tab,pos) + settings:set(tab) + local buttons,colors = get_buttons() + ui:show_buttons(buttons, colors) end diff --git a/scripts.md5 b/scripts.md5 index 385b187..9ca7f08 100644 --- a/scripts.md5 +++ b/scripts.md5 @@ -1 +1 @@ -f479d227b90a6f98f309841cdcce9f38 +6427267169ed17f29d737911edecfb91 diff --git a/scripts.zip b/scripts.zip index 6369f694eb3d4609f390ff18a98a629d09f399d5..658a06a752ee772a0cd789764743309484968311 100644 GIT binary patch delta 1585 zcmV-12G04ltpS~{0k9i04(C{jSVDK_Zjc2403i^QDKi~^BIy)nBIy)nb$AN^0R-p+ z000E&0{{TMS4(f(Mi9R1S1eSZrBKm`)1HjFKx)VBB|*>_@WC*M6*;69UhOiwOG|>` z{`Su7gAZADl0)l*Ih>vM%r{HrIa7QC?3~SSMAd+^%x;A%*I?$eJZBZy(umdxtw`p& zGYTb21EAP{HY(r|R~6HB&9-aguR7;6ig5$1HDE1N-j>_9-ciu=EN+@^1IpQA4YH-f zORau#tXy-|0CQ^?L|7#ZluquKth3=vYSpk(it?VJNOux!c5bZ=*?Olc1AF!-e=tJo z2Y>ni#>Qmco}A8S$SW~e$I(Nc&t_7WTryC6C7~*RN-e!9F7%nFZMHaRjczEdqS3mF z3YD<0XoQL+~X#Y?x@zwL}?}W_*SCmJwCbQW<#gi$SN^6S_!8~$r)bPqC~2d zeDCe>wzc80(z`%NVO^kVEh{VlInc`S(h;e&6E!)l1edz8k@D7@*!ZV)y4`Y|3v$ne z3~E4svX0w(e6sl(xO8ixYQUD`2}o!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