summaryrefslogtreecommitdiff
path: root/lua/playlist_browser.lua
blob: d29899adbfaf2fbac4649ec2a5d84d659a5c0973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
-- 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 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
}