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
+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
}