summaryrefslogtreecommitdiff
path: root/lua/playlist_browser.lua
diff options
context:
space:
mode:
authorrdsh <rdsh@noreply.codeberg.org>2025-02-05 21:57:45 +0000
committerrdsh <rdsh@noreply.codeberg.org>2025-02-05 21:57:45 +0000
commit2ec84a1393331f57f8402bce66d337c0dd255f64 (patch)
tree30f271bf10988a9717abdf266d135e3ec0ae2d31 /lua/playlist_browser.lua
parentddcd06dbca61fc55a7c2cd68f82f8cfe7b4c5cbf (diff)
parent9ecb79a264daa7896ce7d5a65592c05631213d5a (diff)
downloadtangara-fw-2ec84a1393331f57f8402bce66d337c0dd255f64.tar.gz
Merge pull request 'main' (#1) from cool-tech-zone/tangara-fw:main into main
Reviewed-on: https://codeberg.org/rdsh/tangara-fw/pulls/1
Diffstat (limited to 'lua/playlist_browser.lua')
-rw-r--r--lua/playlist_browser.lua94
1 files changed, 94 insertions, 0 deletions
diff --git a/lua/playlist_browser.lua b/lua/playlist_browser.lua
new file mode 100644
index 00000000..8854a19f
--- /dev/null
+++ b/lua/playlist_browser.lua
@@ -0,0 +1,94 @@
+-- SPDX-FileCopyrightText: 2025 Sam Lord <code@samlord.co.uk>
+--
+-- SPDX-License-Identifier: GPL-3.0-only
+
+local lvgl = require("lvgl")
+local widgets = require("widgets")
+local backstack = require("backstack")
+local playing = require("playing")
+local filesystem = require("filesystem")
+local screen = require("screen")
+local font = require("font")
+local theme = require("theme")
+local playback = require("playback")
+local queue = require("queue")
+local playlist_iterator = require("playlist_iterator")
+local img = require("images")
+
+
+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 get_icon_func = function(item)
+ if item:is_directory() then
+ return img.file_directory
+ else
+ return img.file_playlist
+ end
+ end
+
+ widgets.InfiniteList(self.root, playlist_iterator:create(self.iterator), {
+ focus_first_item = true,
+ get_icon = get_icon_func,
+ callback = function(item)
+ return function()
+ if item:is_directory() then
+ backstack.push(
+ require("playlist_browser"):new {
+ title = self.title,
+ iterator = filesystem.iterator(item:filepath()),
+ breadcrumb = item:filepath()
+ })
+ elseif
+ playlist_iterator:is_playlist(item) then
+ -- TODO: playlist viewer
+ queue.open_playlist(item:filepath())
+ playback.playing:set(true)
+ backstack.push(playing:new())
+ end
+ end
+ end
+ })
+ end
+}