From abf13d4ec112fc430b9fadea69455aa45d4e3cd6 Mon Sep 17 00:00:00 2001 From: Rockwell Schrock Date: Wed, 29 Jan 2025 23:07:06 -0500 Subject: On browser and file_browser screens, focus the first item when appearing --- lua/browser.lua | 1 + lua/file_browser.lua | 1 + lua/widgets.lua | 8 ++++++-- 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/browser.lua b/lua/browser.lua index 2a024fc5..264db0c5 100644 --- a/lua/browser.lua +++ b/lua/browser.lua @@ -118,6 +118,7 @@ return screen:new { end widgets.InfiniteList(self.root, self.iterator, { + focus_first_item = true, get_icon = get_icon_func, callback = function(item) return function() diff --git a/lua/file_browser.lua b/lua/file_browser.lua index a85c2ba2..98261d55 100644 --- a/lua/file_browser.lua +++ b/lua/file_browser.lua @@ -59,6 +59,7 @@ return screen:new { end widgets.InfiniteList(self.root, self.iterator, { + focus_first_item = true, callback = function(item) return function() local is_dir = item:is_directory() diff --git a/lua/widgets.lua b/lua/widgets.lua index 5e18809b..0aac7705 100644 --- a/lua/widgets.lua +++ b/lua/widgets.lua @@ -306,10 +306,11 @@ function widgets.InfiniteList(parent, iterator, opts) fwd_iterator:prev() end - local function add_item(item, index) + local function add_item(item, index, item_opts) if not item then return end + item_opts = item_opts or {} local this_item = index local add_to_top = false if this_item < first_index then @@ -325,6 +326,9 @@ function widgets.InfiniteList(parent, iterator, opts) if add_to_top then btn:move_to_index(0) end + if item_opts.focus then + btn:focus() + end -- opts.callback should take an item and return a function matching the arg of onClicked if opts.callback then btn:onClicked(opts.callback(item)) @@ -361,7 +365,7 @@ function widgets.InfiniteList(parent, iterator, opts) if not val then break end - add_item(val, idx) + add_item(val, idx, { focus = (opts.focus_first_item and idx == 0) }) end return infinite_list -- cgit v1.2.3 From 5163e5913056a4f9a5ec7d4c61315ec62bbdd13a Mon Sep 17 00:00:00 2001 From: River Tae Smith <22485304+r-tae@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:29:39 +1100 Subject: Change dropdown background on focus --- lua/theme_light.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/theme_light.lua b/lua/theme_light.lua index f4039766..2addf546 100644 --- a/lua/theme_light.lua +++ b/lua/theme_light.lua @@ -186,6 +186,7 @@ local theme_light = { }, dropdown = { {lvgl.PART.MAIN, lvgl.Style{ + bg_opa = lvgl.OPA(100), radius = 2, pad_all = 2, bg_color = background_color, @@ -196,7 +197,8 @@ local theme_light = { outline_width = 1, }}, {lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style { - border_color = highlight_color, + text_color = "#ffffff", + bg_color = highlight_color, }}, {lvgl.PART.INDICATOR, lvgl.Style { image_recolor_opa = 255, @@ -213,6 +215,7 @@ local theme_light = { bg_color = background_color }}, {lvgl.PART.SELECTED | lvgl.STATE.CHECKED, lvgl.Style { + text_color = "#ffffff", bg_color = highlight_color, }}, }, -- cgit v1.2.3 From b98e67972bca390961ecd2240ab3d3553ea0bf86 Mon Sep 17 00:00:00 2001 From: ailurux Date: Sat, 1 Feb 2025 08:40:48 +1100 Subject: Add outline to switch for better legibility in hicon theme --- lua/theme_hicon.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lua') diff --git a/lua/theme_hicon.lua b/lua/theme_hicon.lua index 80f78a10..f712e0a6 100644 --- a/lua/theme_hicon.lua +++ b/lua/theme_hicon.lua @@ -179,6 +179,8 @@ local theme_hicon = { bg_color = background_color, border_color = text_color, border_width = 1, + outline_color = background_color, + outline_width = 1, }}, {lvgl.PART.KNOB | lvgl.STATE.FOCUSED, lvgl.Style { bg_color = text_color, -- cgit v1.2.3 From e343ffee5a4663374a77073a3e4370041f2fc431 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 1 Feb 2025 17:23:24 +0000 Subject: Add playlist browser Add a menu item to main menu and associated browser for playlist files in the root of the SD card --- lua/main_menu.lua | 8 +++++ lua/playlist_browser.lua | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ lua/table_iterator.lua | 27 ++++++++++++++ lua/widgets.lua | 2 +- 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 lua/playlist_browser.lua create mode 100644 lua/table_iterator.lua (limited to 'lua') diff --git a/lua/main_menu.lua b/lua/main_menu.lua index cc7874d7..80d5b599 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -131,6 +131,14 @@ return widgets.MenuScreen:new { }) end + local playlist_btn = indexes_list:add_btn(nil, "Playlists") + playlist_btn:onClicked(function() + backstack.push(require("playlist_browser"):new { + title = "Playlists", + }) + end) + playlist_btn:add_style(styles.list_item) + local function show_no_indexes(msg) indexes_list:add_flag(lvgl.FLAG.HIDDEN) no_indexes_container:clear_flag(lvgl.FLAG.HIDDEN) diff --git a/lua/playlist_browser.lua b/lua/playlist_browser.lua new file mode 100644 index 00000000..da50f4c8 --- /dev/null +++ b/lua/playlist_browser.lua @@ -0,0 +1,91 @@ +-- SPDX-FileCopyrightText: 2025 Sam Lord +-- +-- SPDX-License-Identifier: GPL-3.0-only + +local lvgl = require("lvgl") +local widgets = require("widgets") +local database = require("database") +local sd_card = require("sd_card") +local backstack = require("backstack") +local browser = require("browser") +local playing = require("playing") +local styles = require("styles") +local filesystem = require("filesystem") +local screen = require("screen") +local font = require("font") +local theme = require("theme") +local img = require("images") +local playback = require("playback") +local queue = require("queue") +local table_iterator = require("table_iterator") + + +return screen:new { + create_ui = function(self) + self.root = lvgl.Object(nil, { + flex = { + flex_direction = "column", + flex_wrap = "wrap", + justify_content = "flex-start", + align_items = "flex-start", + align_content = "flex-start" + }, + w = lvgl.HOR_RES(), + h = lvgl.VER_RES() + }) + self.root:center() + + self.status_bar = widgets.StatusBar(self, { + back_cb = backstack.pop, + title = self.title + }) + + local header = self.root:Object { + flex = { + flex_direction = "column", + flex_wrap = "wrap", + justify_content = "flex-start", + align_items = "flex-start", + align_content = "flex-start" + }, + w = lvgl.HOR_RES(), + h = lvgl.SIZE_CONTENT, + pad_left = 4, + pad_right = 4, + pad_bottom = 2, + scrollbar_mode = lvgl.SCROLLBAR_MODE.OFF + } + theme.set_subject(header, "header") + + if self.breadcrumb then + header:Label { + text = self.breadcrumb, + text_font = font.fusion_10 + } + end + + local playlists = {} + -- Find playlists + local fs_iter = filesystem.iterator("") + for item in fs_iter do + if + item:filepath():match("%.playlist$") or + item:filepath():match("%.m3u8?$") then + table.insert(playlists, item) + end + end + + widgets.InfiniteList(self.root, table_iterator:create(playlists), { + focus_first_item = true, + callback = function(item) + return function() + queue.open_playlist(item:filepath()) + playback.playing:set(true) + backstack.push(playing:new()) + end + end + }) + end +} + + diff --git a/lua/table_iterator.lua b/lua/table_iterator.lua new file mode 100644 index 00000000..5bacada6 --- /dev/null +++ b/lua/table_iterator.lua @@ -0,0 +1,27 @@ + +local TableIterator = {} + +function TableIterator:create(table) + local iterator = {}; + iterator.index = 0; + iterator.table = table; + + function iterator:clone() + return TableIterator:create(table) + end + + function iterator:next() + self.index = self.index + 1 + return self.table[self.index] + end + + function iterator:prev() + self.index = self.index - 1 + return self.table[self.index] + end + + return iterator +end + + +return TableIterator \ No newline at end of file diff --git a/lua/widgets.lua b/lua/widgets.lua index 0aac7705..20f0cd2a 100644 --- a/lua/widgets.lua +++ b/lua/widgets.lua @@ -361,7 +361,7 @@ function widgets.InfiniteList(parent, iterator, opts) end for idx = 0, 8 do - local val = fwd_iterator() + local val = fwd_iterator:next() if not val then break end -- cgit v1.2.3 From 10ba00951be79d843c560e4199ac8325f3315f72 Mon Sep 17 00:00:00 2001 From: Sam Date: Sat, 1 Feb 2025 17:26:23 +0000 Subject: Remove unused imports --- lua/playlist_browser.lua | 5 ----- 1 file changed, 5 deletions(-) (limited to 'lua') diff --git a/lua/playlist_browser.lua b/lua/playlist_browser.lua index da50f4c8..d29899ad 100644 --- a/lua/playlist_browser.lua +++ b/lua/playlist_browser.lua @@ -4,17 +4,12 @@ local lvgl = require("lvgl") local widgets = require("widgets") -local database = require("database") -local sd_card = require("sd_card") local backstack = require("backstack") -local browser = require("browser") local playing = require("playing") -local styles = require("styles") local filesystem = require("filesystem") local screen = require("screen") local font = require("font") local theme = require("theme") -local img = require("images") local playback = require("playback") local queue = require("queue") local table_iterator = require("table_iterator") -- cgit v1.2.3 From 8b12310990bbf03835bd910070841977cd57d22f Mon Sep 17 00:00:00 2001 From: Rockwell Schrock Date: Sat, 1 Feb 2025 10:15:39 -0500 Subject: On the playing screen, show "Not Playing" when the queue is empty --- lua/playing.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/playing.lua b/lua/playing.lua index 08cdaaa2..9391a85c 100644 --- a/lua/playing.lua +++ b/lua/playing.lua @@ -276,7 +276,7 @@ return screen:new { if queue.loading:get() then title:set { text = "Loading..." } else - title:set{text=""} + title:set{ text = "Not Playing" } end album:set{text=""} artist:set{text=""} -- cgit v1.2.3 From 15806716c57d78f3b43ff85caa72b83f6057dfc9 Mon Sep 17 00:00:00 2001 From: Rockwell Schrock Date: Sat, 1 Feb 2025 09:42:18 -0500 Subject: Autofocus the first index on the main menu --- lua/main_menu.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'lua') diff --git a/lua/main_menu.lua b/lua/main_menu.lua index cc7874d7..3b512d72 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -56,7 +56,6 @@ return widgets.MenuScreen:new { now_playing:onClicked(function() backstack.push(playing:new()) end) - local has_focus = false local track_duration = nil self.bindings = self.bindings + { @@ -72,7 +71,6 @@ return widgets.MenuScreen:new { now_playing:add_flag(lvgl.FLAG.HIDDEN) return else - has_focus = true now_playing:clear_flag(lvgl.FLAG.HIDDEN) end title:set { text = track.title } @@ -140,6 +138,10 @@ return widgets.MenuScreen:new { local function hide_no_indexes() no_indexes_container:add_flag(lvgl.FLAG.HIDDEN) indexes_list:clear_flag(lvgl.FLAG.HIDDEN) + + if indexes[1] then + indexes[1].object:focus() + end end local function update_visible_indexes() -- cgit v1.2.3 From 281518eb58d91f4354912c0ef62ce67ecef9ee87 Mon Sep 17 00:00:00 2001 From: Rockwell Schrock Date: Sat, 1 Feb 2025 10:47:09 -0500 Subject: Autofocus controls in settings screens --- lua/settings.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/settings.lua b/lua/settings.lua index c0e7c23e..4f1e36f8 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -93,6 +93,7 @@ settings.BluetoothSettings = SettingsScreen:new { local enabled = enable_sw:enabled() bluetooth.enabled:set(enabled) end) + enable_sw:focus() self.bindings = self.bindings + { bluetooth.enabled:bind(function(en) @@ -232,6 +233,7 @@ settings.HeadphonesSettings = SettingsScreen:new { local selection = volume_chooser:get('selected') + 1 volume.limit_db:set(limits[selection]) end) + volume_chooser:focus() theme.set_subject(self.content:Label { text = "Left/Right balance", @@ -304,6 +306,7 @@ settings.DisplaySettings = SettingsScreen:new { brightness:onevent(lvgl.EVENT.VALUE_CHANGED, function() display.brightness:set(brightness:value()) end) + brightness:focus() self.bindings = self.bindings + { display.brightness:bind(function(b) @@ -372,6 +375,8 @@ settings.ThemeSettings = SettingsScreen:new { backstack.reset(main_menu:new()) end end) + + theme_chooser:focus() end } @@ -419,6 +424,8 @@ settings.InputSettings = SettingsScreen:new { controls.scheme:set(scheme) end) + controls_chooser:focus() + theme.set_subject(self.content:Label { text = "Scroll Sensitivity", }, "settings_title") @@ -483,6 +490,7 @@ settings.MassStorageSettings = SettingsScreen:new { end bind_switch() end) + enable_sw:focus() self.bindings = self.bindings + { usb.msc_enabled:bind(bind_switch), @@ -560,6 +568,7 @@ settings.DatabaseSettings = SettingsScreen:new { update:onClicked(function() database.update() end) + update:focus() self.bindings = self.bindings + { database.auto_update:bind(function(en) @@ -841,10 +850,11 @@ settings.Root = widgets.MenuScreen:new { end) end item:add_style(styles.list_item) + return item end local audio_section = section("Audio") - submenu("Bluetooth", settings.BluetoothSettings, audio_section) + local first_item = submenu("Bluetooth", settings.BluetoothSettings, audio_section) submenu("Headphones", settings.HeadphonesSettings) section("Interface") @@ -863,6 +873,8 @@ settings.Root = widgets.MenuScreen:new { submenu("Firmware", settings.FirmwareSettings) submenu("Licenses", settings.LicensesScreen) submenu("Regulatory", settings.RegulatoryScreen) + + first_item:focus() end } -- cgit v1.2.3 From 1d485c97b0c03577a40b34fb762c76e98f417fa4 Mon Sep 17 00:00:00 2001 From: Tess Eisenberger Date: Sat, 1 Feb 2025 16:15:17 -0800 Subject: Add optional support for changing volume while locked This adds a new Controls setting for adjusting the behavior when locked, and an option for allowing volume control. --- lua/settings.lua | 78 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 32 deletions(-) (limited to 'lua') diff --git a/lua/settings.lua b/lua/settings.lua index c0e7c23e..6386b468 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -380,44 +380,58 @@ settings.InputSettings = SettingsScreen:new { create_ui = function(self) SettingsScreen.create_ui(self) - theme.set_subject(self.content:Label { - text = "Control scheme", - }, "settings_title") + -- Use the control scheme enum lists to generate the relevant dropdowns + local make_scheme_control = function(self, scheme_list, control_scheme) + local option_to_scheme = {} + local scheme_to_option = {} + local option_idx = 0 + local options = "" + + -- Sort the keys to order the dropdowns the same as the enums + keys = {} + for i in pairs(scheme_list) do table.insert(keys, i) end + table.sort(keys) + + for i, k in pairs(keys) do + v = scheme_list[k] + + option_to_scheme[option_idx] = k + scheme_to_option[k] = option_idx + if option_idx > 0 then + options = options .. "\n" + end + options = options .. v + option_idx = option_idx + 1 + end - local schemes = controls.schemes() - local option_to_scheme = {} - local scheme_to_option = {} + local controls_chooser = self.content:Dropdown { + options = options, + symbol = img.chevron, + } - local option_idx = 0 - local options = "" + self.bindings = self.bindings + { + control_scheme:bind(function(s) + local option = scheme_to_option[s] + controls_chooser:set({ selected = option }) + end) + } - for i, v in pairs(schemes) do - option_to_scheme[option_idx] = i - scheme_to_option[i] = option_idx - if option_idx > 0 then - options = options .. "\n" - end - options = options .. v - option_idx = option_idx + 1 + controls_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function() + local option = controls_chooser:get('selected') + local scheme = option_to_scheme[option] + control_scheme:set(scheme) + end) end - local controls_chooser = self.content:Dropdown { - options = options, - symbol = img.chevron, - } - - self.bindings = self.bindings + { - controls.scheme:bind(function(s) - local option = scheme_to_option[s] - controls_chooser:set({ selected = option }) - end) - } + theme.set_subject(self.content:Label { + text = "Control scheme", + }, "settings_title") + make_scheme_control(self, controls.schemes(), controls.scheme) - controls_chooser:onevent(lvgl.EVENT.VALUE_CHANGED, function() - local option = controls_chooser:get('selected') - local scheme = option_to_scheme[option] - controls.scheme:set(scheme) - end) + theme.set_subject(self.content:Label { + text = "Control scheme when locked", + }, "settings_title") + make_scheme_control(self, controls.locked_schemes(), controls.locked_scheme) theme.set_subject(self.content:Label { text = "Scroll Sensitivity", -- cgit v1.2.3 From 844b3f733ec30eff41c3b3d48c74561d7b11da8e Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 3 Feb 2025 20:13:23 +0000 Subject: Use Playlist subdirectory Target /Playlists, display and browse sub directories and playlists within --- lua/main_menu.lua | 1 + lua/playlist_browser.lua | 48 +++++++++++++++++++++++++++++++++++------------- 2 files changed, 36 insertions(+), 13 deletions(-) (limited to 'lua') diff --git a/lua/main_menu.lua b/lua/main_menu.lua index 80d5b599..c8edf766 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -135,6 +135,7 @@ return widgets.MenuScreen:new { playlist_btn:onClicked(function() backstack.push(require("playlist_browser"):new { title = "Playlists", + iterator = filesystem.iterator("/Playlists") }) end) playlist_btn:add_style(styles.list_item) diff --git a/lua/playlist_browser.lua b/lua/playlist_browser.lua index d29899ad..4824b581 100644 --- a/lua/playlist_browser.lua +++ b/lua/playlist_browser.lua @@ -13,6 +13,7 @@ local theme = require("theme") local playback = require("playback") local queue = require("queue") local table_iterator = require("table_iterator") +local img = require("images") return screen:new { @@ -59,28 +60,49 @@ return screen:new { } end - local playlists = {} - -- Find playlists - local fs_iter = filesystem.iterator("") - for item in fs_iter do + local is_playlist = function(item) + return item:filepath():match("%.playlist$") + or item:filepath():match("%.m3u8?$") + end + + local get_icon_func = function(item) + if item:is_directory() then + return img.files + else + return img.enqueue + end + end + + local playlists_and_dirs = {}; + for item in self.iterator do if - item:filepath():match("%.playlist$") or - item:filepath():match("%.m3u8?$") then - table.insert(playlists, item) + is_playlist(item) or + item:is_directory() then + table.insert(playlists_and_dirs, item) end end - widgets.InfiniteList(self.root, table_iterator:create(playlists), { + widgets.InfiniteList(self.root, table_iterator:create(playlists_and_dirs), { focus_first_item = true, + get_icon = get_icon_func, callback = function(item) return function() - queue.open_playlist(item:filepath()) - playback.playing:set(true) - backstack.push(playing:new()) + if item:is_directory() then + backstack.push( + require("playlist_browser"):new { + title = self.title, + iterator = filesystem.iterator(item:filepath()), + breadcrumb = item:filepath() + }) + elseif + is_playlist(item) then + -- TODO: playlist viewer + queue.open_playlist(item:filepath()) + playback.playing:set(true) + backstack.push(playing:new()) + end end end }) end } - - -- cgit v1.2.3 From 813db15da84ee82066564b51f83be451cf121a00 Mon Sep 17 00:00:00 2001 From: ailurux Date: Tue, 4 Feb 2025 14:00:32 +1100 Subject: Fix merge issue breaking control settings screen --- lua/settings.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lua') diff --git a/lua/settings.lua b/lua/settings.lua index 74bd2103..aae6db99 100644 --- a/lua/settings.lua +++ b/lua/settings.lua @@ -426,12 +426,14 @@ settings.InputSettings = SettingsScreen:new { local scheme = option_to_scheme[option] control_scheme:set(scheme) end) + + return controls_chooser end theme.set_subject(self.content:Label { text = "Control scheme", }, "settings_title") - make_scheme_control(self, controls.schemes(), controls.scheme) + local controls_chooser = make_scheme_control(self, controls.schemes(), controls.scheme) theme.set_subject(self.content:Label { text = "Control scheme when locked", -- cgit v1.2.3 From ff733e8f0c827e3d2d91bb7db29a85807867ab5e Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 4 Feb 2025 21:13:52 +0000 Subject: Wrap filesystem iterator Change to wrapping the filesystem iterator rather than iterating over table values. Also centralise the is_playlist check and hide Playlists menu if none are present --- lua/file_browser.lua | 5 ++--- lua/main_menu.lua | 16 +++++++++++++++- lua/playlist_browser.lua | 20 +++----------------- lua/playlist_iterator.lua | 35 +++++++++++++++++++++++++++++++++++ lua/table_iterator.lua | 27 --------------------------- 5 files changed, 55 insertions(+), 48 deletions(-) create mode 100644 lua/playlist_iterator.lua delete mode 100644 lua/table_iterator.lua (limited to 'lua') diff --git a/lua/file_browser.lua b/lua/file_browser.lua index 98261d55..6289828f 100644 --- a/lua/file_browser.lua +++ b/lua/file_browser.lua @@ -8,11 +8,11 @@ local backstack = require("backstack") local font = require("font") local queue = require("queue") local playing = require("playing") -local styles = require("styles") local playback = require("playback") local theme = require("theme") local screen = require("screen") local filesystem = require("filesystem") +local playlist_iterator = require("playlist_iterator") return screen:new { create_ui = function(self) @@ -70,8 +70,7 @@ return screen:new { breadcrumb = item:filepath() }) elseif - item:filepath():match("%.playlist$") or - item:filepath():match("%.m3u8?$") then + playlist_iterator:is_playlist(item) then queue.open_playlist(item:filepath()) playback.playing:set(true) backstack.push(playing:new()) diff --git a/lua/main_menu.lua b/lua/main_menu.lua index c8edf766..fdf11956 100644 --- a/lua/main_menu.lua +++ b/lua/main_menu.lua @@ -11,7 +11,6 @@ local browser = require("browser") local playing = require("playing") local styles = require("styles") local filesystem = require("filesystem") -local screen = require("screen") local font = require("font") local theme = require("theme") local img = require("images") @@ -151,6 +150,14 @@ return widgets.MenuScreen:new { indexes_list:clear_flag(lvgl.FLAG.HIDDEN) end + local function hide_playlist_listing() + playlist_btn:add_flag(lvgl.FLAG.HIDDEN) + end + + local function show_playlist_listing() + playlist_btn:clear_flag(lvgl.FLAG.HIDDEN) + end + local function update_visible_indexes() local has_valid_index = false for _, idx in ipairs(indexes) do @@ -164,6 +171,13 @@ return widgets.MenuScreen:new { end if has_valid_index then hide_no_indexes() + + -- If we have valid indexes, then also check for playlists + if filesystem.iterator("/Playlists/"):next() == nil then + hide_playlist_listing() + else + show_playlist_listing() + end else if require("database").updating:get() then show_no_indexes("The database is updating for the first time. Please wait.") diff --git a/lua/playlist_browser.lua b/lua/playlist_browser.lua index 4824b581..0339d59b 100644 --- a/lua/playlist_browser.lua +++ b/lua/playlist_browser.lua @@ -12,7 +12,7 @@ local font = require("font") local theme = require("theme") local playback = require("playback") local queue = require("queue") -local table_iterator = require("table_iterator") +local playlist_iterator = require("playlist_iterator") local img = require("images") @@ -60,11 +60,6 @@ return screen:new { } end - local is_playlist = function(item) - return item:filepath():match("%.playlist$") - or item:filepath():match("%.m3u8?$") - end - local get_icon_func = function(item) if item:is_directory() then return img.files @@ -73,16 +68,7 @@ return screen:new { end end - local playlists_and_dirs = {}; - for item in self.iterator do - if - is_playlist(item) or - item:is_directory() then - table.insert(playlists_and_dirs, item) - end - end - - widgets.InfiniteList(self.root, table_iterator:create(playlists_and_dirs), { + widgets.InfiniteList(self.root, playlist_iterator:create(self.iterator), { focus_first_item = true, get_icon = get_icon_func, callback = function(item) @@ -95,7 +81,7 @@ return screen:new { breadcrumb = item:filepath() }) elseif - is_playlist(item) then + playlist_iterator:is_playlist(item) then -- TODO: playlist viewer queue.open_playlist(item:filepath()) playback.playing:set(true) diff --git a/lua/playlist_iterator.lua b/lua/playlist_iterator.lua new file mode 100644 index 00000000..06e80ad2 --- /dev/null +++ b/lua/playlist_iterator.lua @@ -0,0 +1,35 @@ +local PlaylistIterator = {} + +function PlaylistIterator:is_playlist(item) + return item:filepath():match("%.playlist$") + or item:filepath():match("%.m3u8?$") +end + +function PlaylistIterator:create(fs_iterator) + local iterator = fs_iterator:clone() + local obj = {}; + + local find_matching = function(iterate_fn) + local next = iterate_fn(iterator); + while next and (not PlaylistIterator:is_playlist(next) and not next:is_directory()) do + next = iterate_fn(); + end + return next; + end + + function obj:clone() + return PlaylistIterator:create(iterator) + end + + function obj:next() + return find_matching(iterator.next) + end + + function obj:prev() + return find_matching(iterator.prev) + end + + return obj +end + +return PlaylistIterator diff --git a/lua/table_iterator.lua b/lua/table_iterator.lua deleted file mode 100644 index 5bacada6..00000000 --- a/lua/table_iterator.lua +++ /dev/null @@ -1,27 +0,0 @@ - -local TableIterator = {} - -function TableIterator:create(table) - local iterator = {}; - iterator.index = 0; - iterator.table = table; - - function iterator:clone() - return TableIterator:create(table) - end - - function iterator:next() - self.index = self.index + 1 - return self.table[self.index] - end - - function iterator:prev() - self.index = self.index - 1 - return self.table[self.index] - end - - return iterator -end - - -return TableIterator \ No newline at end of file -- cgit v1.2.3 From db6239de60fba1f76e3d438c53f2e30bf1135638 Mon Sep 17 00:00:00 2001 From: River Tae Smith <22485304+r-tae@users.noreply.github.com> Date: Wed, 5 Feb 2025 12:41:25 +1100 Subject: Update to latest version of fusion12 and build it like 10px --- lua/fonts/fusion12 | Bin 615260 -> 655932 bytes 1 file changed, 0 insertions(+), 0 deletions(-) (limited to 'lua') diff --git a/lua/fonts/fusion12 b/lua/fonts/fusion12 index 3745c17d..c5380a47 100644 Binary files a/lua/fonts/fusion12 and b/lua/fonts/fusion12 differ -- cgit v1.2.3 From 9ecb79a264daa7896ce7d5a65592c05631213d5a Mon Sep 17 00:00:00 2001 From: ailurux Date: Wed, 5 Feb 2025 16:33:05 +1100 Subject: Add smaller icons for playlists and directory files --- lua/images.lua | 2 ++ lua/img/file_icons/directory.png | Bin 0 -> 7848 bytes lua/img/file_icons/playlist.png | Bin 0 -> 6832 bytes lua/playlist_browser.lua | 4 ++-- 4 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 lua/img/file_icons/directory.png create mode 100644 lua/img/file_icons/playlist.png (limited to 'lua') diff --git a/lua/images.lua b/lua/images.lua index b10d0f74..69bd8e4b 100644 --- a/lua/images.lua +++ b/lua/images.lua @@ -29,6 +29,8 @@ local img = { unlistened = lvgl.ImgData("//lua/img/unlistened.png"), info = lvgl.ImgData("//lua/img/info.png"), menu = lvgl.ImgData("//lua/img/menu.png"), + file_directory = lvgl.ImgData("//lua/img/file_icons/directory.png"), + file_playlist = lvgl.ImgData("//lua/img/file_icons/playlist.png"), } return img diff --git a/lua/img/file_icons/directory.png b/lua/img/file_icons/directory.png new file mode 100644 index 00000000..32624415 Binary files /dev/null and b/lua/img/file_icons/directory.png differ diff --git a/lua/img/file_icons/playlist.png b/lua/img/file_icons/playlist.png new file mode 100644 index 00000000..4787d59c Binary files /dev/null and b/lua/img/file_icons/playlist.png differ diff --git a/lua/playlist_browser.lua b/lua/playlist_browser.lua index 0339d59b..8854a19f 100644 --- a/lua/playlist_browser.lua +++ b/lua/playlist_browser.lua @@ -62,9 +62,9 @@ return screen:new { local get_icon_func = function(item) if item:is_directory() then - return img.files + return img.file_directory else - return img.enqueue + return img.file_playlist end end -- cgit v1.2.3