begin the refactoring - doesnt compile

This commit is contained in:
Drew Weymouth
2023-05-14 19:31:04 -07:00
parent 0ebbf621b1
commit 85042fcbd4
23 changed files with 183 additions and 747 deletions
+6 -6
View File
@@ -7,6 +7,7 @@ import (
"time"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/player"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
@@ -15,7 +16,6 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
type BottomPanel struct {
@@ -69,7 +69,7 @@ func NewBottomPanel(p *player.Player, contr *controller.Controller) *BottomPanel
contr.NavigateTo(controller.AlbumRoute(bp.playbackManager.NowPlaying().AlbumID))
})
bp.NowPlaying.OnArtistNameTapped(func() {
contr.NavigateTo(controller.ArtistRoute(bp.playbackManager.NowPlaying().ArtistID))
contr.NavigateTo(controller.ArtistRoute(bp.playbackManager.NowPlaying().ArtistIDs[0]))
})
bp.NowPlaying.OnTrackNameTapped(func() {
contr.NavigateTo(controller.NowPlayingRoute(bp.playbackManager.NowPlaying().ID))
@@ -108,11 +108,11 @@ func (bp *BottomPanel) SetPlaybackManager(pm *backend.PlaybackManager) {
})
}
func (bp *BottomPanel) onSongChange(song *subsonic.Child, _ *subsonic.Child) {
func (bp *BottomPanel) onSongChange(song, _ *mediaprovider.Track) {
if song == nil {
bp.NowPlaying.Update("", "", false, "", nil)
} else {
bp.coverArtID = song.CoverArt
bp.coverArtID = song.CoverArtID
var im image.Image
if bp.ImageManager != nil {
// set image to expire not long after the length of the song
@@ -120,9 +120,9 @@ func (bp *BottomPanel) onSongChange(song *subsonic.Child, _ *subsonic.Child) {
// be in cache for the next song if it's from the same album, or
// if the user navigates to the album page for the track
imgTTLSec := song.Duration + 30
im, _ = bp.ImageManager.GetCoverThumbnailWithTTL(song.CoverArt, time.Duration(imgTTLSec)*time.Second)
im, _ = bp.ImageManager.GetCoverThumbnailWithTTL(song.CoverArtID, time.Duration(imgTTLSec)*time.Second)
}
bp.NowPlaying.Update(song.Title, song.Artist, song.ArtistID != "", song.Album, im)
bp.NowPlaying.Update(song.Name, song.ArtistNames[0], song.ArtistIDs[0] != "", song.Album, im)
}
}
+21 -25
View File
@@ -5,6 +5,7 @@ import (
"log"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
@@ -17,8 +18,6 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
type AlbumPage struct {
@@ -92,11 +91,11 @@ func (a *AlbumPage) Route() controller.Route {
return controller.AlbumRoute(a.albumID)
}
func (a *AlbumPage) OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
if song == nil {
func (a *AlbumPage) OnSongChange(track, lastScrobbledIfAny *mediaprovider.Track) {
if track == nil {
a.nowPlayingID = ""
} else {
a.nowPlayingID = song.ID
a.nowPlayingID = track.ID
}
a.tracklist.SetNowPlaying(a.nowPlayingID)
a.tracklist.IncrementPlayCount(sharedutil.TrackIDOrEmptyStr(lastScrobbledIfAny))
@@ -116,14 +115,14 @@ func (a *AlbumPage) SelectAll() {
// should be called asynchronously
func (a *AlbumPage) load() {
album, err := a.lm.GetAlbum(a.albumID)
album, err := a.sm.Server.GetAlbum(a.albumID)
if err != nil {
log.Printf("Failed to get album: %s", err.Error())
return
}
a.header.Update(album, a.im)
a.tracklist.ShowDiscNumber = album.Song[0].DiscNumber != album.Song[len(album.Song)-1].DiscNumber
a.tracklist.Tracks = album.Song
a.tracklist.ShowDiscNumber = album.Tracks[0].DiscNumber != album.Tracks[len(album.Tracks)-1].DiscNumber
a.tracklist.Tracks = album.Tracks
a.tracklist.SetNowPlaying(a.nowPlayingID)
}
@@ -215,20 +214,20 @@ func (a *AlbumPageHeader) CreateRenderer() fyne.WidgetRenderer {
return widget.NewSimpleRenderer(a.container)
}
func (a *AlbumPageHeader) Update(album *subsonic.AlbumID3, im *backend.ImageManager) {
func (a *AlbumPageHeader) Update(album *mediaprovider.AlbumWithTracks, im *backend.ImageManager) {
a.albumID = album.ID
a.coverID = album.CoverArt
a.artistID = album.ArtistID
a.coverID = album.CoverArtID
a.artistID = album.ArtistIDs[0]
a.titleLabel.Segments[0].(*widget.TextSegment).Text = album.Name
a.artistLabel.SetText(album.Artist)
a.genre = album.Genre
a.genreLabel.SetText(album.Genre)
a.artistLabel.SetText(album.ArtistNames[0])
a.genre = album.Genres[0]
a.genreLabel.SetText(album.Genres[0])
a.miscLabel.SetText(formatMiscLabelStr(album))
a.toggleFavButton.IsFavorited = !album.Starred.IsZero()
a.toggleFavButton.IsFavorited = album.Favorite
a.Refresh()
go func() {
if cover, err := im.GetCoverThumbnail(album.CoverArt); err == nil {
if cover, err := im.GetCoverThumbnail(album.CoverArtID); err == nil {
a.cover.Image.Image = cover
a.cover.Refresh()
} else {
@@ -238,11 +237,8 @@ func (a *AlbumPageHeader) Update(album *subsonic.AlbumID3, im *backend.ImageMana
}
func (a *AlbumPageHeader) toggleFavorited() {
if a.toggleFavButton.IsFavorited {
a.page.sm.Server.Star(subsonic.StarParameters{AlbumIDs: []string{a.albumID}})
} else {
a.page.sm.Server.Unstar(subsonic.StarParameters{AlbumIDs: []string{a.albumID}})
}
params := mediaprovider.RatingFavoriteParameters{AlbumIDs: []string{a.albumID}}
a.page.sm.Server.SetFavorite(params, a.toggleFavButton.IsFavorited)
}
func (a *AlbumPageHeader) showPopUpCover() {
@@ -254,16 +250,16 @@ func (a *AlbumPageHeader) showPopUpCover() {
a.page.contr.ShowPopUpImage(cover)
}
func formatMiscLabelStr(a *subsonic.AlbumID3) string {
func formatMiscLabelStr(a *mediaprovider.AlbumWithTracks) string {
var discs string
if discCount := a.Song[len(a.Song)-1].DiscNumber; discCount > 1 {
if discCount := a.Tracks[len(a.Tracks)-1].DiscNumber; discCount > 1 {
discs = fmt.Sprintf("%d discs · ", discCount)
}
tracks := "tracks"
if a.SongCount == 1 {
if a.TrackCount == 1 {
tracks = "track"
}
return fmt.Sprintf("%d · %d %s · %s%s", a.Year, a.SongCount, tracks, discs, util.SecondsToTimeString(float64(a.Duration)))
return fmt.Sprintf("%d · %d %s · %s%s", a.Year, a.TrackCount, tracks, discs, util.SecondsToTimeString(float64(a.Duration)))
}
func (s *albumPageState) Restore() Page {
+2 -1
View File
@@ -2,6 +2,7 @@ package browsing
import (
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/util"
@@ -29,7 +30,7 @@ type AlbumsPage struct {
searcher *widgets.SearchEntry
filterBtn *widgets.AlbumFilterButton
searchText string
filter backend.AlbumFilter
filter mediaprovider.AlbumFilter
titleDisp *widget.RichText
sortOrder *selectWidget
container *fyne.Container
+2 -1
View File
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/controller"
@@ -118,7 +119,7 @@ func (a *ArtistPage) Save() SavedPage {
var _ CanShowNowPlaying = (*ArtistPage)(nil)
func (a *ArtistPage) OnSongChange(track *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
func (a *ArtistPage) OnSongChange(track, lastScrobbledIfAny *mediaprovider.Track) {
a.nowPlayingID = sharedutil.TrackIDOrEmptyStr(track)
if a.tracklistCtr != nil {
tl := a.tracklistCtr.Objects[0].(*widgets.Tracklist)
+3 -4
View File
@@ -2,6 +2,7 @@ package browsing
import (
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
@@ -11,8 +12,6 @@ import (
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
type Page interface {
@@ -37,7 +36,7 @@ type CanSelectAll interface {
}
type CanShowNowPlaying interface {
OnSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child)
OnSongChange(song, lastScrobbledIfAny *mediaprovider.Track)
}
type BrowsingPane struct {
@@ -160,7 +159,7 @@ func (b *BrowsingPane) doSetPage(p Page) bool {
return true
}
func (b *BrowsingPane) onSongChange(song *subsonic.Child, lastScrobbledIfAny *subsonic.Child) {
func (b *BrowsingPane) onSongChange(song, lastScrobbledIfAny *mediaprovider.Track) {
if b.curPage == nil {
return
}
+8 -9
View File
@@ -4,6 +4,7 @@ import (
"log"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/controller"
"github.com/dweymouth/supersonic/ui/layouts"
myTheme "github.com/dweymouth/supersonic/ui/theme"
@@ -15,8 +16,6 @@ import (
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
type FavoritesPage struct {
@@ -216,7 +215,7 @@ func (a *FavoritesPage) OnSearched(query string) {
var _ CanShowNowPlaying = (*FavoritesPage)(nil)
func (a *FavoritesPage) OnSongChange(song *subsonic.Child, _ *subsonic.Child) {
func (a *FavoritesPage) OnSongChange(song, _ *mediaprovider.Track) {
a.nowPlayingID = ""
if song != nil {
a.nowPlayingID = song.ID
@@ -271,12 +270,12 @@ func (a *FavoritesPage) onShowFavoriteArtists() {
a.createContainer(layout.NewSpacer())
}
go func() {
s, err := a.sm.Server.GetStarred2(nil)
fav, err := a.sm.Server.GetFavorites()
if err != nil {
log.Printf("error getting starred items: %s", err.Error())
return
}
model := buildArtistListModel(s.Artist)
model := buildArtistListModel(fav.Artists)
artistList := widgets.NewArtistGenreList(model)
artistList.ShowAlbumCount = true
artistList.OnNavTo = func(artistID string) {
@@ -295,7 +294,7 @@ func (a *FavoritesPage) onShowFavoriteArtists() {
}
}
func buildArtistListModel(artists []*subsonic.ArtistID3) []widgets.ArtistGenreListItemModel {
func buildArtistListModel(artists []*mediaprovider.Artist) []widgets.ArtistGenreListItemModel {
model := make([]widgets.ArtistGenreListItemModel, 0)
for _, ar := range artists {
model = append(model, widgets.ArtistGenreListItemModel{
@@ -320,12 +319,12 @@ func (a *FavoritesPage) onShowFavoriteSongs() {
a.createContainer(layout.NewSpacer())
}
go func() {
s, err := a.sm.Server.GetStarred2(nil)
fav, err := a.sm.Server.GetFavorites()
if err != nil {
log.Printf("error getting starred items: %s", err.Error())
return
}
tracklist := widgets.NewTracklist(s.Song)
tracklist := widgets.NewTracklist(fav.Tracks)
tracklist.AutoNumber = true
tracklist.SetVisibleColumns(a.cfg.TracklistColumns)
tracklist.OnVisibleColumnsChanged = func(cols []string) {
@@ -360,7 +359,7 @@ type savedFavoritesPage struct {
lm *backend.LibraryManager
gridState widgets.GridViewState
searchGridState widgets.GridViewState
filter backend.AlbumFilter
filter mediaprovider.AlbumFilter
searchText string
activeToggleBtn int
}
+3 -3
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/res"
"github.com/dweymouth/supersonic/ui/browsing"
"github.com/dweymouth/supersonic/ui/controller"
@@ -15,7 +16,6 @@ import (
"fyne.io/fyne/v2/dialog"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
var (
@@ -81,12 +81,12 @@ func NewMainWindow(fyneApp fyne.App, appName, appVersion string, app *backend.Ap
m.container = container.NewBorder(nil, m.BottomPanel, nil, nil, m.BrowsingPane)
m.Window.SetContent(m.container)
m.Window.Resize(size)
app.PlaybackManager.OnSongChange(func(song *subsonic.Child, _ *subsonic.Child) {
app.PlaybackManager.OnSongChange(func(song, _ *mediaprovider.Track) {
if song == nil {
m.Window.SetTitle(appName)
return
}
m.Window.SetTitle(fmt.Sprintf("%s %s · %s", song.Title, song.Artist, appName))
m.Window.SetTitle(fmt.Sprintf("%s %s · %s", song.Name, song.ArtistNames[0], appName))
})
app.ServerManager.OnServerConnected(func() {
m.BrowsingPane.EnableNavigationButtons()
+3 -3
View File
@@ -9,7 +9,7 @@ import (
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/layout"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/ui/theme"
"github.com/dweymouth/supersonic/ui/util"
)
@@ -21,11 +21,11 @@ type AlbumFilterButton struct {
GenreDisabled bool
FavoriteDisabled bool
filter *backend.AlbumFilter
filter *mediaprovider.AlbumFilter
dialog *widget.PopUp
}
func NewAlbumFilterButton(filter *backend.AlbumFilter) *AlbumFilterButton {
func NewAlbumFilterButton(filter *mediaprovider.AlbumFilter) *AlbumFilterButton {
a := &AlbumFilterButton{
filter: filter,
Button: widget.Button{
+27 -32
View File
@@ -5,8 +5,8 @@ import (
"log"
"strconv"
"sync"
"time"
"github.com/dweymouth/supersonic/backend/mediaprovider"
"github.com/dweymouth/supersonic/sharedutil"
"github.com/dweymouth/supersonic/ui/layouts"
"github.com/dweymouth/supersonic/ui/os"
@@ -18,7 +18,6 @@ import (
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/theme"
"fyne.io/fyne/v2/widget"
"github.com/dweymouth/go-subsonic/subsonic"
)
const (
@@ -40,7 +39,7 @@ type Tracklist struct {
// Tracks is the set of tracks displayed by the widget.
// Direct access to this is not thread-safe but OK for
// views that only load tracks into the widget once at page load.
Tracks []*subsonic.Child
Tracks []*mediaprovider.Track
// AutoNumber sets whether to auto-number the tracks 1..N in display order,
// or to use the number from the track's metadata
@@ -60,8 +59,8 @@ type Tracklist struct {
// user action callbacks
OnPlayTrackAt func(int)
OnPlaySelection func(tracks []*subsonic.Child, shuffle bool)
OnAddToQueue func(trackIDs []*subsonic.Child)
OnPlaySelection func(tracks []*mediaprovider.Track, shuffle bool)
OnAddToQueue func(trackIDs []*mediaprovider.Track)
OnAddToPlaylist func(trackIDs []string)
OnSetFavorite func(trackIDs []string, fav bool)
OnSetRating func(trackIDs []string, rating int)
@@ -85,7 +84,7 @@ type Tracklist struct {
container *fyne.Container
}
func NewTracklist(tracks []*subsonic.Child) *Tracklist {
func NewTracklist(tracks []*mediaprovider.Track) *Tracklist {
t := &Tracklist{Tracks: tracks, visibleColumns: make([]bool, 12)}
t.ExtendBaseWidget(t)
@@ -144,7 +143,7 @@ func (t *Tracklist) buildHeader() {
}
// Gets the track at the given index. Thread-safe.
func (t *Tracklist) TrackAt(idx int) *subsonic.Child {
func (t *Tracklist) TrackAt(idx int) *mediaprovider.Track {
t.tracksMutex.RLock()
defer t.tracksMutex.RUnlock()
if idx >= len(t.Tracks) {
@@ -216,7 +215,7 @@ func (t *Tracklist) Clear() {
}
// Append more tracks to the tracklist. Thread-safe.
func (t *Tracklist) AppendTracks(trs []*subsonic.Child) {
func (t *Tracklist) AppendTracks(trs []*mediaprovider.Track) {
t.tracksMutex.Lock()
defer t.tracksMutex.Unlock()
t.Tracks = append(t.Tracks, trs...)
@@ -330,16 +329,12 @@ func (t *Tracklist) onSetFavorite(trackID string, fav bool) {
t.tracksMutex.RLock()
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
t.tracksMutex.RUnlock()
t.onSetFavorites([]*subsonic.Child{tr}, fav, false)
t.onSetFavorites([]*mediaprovider.Track{tr}, fav, false)
}
func (t *Tracklist) onSetFavorites(tracks []*subsonic.Child, fav bool, needRefresh bool) {
func (t *Tracklist) onSetFavorites(tracks []*mediaprovider.Track, fav bool, needRefresh bool) {
for _, tr := range tracks {
if fav {
tr.Starred = time.Now()
} else {
tr.Starred = time.Time{}
}
tr.Favorite = fav
}
if needRefresh {
t.Refresh()
@@ -355,12 +350,12 @@ func (t *Tracklist) onSetRating(trackID string, rating int) {
t.tracksMutex.RLock()
tr := sharedutil.FindTrackByID(trackID, t.Tracks)
t.tracksMutex.RUnlock()
t.onSetRatings([]*subsonic.Child{tr}, rating, false)
t.onSetRatings([]*mediaprovider.Track{tr}, rating, false)
}
func (t *Tracklist) onSetRatings(tracks []*subsonic.Child, rating int, needRefresh bool) {
func (t *Tracklist) onSetRatings(tracks []*mediaprovider.Track, rating int, needRefresh bool) {
for _, tr := range tracks {
tr.UserRating = rating
tr.Rating = rating
}
if needRefresh {
t.Refresh()
@@ -383,9 +378,9 @@ func (t *Tracklist) onAlbumTapped(albumID string) {
}
}
func (t *Tracklist) selectedTracks() []*subsonic.Child {
func (t *Tracklist) selectedTracks() []*mediaprovider.Track {
sel := t.selectionMgr.GetSelection()
tracks := make([]*subsonic.Child, 0, len(sel))
tracks := make([]*mediaprovider.Track, 0, len(sel))
t.tracksMutex.RLock()
defer t.tracksMutex.RUnlock()
for _, idx := range sel {
@@ -484,7 +479,7 @@ type TrackRow struct {
albumID string
isPlaying bool
isFavorite bool
playCount int64
playCount int
num *widget.RichText
name *widget.RichText
@@ -543,37 +538,37 @@ func newTrailingAlignRichText() *widget.RichText {
return rt
}
func (t *TrackRow) Update(tr *subsonic.Child, rowNum int) {
func (t *TrackRow) Update(tr *mediaprovider.Track, rowNum int) {
// Update info that can change if this row is bound to
// a new track (*subsonic.Child)
// a new track (*mediaprovider.Track)
if tr.ID != t.trackID {
if t.Focused {
fyne.CurrentApp().Driver().CanvasForObject(t).Focus(nil)
t.Focused = false
}
t.trackID = tr.ID
t.artistID = tr.ArtistID
t.artistID = tr.ArtistIDs[0]
t.albumID = tr.AlbumID
t.name.Segments[0].(*widget.TextSegment).Text = tr.Title
t.artist.SetText(tr.Artist)
t.artist.Disabled = tr.ArtistID == ""
t.name.Segments[0].(*widget.TextSegment).Text = tr.Name
t.artist.SetText(tr.ArtistNames[0])
t.artist.Disabled = tr.ArtistIDs[0] == ""
t.album.SetText(tr.Album)
t.dur.Segments[0].(*widget.TextSegment).Text = util.SecondsToTimeString(float64(tr.Duration))
t.year.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(tr.Year)
t.plays.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(int(tr.PlayCount))
t.bitrate.Segments[0].(*widget.TextSegment).Text = strconv.Itoa(tr.BitRate)
t.size.Segments[0].(*widget.TextSegment).Text = util.BytesToSizeString(tr.Size)
t.path.Segments[0].(*widget.TextSegment).Text = tr.Path
t.path.Segments[0].(*widget.TextSegment).Text = tr.FilePath
}
// Update track num if needed
// (which can change based on bound *subsonic.Child or tracklist.AutoNumber)
// (which can change based on bound *mediaprovider.Track or tracklist.AutoNumber)
if t.trackNum != rowNum {
discNum := -1
var str string
if rowNum < 0 {
rowNum = tr.Track
rowNum = tr.TrackNumber
if t.tracklist.ShowDiscNumber {
discNum = tr.DiscNumber
}
@@ -612,7 +607,7 @@ func (t *TrackRow) Update(tr *subsonic.Child, rowNum int) {
}
// Render favorite column
if tr.Starred.IsZero() {
if tr.Favorite {
t.isFavorite = false
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.NotFavoriteIcon
} else {
@@ -620,7 +615,7 @@ func (t *TrackRow) Update(tr *subsonic.Child, rowNum int) {
t.favorite.Objects[0].(*TappableIcon).Resource = myTheme.FavoriteIcon
}
t.rating.Rating = tr.UserRating
t.rating.Rating = tr.Rating
// Show only columns configured to be visible
t.artist.Hidden = !t.tracklist.visibleColumns[ColNumber(ColumnArtist)]
+5 -7
View File
@@ -1,25 +1,23 @@
package widgets
import (
"github.com/dweymouth/supersonic/backend"
"github.com/dweymouth/go-subsonic/subsonic"
"github.com/dweymouth/supersonic/backend/mediaprovider"
)
// Component that manages lazily loading more tracks into a Tracklist
// as the user scrolls near the bottom.
type TracklistLoader struct {
tracklist *Tracklist
iter backend.TrackIterator
iter mediaprovider.TrackIterator
trackBuffer []*subsonic.Child
trackBuffer []*mediaprovider.Track
fetching bool
done bool
len int
highestShown int
}
func NewTracklistLoader(tracklist *Tracklist, iter backend.TrackIterator) TracklistLoader {
func NewTracklistLoader(tracklist *Tracklist, iter mediaprovider.TrackIterator) TracklistLoader {
t := TracklistLoader{
tracklist: tracklist,
iter: iter,
@@ -44,7 +42,7 @@ func (t *TracklistLoader) loadMoreTracks(num int) {
// repeat fetch task as long as user has scrolled near bottom
for !t.done && t.highestShown >= t.len-25 {
if t.trackBuffer == nil {
t.trackBuffer = make([]*subsonic.Child, 0, num)
t.trackBuffer = make([]*mediaprovider.Track, 0, num)
}
t.trackBuffer = t.trackBuffer[:0]
for i := 0; i < num; i++ {