Hide database indexes that do not contain any tracks

custom
jacqueline 7 months ago
parent e91580c75b
commit ec4fb715d0
  1. 103
      lua/main_menu.lua

@ -1,6 +1,7 @@
local lvgl = require("lvgl") local lvgl = require("lvgl")
local widgets = require("widgets") local widgets = require("widgets")
local database = require("database") local database = require("database")
local sd_card = require("sd_card")
local backstack = require("backstack") local backstack = require("backstack")
local browser = require("browser") local browser = require("browser")
local playing = require("playing") local playing = require("playing")
@ -89,44 +90,86 @@ return widgets.MenuScreen:new {
-- Next, a list showing the user's prefer's music source. This defaults to -- Next, a list showing the user's prefer's music source. This defaults to
-- a list of all available database indexes, but could also be the contents -- a list of all available database indexes, but could also be the contents
-- of the SD card root. -- of the SD card root.
local no_indexes_container = self.root:Object {
w = lvgl.PCT(100),
flex_grow = 1,
}
local no_indexes_label = no_indexes_container:Label {
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
text_align = 2,
long_mode = 0,
margin_all = 4,
text = "",
}
no_indexes_label:center()
if require("sd_card").mounted:get() then local indexes_list = lvgl.List(self.root, {
local list = lvgl.List(self.root, { w = lvgl.PCT(100),
w = lvgl.PCT(100), h = lvgl.PCT(100),
h = lvgl.PCT(100), flex_grow = 1,
flex_grow = 1, })
local indexes = {}
for _, idx in ipairs(database.indexes()) do
local btn = indexes_list:add_btn(nil, tostring(idx))
btn:onClicked(function()
backstack.push(browser:new {
title = tostring(idx),
iterator = idx:iter(),
})
end)
btn:add_style(styles.list_item)
table.insert(indexes, {
object = btn,
index = idx,
}) })
end
local function show_no_indexes(msg)
indexes_list:add_flag(lvgl.FLAG.HIDDEN)
no_indexes_container:clear_flag(lvgl.FLAG.HIDDEN)
no_indexes_label:set { text = msg }
end
local indexes = database.indexes() local function hide_no_indexes()
no_indexes_container:add_flag(lvgl.FLAG.HIDDEN)
indexes_list:clear_flag(lvgl.FLAG.HIDDEN)
end
local function update_visible_indexes()
local has_valid_index = false
for _, idx in ipairs(indexes) do for _, idx in ipairs(indexes) do
local btn = list:add_btn(nil, tostring(idx)) local it = idx.index:iter():next()
btn:onClicked(function() if it then
backstack.push(browser:new { has_valid_index = true
title = tostring(idx), idx.object:clear_flag(lvgl.FLAG.HIDDEN)
iterator = idx:iter(), else
}) idx.object:add_flag(lvgl.FLAG.HIDDEN)
end) end
btn:add_style(styles.list_item) end
if not has_focus then if has_valid_index then
has_focus = true hide_no_indexes()
btn:focus() else
if require("database").updating:get() then
show_no_indexes("The database is updating for the first time. Please wait.")
else
show_no_indexes("No compatible media was found on your SD Card.")
end end
end end
else
local container = self.root:Object {
w = lvgl.PCT(100),
flex_grow = 1,
}
container:Label {
w = lvgl.PCT(100),
h = lvgl.SIZE_CONTENT,
text_align = 2,
long_mode = 0,
margin_all = 4,
text = "SD Card is not inserted or could not be opened.",
}:center();
end end
self.bindings = self.bindings + {
database.updating:bind(function()
update_visible_indexes()
end),
sd_card.mounted:bind(function(mounted)
if not mounted then
show_no_indexes("SD Card is not inserted or could not be opened.")
end
end),
}
-- Finally, the bottom bar with icon buttons for other device features. -- Finally, the bottom bar with icon buttons for other device features.
local bottom_bar = lvgl.Object(self.root, { local bottom_bar = lvgl.Object(self.root, {

Loading…
Cancel
Save