Added listened indicator for audiobooks and podcasts

custom
ailurux 7 months ago
parent f8a6c8c85a
commit 3490cceb6b
  1. 25
      lua/browser.lua
  2. 2
      lua/images.lua
  3. BIN
      lua/img/listened.png
  4. BIN
      lua/img/unlistened.png
  5. 1
      lua/main_menu.lua
  6. 6
      lua/theme_dark.lua
  7. 8
      lua/theme_hicon.lua
  8. 10
      lua/theme_light.lua
  9. 6
      lua/widgets.lua
  10. 3
      luals-stubs/database.lua
  11. 2
      src/tangara/database/index.cpp
  12. 18
      src/tangara/lua/lua_database.cpp

@ -9,6 +9,7 @@ local playback = require("playback")
local theme = require("theme") local theme = require("theme")
local screen = require("screen") local screen = require("screen")
local database = require("database") local database = require("database")
local img = require("images")
return screen:new{ return screen:new{
create_ui = function(self) create_ui = function(self)
@ -54,6 +55,7 @@ return screen:new{
} }
end end
if (self.mediatype == database.MediaTypes.Music) then
local buttons = header:Object({ local buttons = header:Object({
flex = { flex = {
flex_direction = "row", flex_direction = "row",
@ -89,8 +91,30 @@ return screen:new{
playback.playing:set(true) playback.playing:set(true)
backstack.push(playing:new()) backstack.push(playing:new())
end) end)
end
local get_icon_func = nil
local show_listened = self.mediatype == database.MediaTypes.Audiobook or self.mediatype == database.MediaTypes.Podcast
if show_listened then
get_icon_func = function (item)
local contents = item:contents()
if type(contents) == "userdata" then
return
else
local track = database.track_by_id(contents)
if not track then return end
if (track.play_count > 0) then
return img.listened
else
return img.unlistened
end
end
end
end
widgets.InfiniteList(self.root, self.iterator, { widgets.InfiniteList(self.root, self.iterator, {
get_icon = get_icon_func,
callback = function(item) callback = function(item)
return function() return function()
local contents = item:contents() local contents = item:contents()
@ -98,6 +122,7 @@ return screen:new{
backstack.push(require("browser"):new{ backstack.push(require("browser"):new{
title = self.title, title = self.title,
iterator = contents, iterator = contents,
mediatype = self.mediatype,
breadcrumb = tostring(item) breadcrumb = tostring(item)
}) })
else else

@ -17,6 +17,8 @@ local img = {
settings = lvgl.ImgData("//lua/img/settings.png"), settings = lvgl.ImgData("//lua/img/settings.png"),
chevron = lvgl.ImgData("//lua/img/chevron.png"), chevron = lvgl.ImgData("//lua/img/chevron.png"),
usb = lvgl.ImgData("//lua/img/usb.png"), usb = lvgl.ImgData("//lua/img/usb.png"),
listened = lvgl.ImgData("//lua/img/listened.png"),
unlistened = lvgl.ImgData("//lua/img/unlistened.png"),
} }
return img return img

Binary file not shown.

After

Width:  |  Height:  |  Size: 595 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

@ -117,6 +117,7 @@ return widgets.MenuScreen:new {
backstack.push(browser:new { backstack.push(browser:new {
title = tostring(idx), title = tostring(idx),
iterator = idx:iter(), iterator = idx:iter(),
mediatype = idx:type(),
}) })
end) end)
btn:add_style(styles.list_item) btn:add_style(styles.list_item)

@ -55,6 +55,12 @@ local theme_dark = {
}}, }},
}, },
listbutton = { listbutton = {
{lvgl.PART.MAIN, lvgl.Style {
image_recolor_opa = 255,
image_recolor = text_color,
flex_cross_place = lvgl.FLEX_ALIGN.CENTER,
pad_column = 4,
}},
{lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style { {lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style {
bg_opa = lvgl.OPA(100), bg_opa = lvgl.OPA(100),
bg_color = highlight_color, bg_color = highlight_color,

@ -61,10 +61,18 @@ local theme_hicon = {
}}, }},
}, },
listbutton = { listbutton = {
{lvgl.PART.MAIN, lvgl.Style {
image_recolor_opa = 255,
image_recolor = text_color,
flex_cross_place = lvgl.FLEX_ALIGN.CENTER,
pad_column = 4,
}},
{lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style { {lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style {
bg_opa = lvgl.OPA(100), bg_opa = lvgl.OPA(100),
bg_color = text_color, bg_color = text_color,
text_color = background_color, text_color = background_color,
image_recolor_opa = 255,
image_recolor = background_color,
}}, }},
}, },
bar = { bar = {

@ -63,10 +63,18 @@ local theme_light = {
}}, }},
}, },
listbutton = { listbutton = {
{lvgl.PART.MAIN, lvgl.Style {
image_recolor_opa = 255,
image_recolor = text_color,
flex_cross_place = lvgl.FLEX_ALIGN.CENTER,
pad_column = 4,
}},
{lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style { {lvgl.PART.MAIN | lvgl.STATE.FOCUSED, lvgl.Style {
bg_opa = lvgl.OPA(100), bg_opa = lvgl.OPA(100),
bg_color = highlight_color, bg_color = highlight_color,
text_color = "#ffffff" text_color = "#ffffff",
image_recolor_opa = 255,
image_recolor = "#ffffff",
}}, }},
}, },
bar = { bar = {

@ -313,7 +313,11 @@ function widgets.InfiniteList(parent, iterator, opts)
add_to_top = true add_to_top = true
end end
if this_item > last_index then last_index = index end if this_item > last_index then last_index = index end
local btn = infinite_list.root:add_btn(nil, tostring(item)) local icon = nil
if opts.get_icon then
icon = opts.get_icon(item)
end
local btn = infinite_list.root:add_btn(icon, tostring(item))
if add_to_top then if add_to_top then
btn:move_to_index(0) btn:move_to_index(0)
end end

@ -67,6 +67,9 @@ local Index = {}
--- @return string --- @return string
function Index:name() end function Index:name() end
--- Returns the media type of this index
function Index:type() end
--- Returns a new iterator that can be used to access every record within the --- Returns a new iterator that can be used to access every record within the
--- first level of this index. --- first level of this index.
--- @return Iterator it An iterator that yields `Record`s. --- @return Iterator it An iterator that yields `Record`s.

@ -60,7 +60,7 @@ const IndexInfo kPodcasts{
.id = 5, .id = 5,
.type = MediaType::kPodcast, .type = MediaType::kPodcast,
.name = "Podcasts", .name = "Podcasts",
.components = {Tag::kTitle}, .components = {Tag::kAlbum, Tag::kTitle},
}; };
const IndexInfo kAudiobooks{ const IndexInfo kAudiobooks{

@ -388,6 +388,24 @@ static auto lua_database(lua_State* state) -> int {
luaL_setfuncs(state, kDbRecordFuncs, 0); luaL_setfuncs(state, kDbRecordFuncs, 0);
luaL_newlib(state, kDatabaseFuncs); luaL_newlib(state, kDatabaseFuncs);
lua_pushliteral(state, "MediaTypes");
lua_newtable(state);
lua_pushliteral(state, "Unknown");
lua_pushinteger(state, (int)database::MediaType::kUnknown);
lua_rawset(state, -3);
lua_pushliteral(state, "Music");
lua_pushinteger(state, (int)database::MediaType::kMusic);
lua_rawset(state, -3);
lua_pushliteral(state, "Podcast");
lua_pushinteger(state, (int)database::MediaType::kPodcast);
lua_rawset(state, -3);
lua_pushliteral(state, "Audiobook");
lua_pushinteger(state, (int)database::MediaType::kAudiobook);
lua_rawset(state, -3);
lua_rawset(state, -3);
return 1; return 1;
} }

Loading…
Cancel
Save